
function show_all(type,element,topic_id){var parent=$(element);$.ajax({url:'/topics/show_all/'+topic_id,data:'type='+type+'&token='+$token,dataType:'json',beforeSend:function(){spinner_id=spinner(parent,'after','show_all_'+type);$(parent).hide();},error:function(xhr,error_type){var error_message=throw_error(error_type,xhr);$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);handle_error(error_message);});},success:function(xhr){$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);var func=eval(type);if(typeof(func)=='function')
func(parent,xhr);});}});return false;}
function recent_posts(element,xhr){var panel=$(element).parents('div.panel');$('div.section div.description span',panel).text(xhr.count);$('ul',panel).append('<div id="show_all_recent_posts" style="display: none;">'+xhr.html+'</div>');$('#show_all_recent_posts').fadeIn(250);}
function change_take(element,topic_take_id){if($('#take_form_container').length)
$('#take_form_container').remove();$.ajax({url:'/topic_takes/edit/'+topic_take_id,data:'token='+$token,dataType:'json',beforeSend:function(){$(element).hide();spinner_id=spinner(element,'after','change_take_loading');},error:function(xhr,error_type){var error_message=throw_error(error_type,xhr);$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);handle_error(error_message);$(element).show();});},success:function(xhr){$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);$(element).show();setup_take_form(xhr);});}});return false;}
function takes(element,type,topic_id){if(typeof(type)!='string'&&typeof(topic_id)!='number')
return false;$.ajax({url:'/topic_takes/record/'+topic_id,data:'token='+$token+'&list='+type,dataType:'json',beforeSend:function(){if($('#take_form_container').length)
$('#take_form_container').remove();spinner_id=spinner('#heading ul.expose','after','heading_loading');},error:function(xhr,error_type){var error_message=throw_error(error_type,xhr);$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);handle_error(error_message);});},success:function(xhr){$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);if(check_xhr_if_logged(xhr)){$(element).parents('ul.expose').find('.current').removeClass('current');if(xhr.disable.length>0){if($('#activity-'+xhr.disable).parent().find('li').length==1){$('#activity-'+xhr.disable).parents('li.takes').fadeOut(250,function(){$(this).remove();});}else{$('#activity-'+xhr.disable).fadeOut(250);}}
if(xhr.html){$(element).addClass('current');$('#my_take p').text('');if(type!='want'){setup_take_form(xhr);}}else{$('#my_take').fadeOut(250);}
if(xhr.task_id){remove_task(xhr.task_id);}}});}});return false;}
function setup_take_form(xhr){$('ul#items').before(xhr.html);$('#take_form_container').slideDown(250,function(){$('input#take',this).focus();var c=this;$('form#take_form',this).register_form({cancel:function(el){show_my_take();if($('#take_form input[name=topic_activity[id]]').val()==0){var topic_id=$('#take_form input[name=topic[id]]').val();var t_count=$('#rsidebar div.claimed_tasks ul li').length;$.post('/tasks/create',{token:$token,"task[topic_id]":topic_id,"task[task_type]":'take',tasks_count:t_count},function(xhr){if($('#rsidebar div.claimed_tasks ul li').length){$('#rsidebar div.claimed_tasks ul .last').removeClass('last');$('#rsidebar div.claimed_tasks ul').append(xhr);$('#rsidebar div.claimed_tasks ul li:last').hide().removeClass('first').addClass('last').fadeIn(250);}else{if($('#rsidebar div.claimed_tasks').length)
$('#rsidebar div.claimed_tasks').remove();$('#rsidebar').prepend(xhr).find('div.claimed_tasks').hide().fadeIn(250);}});}
$(c).slideUp(250,function(){$(this).remove();});},success:function(xhr,el){$('#take_form_container').slideUp(250,function(){$(this).remove();act_on_take_form(xhr);});}});if($('ul#items li:first').hasClass('takes')){$('form#take_form').prepend('<input type="hidden" name="display" value="append" />');}else{$('form#take_form').prepend('<input type="hidden" name="display" value="whole" />');}});}
function act_on_take_form(xhr){if(xhr.topic_activity_id){$('li#activity-'+xhr.topic_activity_id).remove();}
if(xhr.task_id){remove_task(xhr.task_id);}
if(xhr.panel_mytake){$('#my_take').replaceWith(xhr.panel_mytake);}
show_my_take();if($('ul#items li:first').hasClass('takes')){$('ul#items li:first ul').prepend(xhr.html).find('li:first').hide().css('background-color','#ffffcc').fadeIn(250,function(){$(this).highlight();});}else{$('ul#items').prepend(xhr.html).find('li:first').hide().find('ul li').css('visibility','hidden');$('ul#items li:first').slideDown(250,function(){$('ul li',this).hide().css({visibility:'visible',backgroundColor:'#ffffcc'}).fadeIn(250,function(){$(this).highlight();});});$('ul#items li.activity:first').removeClass('first');}
if(typeof(xhr.follow)=='string'){$('#followers_count').text(parseInt($('#followers_count').text())+1);$('#unfollow_button, p.follow_status').show();$('#heading_buttons').hide();}}
function show_my_take(){if($('#my_take').length&&$('#my_take p').text().length){$('#my_take').fadeIn(250);if($('#my_take').prev().hasClass('panel')){$('#my_take').prev().removeClass('panel').addClass('panel_open');}}}
function hide_my_take(){if($('#my_take').length)
$('#my_take').hide();}
var follow_topic_id;var follow_spinner_id;function follow_topic(topic_id,is_twitter_setup){if(typeof(is_twitter_setup)!='boolean')return false;if(is_twitter_setup==false){$('#heading_buttons').hide();follow_spinner_id=spinner('#heading_buttons','after','heading_loading');return sync_twitter('/topics/setup_twitter/'+topic_id);}else{do_follow(topic_id);}}
function init(twitter_username,topic_id){spinner_callback(follow_spinner_id);do_follow(topic_id);}
function do_follow(topic_id){if(typeof(topic_id)!='number')return false;$.ajax({url:'/topics/follow/'+topic_id,data:'token='+$token,dataType:'json',beforeSend:function(){$('#heading_buttons').hide();spinner_id=spinner('#heading_buttons','after','heading_loading');},error:function(xhr,error_type){var error_message=throw_error(error_type,xhr);$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);$('#heading_buttons').fadeIn(250);handle_error(error_message);});},success:function(xhr){$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);$('#followers_count').text(parseInt($('#followers_count').text())+1);});}});return false;}
function do_follow2(topic_id){if(typeof(topic_id)!='number')return false;$.ajax({url:'/topics/follow/'+topic_id,data:'token='+$token,dataType:'json',beforeSend:function(){$('#heading_buttons').hide();spinner_id=spinner('#heading_buttons','after','heading_loading');},error:function(xhr,error_type){var error_message=throw_error(error_type,xhr);$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);$('#heading_buttons').fadeIn(250);handle_error(error_message);});},success:function(xhr){$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);$('#followers_count').text(parseInt($('#followers_count').text())+1);$('#unfollow_button, p.follow_status').show();});}});return false;}
function do_unfollow(topic_id){if(typeof(topic_id)!='number')return false;$.ajax({url:'/topics/unfollow/'+topic_id,data:'token='+$token,dataType:'json',beforeSend:function(){$('#unfollow_button').hide();spinner_id=spinner('#unfollow_button','after','unfollow_button_loading');},error:function(xhr,error_type){var error_message=throw_error(error_type,xhr);$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);$('#unfollow_button').fadeIn(250);handle_error(error_message);});},success:function(xhr){$(spinner_id).fadeOut(250,function(){spinner_callback(spinner_id);$('#followers_count').text(parseInt($('#followers_count').text())-1);$('#unfollow_button, p.follow_status').hide();$('#heading_buttons').show();});}});return false;}