var showFollowButton=function(){return !sessionUserIsPageUser()||$("body").hasClass("followers")};var fadeUserOnUnfollow=function(){return sessionUserIsPageUser()&&$("body").hasClass("following")};$.fn.isCtrlBar=function(){var A=$("#follow_grid");return this.each(function(){$(this).find("a").click(function(B){A.attr("class","follow-"+$(this).attr("class"));$.cookie("follow_view",$(this).attr("class"));B.preventDefault()}).tipsy({gravity:"s"})})};$.fn.isUser=function(){return this.each(function(){var F=$(this);var B=F.find(".user-settings a").isUserSetting().tipsy({gravity:"s"});var A=F.find(".follow-action button").tipsy({gravity:"s"});var C=F.find(".user-actions .action-menu button").isUserActionMenu();try{F.find(".user-actions .list-menu button").isUserListMenu().tipsy({gravity:"s"})}catch(E){}var D=F.find(".is-pending .cancel a, .is-blocked .unblock a, .follow-action button").isUserActionLink()})};var successfullUndo=function(C){var B=C.find(".undo");var A=B.data("previousClass");successfullUnblock(C);if(sessionUserIsPageUser()){C.html(B.data("originalHtml"));C.isUser()}C.attr("class",A);$(".protected-profile-controls").hide()};var successfullUnblock=function(B){var A="";if(sessionUserIsPageUser()){updateFollowersCount(-1);A=B.find(".screen-name")}else{B.removeClass("blocking").find(".is-blocked").remove();$("ul.sidebar-actions").removeClass("blocked").addClass("unblocked");A=B.find("div.screen-name")}};var successfullReportAsSpamOrBlock=function(D,C,H){if(D!="follow"){if(sessionUserIsPageUser()){updateFollowersCount(-1);var I=jQuery.trim(C.find("span.screenname a").text());var A=$("#is_blocked_as_spammer_my_followers");var J=C.html();C.html('<td colspan="3">'+A.html()+"</td>");C.find(".is-blocked").show();var B="";if(D=="report-for-spam"){B=_("<a class='screen-name' href='/%{user}'>%{user}</a> blocked and reported for spam",{user:I})}else{B=_("<a class='screen-name' href='/%{user}'>%{user}</a> blocked",{user:I})}C.find(".undo").data("undoCommands",H).data("originalHtml",J);C.find("#blocked_msg").html(B);C.find(".is-blocked .unblock a, .is-blocked .undo a").isUserActionLink()}else{var G=$(D!="report-for-spam"?"#is_blocked_with_undo":"#is_blocked_as_spammer");var F=C.attr("class");C.addClass("blocking").removeClass("following").find(".is-relationship").append(G.html()).end().find(".is-blocked .unblock a, .is-blocked .undo a").isUserActionLink();var E=C.find(".undo");E.data("undoCommands",H);E.data("previousClass",F);$("ul.sidebar-actions").removeClass("unblocked").addClass("blocked");$(".protected-profile-controls").show()}}else{new InfoNotification().setMessage(_("This user has blocked you from following them.")).show()}};var sendSidebarAction=function(A){if(!A.data){A.data={}}A.data.authenticity_token=twttr.form_authenticity_token;A.data.twttr=true;$.ajax({type:"POST",dataType:"json",url:A.url,data:A.data,complete:function(){$(this).blur()},success:A.success,error:function(){twttr.error()}})};function User(A){}$(function(){var B=$("ul.sidebar-actions");if(B.length>0){var C=$("div.profile-user div.user");var A=B.attr("id").replace("sidebar_actions_for_user_","");$("li.unblock-sidebar-action a").bind("click",function(){var D=C.find(".undo").data("undoCommands");if(D){sendSidebarAction({url:"/blocks/undo",data:{user_id:A,undo_commands:D},success:function(){successfullUndo(C)}})}else{sendSidebarAction({url:"/blocks/destroy/"+A,success:function(){successfullUnblock(C)}})}return false});$("li.report-for-spam-sidebar-action a").bind("click",function(){sendSidebarAction({url:"/user_spam_reports/create/"+A,dataType:"json",success:function(D){switch(D.result){case"reported_as_spam":successfullReportAsSpamOrBlock("report-for-spam",C,D.undo_commands);break;case"over_limit":(new ErrorNotification()).setMessage(D.notice).show();break}},userId:A});return false});$("li.block-sidebar-action a").bind("click",function(){sendSidebarAction({url:"/blocks/create/"+A,success:function(D){successfullReportAsSpamOrBlock("block",C,D.undo_commands)},userId:A});return false})}});$.fn.isUserActionLink=function(){return this.each(function(){var A=$("#is_following");var B=$("#is_pending");$(this).click(function(I){var C=$(this);var J=C.parents(".user");var F=J.attr("id").replace("user_","");var H=C.parent("li, span").attr("class").replace("-action","");var E=J.find(".screenname a, .screen-name").html();switch(H){case"mention":case"direct-message":document.location=C.attr("href")+E;break;case"block":case"remove":case"undo":case"follow":case"unfollow":case"cancel":case"report-for-spam":case"unblock":if(H=="remove"&&!confirm(_("Are you sure you want to remove this person from your followers?"))){return false}var D=C.attr("href");var G={authenticity_token:twttr.form_authenticity_token,twttr:true};if(H=="undo"){G.undo_commands=J.find(".undo").data("undoCommands")}if(H=="cancel"||H=="undo"){G.user_id=F}else{D+=F}$.ajax({type:"POST",dataType:"json",url:D,data:G,complete:function(){C.blur()},success:function(K){switch(K.result){case"unfollowed":if(sessionUserIsPageUser()){updateFollowingCount(-1)}else{updateFollowersCount(-1)}if(fadeUserOnUnfollow()){J.fadeOut("medium",function(){J.remove()})}else{J.removeClass("following").find(".is-following").remove().end().find(".follow-action").show().end().find(".user-settings .on").attr("class","off")}break;case"added":if(sessionUserIsPageUser()){updateFollowingCount(1)}else{if($("body#profile").length){updateFollowersCount(1)}}J.addClass("following").removeClass("blocking").find(".is-following, .is-pending, .is-blocked").remove().end().find(".is-relationship").append(A.html()).end().find(".user-settings .shares-setting a").removeClass("off").addClass("on");break;case"follow_request":J.addClass("pending").find(".is-relationship").append(B.html()).end().find(".is-pending .cancel a").isUserActionLink();break;case"canceled":J.removeClass("pending").find(".is-pending").remove();break;case"undone":successfullUndo(J);break;case"removed":if(sessionUserIsPageUser()){updateFollowersCount(-1);J.fadeOut("medium",function(){J.remove()})}break;case"reported_as_spam":case"blocked":successfullReportAsSpamOrBlock(H,J,K.undo_commands);break;case"over_limit":(new ErrorNotification()).setMessage(K.notice).show();break;default:if(H=="unblock"&&!K.following){successfullUnblock(J)}}},error:function(){twttr.error()}});break}I.preventDefault()})})};$.fn.isUserActionMenu=function(){$actionMenu=$("#action_menu");return this.one("click",function(){var B=$(this);var A=B.parents(".user").find(".screenname a, .screen-name").html();$("body").click();B.addClass("clicked").after($actionMenu.html());B.siblings("ul").find("a").find("span").html(A).end().isUserActionLink();$("html").one("click",function(){B.removeClass("clicked").blur().siblings("ul").remove().end().isUserActionMenu();return false});return false})};$.fn.isUserSetting=function(){return this.click(function(F){var A=$(this);var E=A.parent(".setting");var B=A.parents(".user").attr("id").replace("user_","");var C=E.attr("class").match(/(\w+)-setting/)[1];var D=A.hasClass("off")?"on":"off";if(C.length>0){$.ajax({type:"POST",dataType:"json",url:"/friendships/set_"+C,data:{user_ids:[B],value:D,authenticity_token:twttr.form_authenticity_token,twttr:true},beforeSend:function(){A.toggleClass("off").toggleClass("on").attr("title",window.titleText[C][D])},complete:function(){A.trigger("mouseenter");setTimeout(function(){A.trigger("mouseleave")},2000)},error:function(){A.toggleClass("off").toggleClass("on")}})}F.preventDefault()})};