$.enswerme.profile={};$.enswerme.profile.form_settings={beforeSubmit:function(formData,jqForm,options){$("#facebox form").block($.enswerme.settings.blockui);},success:function(data){$("#facebox form").unblock();}};$.enswerme.profile.renders=function(hash,start){var username=$.trim($("#profile_username").text());if(username==null)return;if(hash){$.ajax({url:"/user/"+username+"/render/"+hash+"/",cache:false,data:{start:start},dataType:'xml',async:false});$(".profile_menu a").removeClass("selected");var $current_menu_link=$(".profile_menu a[href='#"+hash+"']");$current_menu_link.addClass("selected");$("#site_location span:first").html($current_menu_link.html());}
else{$.ajax({url:"/user/"+username+"/render/"+DEFAULT_HASH+"/",cache:false,dataType:'xml',async:false});$(".profile_menu a[href='#"+DEFAULT_HASH+"']").addClass("selected");}}
$.enswerme.profile.hashbehaviors=function(hash){$.enswerme.profile.renders(hash,0);$.enswerme.profile.sortable();};$.enswerme.profile.bind_buttons=function(){$("#profile_contents dd.edit a[rel*=facebox]").livequery(function(){$(this).facebox();},function(){$(this).unbind("click");});}
$.enswerme.profile.editable=function(){$("#profile_contents ol.line dl").livequery(function(){$(this).hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});},function(){$(this).unbind("mouseover");$(this).unbind("mouseout");});};$.enswerme.profile.readmore=function(){var username=$.trim($("#profile_username").text());$("#profile_contents .more_list").livequery("click",function(){var $this=$(this);var data=null;if($this.attr("rel")=="activity_streams"){var length=$this.prev("ol").find("dl.stream").length;length=length+$this.prev("ol").find("li.comment").length;data={start:length,as_type:$("#activity_streams_type").fieldValue()};}
else{var length=$this.prev("ol.line").find("dl").length;data={start:length};}
var start=length;var target=$this.attr("rel");$(this).block($.enswerme.settings.blockui);$.ajax({cache:false,url:"/user/"+username+"/render/more/"+target+"/",data:data,dataType:'xml',async:false,success:function(){$(this).unblock();}});$(this).unblock();return false;});};$.enswerme.profile.sortable=function(){var username=$.trim($("#profile_username").text());$("#profile_contents ol.sortable").livequery(function(){var $this=$(this);var target=$this.parent("div").attr("id").replace("_div","");$this.sortable({opacity:0.7,axis:'y',update:function(e,ui){var sort=$this.sortable("serialize",{key:'id'});$.post("/user/"+username+"/move/"+target+"/?"+sort,null,null,'json');}});},function(){$(this).sortable('destory');});$("#profile_contents ol.sortable2").livequery(function(){var $this=$(this);$this.sortable({opacity:0.7,forcePlaceholderSize:true,update:function(e,ui){var sort=$this.sortable("serialize",{key:'id'});$.post('/user/'+username+'/move/favorite_videos/?'+sort,null,null,'json');}});},function(){$(this).sortable('destory');});}
$.enswerme.profile.submit=function(form,is_clean_form){$(form).block($.enswerme.settings.blockui);$(form).ajaxSubmit({clearForm:is_clean_form});$(form).unblock();return false;};$.enswerme.profile.toggle_comment_reply=function(id){if($("#comment_reply_area_"+id).is(":visible")==true){$("#comment_reply_area_"+id).css("display","none");}
else{$("#comment_reply_area_"+id).css("display","");}
return false;}
$.enswerme.profile.toggle_comment_edit=function(id){$('#comment_body_'+id).toggle();$('#comment_modify_area_'+id).toggle();return false;}
$.enswerme.profile.bind_comments=function(){$("#activity_streams_type").livequery('change',function(){var as_type=$(this).fieldValue();$.get("/user/"+PROFILE_USERNAME+"/render/activity_streams/",{start:0,as_type:as_type});});$("#activity").submit(function(){return $.enswerme.profile.submit(this,false);});$(".comment_form").livequery('submit',function(){return $.enswerme.profile.submit(this,true);});$(".comment_edit_form").livequery('submit',function(){return $.enswerme.profile.submit(this,false);});$("a[rel=stream_comment_toggle]").livequery("click",function(){var stream_id=$(this).find("span.stream_id").text();$("#as_comment_reply_area_"+stream_id).toggle();return false;});$("a[rel=similar_streams_show]").livequery("click",function(){var stream_id=$(this).find("span.stream_id").text();$("#similar_streams_"+stream_id).show();$(this).remove();return false;});$("a[rel=stream_comment_delete]").livequery("click",function(){var comment_id=$(this).find("span.comment_id").text();$.post("/user/"+PROFILE_USERNAME+"/comment/stream/delete/dialog/",{comment_id:comment_id});return false;});$("a[rel=comment_reply_toggle]").livequery("click",function(){var comment_id=$(this).find("span.comment_id").text();return $.enswerme.profile.toggle_comment_reply(comment_id);});$("a[rel=comment_edit_toggle]").livequery("click",function(){var comment_id=$(this).find("span.comment_id").text();return $.enswerme.profile.toggle_comment_edit(comment_id);});$("a[rel=comment_delete]").livequery("click",function(){var comment_id=$(this).find("span.comment_id").text();$.post("/user/"+PROFILE_USERNAME+"/comment/delete/dialog/",{comment_id:comment_id});return false;});}
$(document).ready(function(){$.enswerme.commons.header_menubar();$.enswerme.profile.editable();$.enswerme.profile.readmore();$.enswerme.profile.bind_buttons();$.enswerme.profile.bind_comments();$.historyInit($.enswerme.profile.hashbehaviors);$(".profile_menu a").click(function(){$("#profile_contents").block($.enswerme.settings.blockui);var hash=this.href;hash=hash.replace(/^.*#/,'');$.historyLoad(hash);$.unblockUI();return false;});});