function setupMain(){$("#excel-item a").click(function(){if($(this).parent().find(".counter").html()!="0"){var A=$(this).parent().find(".counter").html()-1;if(A>0){$(this).parent().find(".counter").html(A)}else{$(this).parent().find(".counter").html("0")}}})}function ieStopFlicker(){try{document.execCommand("BackgroundImageCache",false,true)}catch(A){}}function ieHover(){var B=document.getElementsByTagName("li");if(B){for(var A=0;A<B.length;A++){if(B[A].className.indexOf("pop-up")!=-1){B[A].onmouseover=function(){this.className+=" hover"};B[A].onmouseout=function(){this.className=this.className.replace(" hover","")}}}}}if(window.attachEvent&&!window.opera){window.attachEvent("onload",ieHover);window.attachEvent("onload",ieStopFlicker);window.attachEvent("onresize",function(){document.body.style.width=(parseInt(document.documentElement.clientWidth)<995)?"995":"auto"})}function setInput(C,D,F,B){alert("in setInput");var E=$("#searchForm");var A=$("#"+C,E);if(F=="00"){$("#"+C,E).remove()}else{var A=$("#"+C,E);if(A.length==0){E.append("<input id='"+C+"' type='hidden' name='"+D+"' value='"+F+"' />")}else{A.attr("value",F)}}if(B){E.submit()}}function setSelectedDropdownValue(C,B,A){switch(B){case"langDrpDwn":setInput("langFilter","lang",C,A);break;case"sortDrpDwn":setInput("sortFilter","sort",C,A);break;case"tspanDrpDwn":setInput("tspanFilter","tspan",C,A);break}var D=$("."+B);setSelectDropDownDisplayValue(D,C)}function setSelectDropDownDisplayValue(E,C){for(var B=0;B<E.length;B++){$("li:hidden",E[B]).show();var D=$("li[class='"+C+"']",E[B]);var A=D.text();D.hide();$("a[class='opener']",E[B]).html("<span>"+A+"</span>")}}if(window.attachEvent&&!window.opera){window.attachEvent("onload",ieHover)}function setupItemAdministration(){$(".ExpandItemAdmin").click(function(){if($(this).siblings(".ItemAdminInner").css("display")=="none"){$(this).text($(this).text().replace("+","-"))}else{$(this).text($(this).text().replace("-","+"))}$(this).siblings(".ItemAdminInner").toggle()});$(".ExpandAllItemAdmin").click(function(){if($(this).text().indexOf("+")!=-1){$(".ItemAdminInner:hidden").show();$(".ExpandAllItemAdmin").text("Collapse all [-]");$(".ExpandItemAdmin").text($(this).siblings(".ExpandItemAdmin").text().replace("+","-"))}else{$(".ItemAdminInner:visible").hide();$(".ExpandAllItemAdmin").text("Expand all [+]");$(".ExpandItemAdmin").text($(this).siblings(".ExpandItemAdmin").text().replace("-","+"))}})}function setupMicroblogFilter(){function F(M,O){var N=false;$(M).each(function(P){if(this==O){N=true;return }});return N}function G(){if(A.attr("checked")){var O="";for(var M=0;M<J.length;M++){if(!J[M].checked){O+=J[M].name+"|"}}L.val(O.substring(0,O.length-1));D.val("")}else{var N="";for(var M=0;M<J.length;M++){if(J[M].checked){N+=J[M].name+"|"}}D.val(N.substring(0,N.length-1));L.val("")}}$("#filterMicroBlog").append('<div><h3>Show...</h3><form id="searchFilterForm"><input type="hidden" class="excludeField" name="excludesite" value="" /><input type="hidden" class="includeField" name="site" value="" /><div class="row"><input type="checkbox" class="filterCheck" id="twitter.com" name="twitter.com" value="twitter" /><ul class="microbloglist"><li class="twitter"><label for="twitter.com"><span><a href="http://www.twitter.com/">Twitter</a></span></label></li></ul></div><div class="row"><input type="checkbox" class="filterCheck" id="jaiku.com" name="jaiku.com" value="jaiku" /><ul class="microbloglist"><li class="jaiku"><label for="jaiku.com"><span><a href="http://www.jaiku.com/">Jaiku</a></span></label></li></ul></div><div class="row"><input type="checkbox" class="filterCheck" id="identi.ca" name="identi.ca" value="identica" /><ul class="microbloglist"><li class="identica"><label for="identi.ca"><span><a href="http://identi.ca/">Identica</a></span></label></li></ul></div><div class="row last"><input type="checkbox" class="filterCheckOthers" id="others" name="others" value="others" /><ul class="microbloglist"><li class="bleeper"><label for="others"><span><a href="http://bleeper.de/">Bleeper</a></span></label></li><li class="bloggy"><label for="others"><span><a href="http://www.bloggy.se/">Bloggy</a></span></label></li><li class="cirip"><label for="others"><span><a href="http://www.cirip.ro/">Cirip</a></span></label></li><li class="koornk"><label for="others"><span><a href="http://www.koornk.com/">Koornk</a></span></label></li><li class="lareta"><label for="others"><span><a href="http://lareta.net/">Lareta</a></span></label></li><li class="linuxoutlaws"><label for="others"><span><a href="http://linuxoutlaws.net/">Linux Outlaws</a></span></label></li><li class="sufficetosay"><label for="others"><span><a href="http://sufficetosay.frontrowcrew.com/">Suffice to say</a></span></label></li><li class="armytwit"><label for="others"><span><a href="http://army.twit.tv/">TWiT Army</a></span></label></li><li class="youare"><label for="others"><span><a href="http://www.youare.com/">YouAre</a></span></label></li></ul></label></div><input type="submit" value="Update results" id="filterbutton" class="button" tabindex="8" /></form></div>');var E=$("#searchForm .includeField");var C=$("#searchForm .excludeField");var D=$("#searchFilterForm .includeField");var L=$("#searchFilterForm .excludeField");var J=$("#searchFilterForm .filterCheck");var A=$("#searchFilterForm .filterCheckOthers");if(C.length==0){$("#searchForm .search-box .inputs").append('<input type="hidden" class="excludeField" name="excludesite" value="" />');C=$("#searchForm .excludeField")}if(E.length==0){$("#searchForm .search-box .inputs").append('<input type="hidden" class="includeField" name="site" value="" />');E=$("#searchForm .includeField")}L.val(C.val());D.val(E.val());var I=$("#searchFilterForm .filterCheck, .filterCheckOthers");var K=[];if(L.length>0){K=L.val().split("|")}if(D.length>0){if(D.val()==""){A.attr("checked",true)}else{var B=D.val().split("|");for(var H=0;H<I.length;H++){if(!F(B,I[H].name)){K[K.length]=I[H].name}}}}for(var H=0;H<I.length;H++){if(F(K,I[H].name)){$(I[H]).removeAttr("checked")}else{$(I[H]).attr("checked",true)}}J.change(function(){G()});A.change(function(){G()});$("#searchForm").submit(function(){if(C.val()==""){C.remove()}if(E.val()==""){E.remove()}});$("#searchFilterForm").submit(function(){C.val(L.val());E.val(D.val());$("#searchForm").submit();return false})}function setupCommentsLoading(){var C='<div class="no-more-comments" style="display:block;"><h2>No comments found, sorry!</h2></div>';var B=5;function E(H){$(H).find("a.has-more").click(function(L){if(L.detail!=2){var K=$(this).parent().parent().parent();var J=$(this).attr("rel");var O=$(K).find("h3").attr("class");var M=parseInt($(this).parent().find("div.pagenum").find("div").attr("rel"));var N=M+1;var I=parseInt($(K).attr("class").replace("post micro ",""));$(this).parent().find("div.pagenum").html('<div rel="'+N+'"></div>');F(J,O,N,false,K);if((N*B)>=I){$(K).find("div.micro-has-more-comments").slideUp("fast")}}$(this).blur();return false})}function G(H){return $(H).children("div.left").children("div.info").children("p.showcommentlink").children("img.comment-loader")}function F(J,M,K,H,I){G(I).show();var L=$(I).children("div.comments");$.ajax({type:"GET",url:"/search/getcomments?url="+encodeURIComponent(J)+"&page="+K+"&size="+B,dataType:"html",success:function(N){$(L).append(N);$(I).children("div.micro-has-more-comments").show();L.find(".micro").show();if(H){$(L).animate({height:"toggle",opacity:"toggle"},{duration:"fast"})}else{$(L).slideDown("fast")}G(I).hide();E(I);D(L);var O=parseInt($(I).attr("class").replace("post micro ",""));if($(I).find("div.post").size()>=O){$(I).find("div.micro-has-more-comments").remove()}},error:function(O,N,P){$(L).append(C);$(I).children("div.micro-has-more-comments").remove();if(H){A(I)}else{$(L).parent().find(".no-more-comments").slideDown("fast");G(I).hide()}}})}function A(H){$(H).children("div.comments").animate({height:"toggle",opacity:"toggle"},{duration:"fast"});$(H).children("div.micro-has-more-comments").animate({height:"toggle",opacity:"toggle"},{duration:"fast"});G(H).hide()}function D(H){var I=H;if(!I){I=$("p.showcommentlink")}$(I).find("a.unfoldcomment").click(function(L){if(L.detail!=2){if($(this).html()=="Hide comments"){$(this).html("View comments")}else{$(this).html("Hide comments")}var K=$(this).parent().parent().parent().parent();var J=$(this).attr("rel");var N=$(this).parent().parent().find("h3").attr("class");var M=1;if($(K).children("div.comments").html()==""){F(J,N,M,true,K)}else{A(K)}}$(this).blur();return false})}D()}function setupMicroblogResult(){setupCommentsLoading();setupMicroblogFilter()}function setupBubbleHandler(){if($("div.bubble-container").css("width")){$("ul.bubble-tabs").html('<li class="tags"><a href="" class="active" title="Tagcloud">Tags</a></li><li class="posts"><a href="" title="Most recent posts">Posts</a></li><li class="stats"><a href="" title="Stats">Stats</a></li>');var A=$("div.bubble-container").css("width").replace("px","")+"px";var B=$("div.bubble-container").css("width").replace("px","")-40+"px";$("div.bubble-container").css({width:A});$("div.content-area").css({width:B});$("ul.bubble-tabs a").click(function(F){if(F.detail!=2){var G=$(this).parent().parent().attr("class").replace("bubble-tabs ","");var D=$(this).parent().attr("class");var C=$(this).parent().parent().parent().find("div.content-area");var E=$(C).find("div").filter("div."+D);$(this).parent().parent().find("a.active").removeClass("active");$(this).addClass("active");$(C).children("div").css({display:"none"});$(C).children("div.bubble-min-height-fix").css({display:"block"});$(E).css({display:"block"});if($(C).find("div."+D).html()==""){AjaxBubbleRequest(G,C,D)}}$(this).blur();return false})}}function AjaxBubbleRequest(G,B,F){$(B).find("div."+F).append('<div style="text-align: center;"><img src="http://static.twingly.com/content/images/ajax-loader.gif" width="16" height="16" alt="" style="margin: 20px auto 0 auto;" /></div>');var A;var E;if(F=="posts"){var C=$(B).attr("id");var D=D=$(B).find("div."+F).attr("class").replace("posts ","");E="/json/search?q="+D+"%2bblog%253a"+C}else{E="blogs/"+G+".json"}$.getJSON(E,function(H){if(H.totalFound>0){if(F=="posts"){var I=H.totalFound;if(I>3){I=3}A='<ul class="post-list">';for(i=0;i<I;i++){A+='<li><a href="'+H.items[i].url+'">'+H.items[i].title+"</a></li>"}A+="</ul>"}}else{A='<p style="margin: 5px 0 0 5px;width:auto !important;">No posts found, sorry!</p>'}$(B).find("div."+F).empty().append(A)})}if(typeof (google)!="undefined"&&typeof (google.load)!="undefined"){google.load("language","1")}var languageMapping=new Object();languageMapping.ar="Arabic";languageMapping.bg="Bulgarian";languageMapping.zh="Chinese";languageMapping.hr="Croatian";languageMapping.cs="Czech";languageMapping.da="Danish";languageMapping.nl="Dutch";languageMapping.fi="Finnish";languageMapping.fr="French";languageMapping.de="German";languageMapping.el="Greek";languageMapping.hi="Hindi";languageMapping.it="Italian";languageMapping.jp="Japanese";languageMapping.no="Norwegian";languageMapping.pl="Polish";languageMapping["pt-PT"]="Portuguese";languageMapping.ro="Romanian";languageMapping.ru="Russian";languageMapping.es="Spanish";languageMapping.sv="Swedish";$("#undo-translate").click(function(){$("#undo-translate").hide()});function TranslateTitlesAndSummaries(){var B=$(".info > p:nth-child(4), .info > h3 > a");var A=$(".info");if(typeof google!="undefined"){TranslateStrings(B,A)}}function TranslateStrings(B,E){var G=B.length;var D=$("#translation-by-google");var C=$("#translate-loader");var F=$("#translate-button");var A=$("#undo-translate");F.hide();D.show();C.show();B.each(function(H,J){var K=$(J).html();var I=new Object();I.text=K;I.type="html";google.language.translate(I,"","en",function(L){if(!L.error&&L.detectedSourceLanguage&&languageMapping[L.detectedSourceLanguage]){$(J).html(L.translation);if(H<B.length/2){var M=$(E[H]);var N=$(".translate-info",M);$(N).html("Translated from "+languageMapping[L.detectedSourceLanguage]);$(N).show();M.addClass("highlighted")}}G--;if(G==0){C.hide();A.show()}})})}if((typeof (Orbited)!="undefined")&&(typeof (Orbited.TCPSocket)!="undefined")){TCPSocket=Orbited.TCPSocket;if($.browser.opera){Orbited.settings.streaming=false}if($.browser.msie&&(parseInt($.browser.version)<8)){Orbited.settings.streaming=false}}notifications=null;RetryingSTOMPClient=function(orbitedHostname,channelName){var self=this;self.isConnected=false;self.isConnecting=false;self.nextRetryLevels=[3,7,15];self.nextRetryIndex=0;self.nextRetryTS=null;self.retryTimeoutId=null;self.stomp=new STOMPClient();self.stomp.onopen=function(){self.isConnected=true;self.isConnecting=false;self.nextRetryIndex=0;if(self.retryTimeoutId!=null){clearInterval(self.retryTimeoutId);self.retryTimeoutId=null;self.onRetryStatus("")}};self.stomp.onclose=function(c){if(self.retryTimeoutId!=null){}if(self.retryTimeoutId==null){self.retryTimeoutId=setInterval(self._onRetryInterval,1000)}self.isConnected=false;self.isConnecting=false;self.nextRetryTS=new Date();self.nextRetryTS.setTime(self.nextRetryTS.getTime()+(1000*self.nextRetryLevels[self.nextRetryIndex]))};self._onRetryInterval=function(e){if(self.isConnecting){self.onRetryStatus("Connecting...")}else{if(self.nextRetryTS.getTime()<(new Date()).getTime()){if(self.nextRetryIndex<self.nextRetryLevels.length-1){self.nextRetryIndex++}self.onRetryStatus("Connecting...");self.connect()}else{var secondsLeft=1+parseInt(Math.round((self.nextRetryTS.getTime()-(new Date().getTime()))/1000));self.onRetryStatus("Lost connection. Re-connecting in "+secondsLeft+" s")}}};self.onRetryStatus=function(msg){};self.stomp.onerror=function(error){};self.stomp.onerrorframe=function(frame){};self.stomp.onconnectedframe=function(){self.stomp.subscribe("/topic/"+channelName)};self.stomp.onmessageframe=function(frame){try{var tmp=eval("("+frame.body+")");self.onJsonMessage(tmp)}catch(E){}};self.onJsonMessage=function(msg){};self.connect=function(){self.stomp.connect(orbitedHostname,61613);self.isConnecting=true}};var Channels=window.Channels={Controllers:{extend:function(A){$.extend(this,A)}},Views:{extend:function(A){$.extend(this,A)}},Models:{extend:function(A){$.extend(this,A)}},Api:{Urls:{GetNewIncomingDocumentEvent:"/channels/newincomingdocumentevent",GetNewLinkEvent:"/channels/newlinkevent",GetPopularChangedEvent:"/channels/popularchangedevent",GetNewExternalCommentEvent:"/externalcomments/get",GetMoreExternalComments:"/externalcomments/find",DeleteChannelItem:"/channelitems/delete",SendWritingCommentNotification:"/notifications/writingcomment",CreateLike:"/useractions/createlike",CreateComment:"/useractions/createcomment",CreateUserCreatedContent:"/useractions/createusercreatedcontent",CreateSubscription:"/useractions/createsubscription",GetTitleForUrl:"/usercreatedcontent/gettitleforurl"}},extend:function(A){$.extend(this,A)},updateDocumentTimestamps:function(){var A=$(".timestamp");var C=$(".timestamp-hidden");for(var B=0;B<A.length;B++){$(A[B]).text(Channels.DateTimeHelper.GetTimespanString(new Date($(C[B]).text())))}},redirectIfNotSignedIn:function(){if(CURRENT_USER_NAME==null){window.location=SIGN_IN_URL+encodeURIComponent(window.location);return true}return false},makeRequest:function(A,B,C){if(Channels.redirectIfNotSignedIn()){return false}$.ajax({url:A,data:B,type:"POST",dataType:"json",success:function(D,F,E){if(!D.is_ok){window.location=D.redirectUrl+encodeURIComponent(window.location)}else{C(D,F,E)}}});return true}};Channels.Client=function(A,B){this.stompClient=new RetryingSTOMPClient(A,B);this.stompClient.onJsonMessage=function(D){if(D.type=="comment"){Channels.Controllers.Comment.Add(D.author_name,D.comment_on,D.html,D.comment_guid)}else{if(D.type=="incomingdocument"){if(IS_INCOMING_VIEW){Channels.Controllers.ChannelItem.Add(CHANNEL_NAME,D.id,D.url,D.title,D.body,D.content_type,D.created,D.website_url,D.website_title,D.image_url)}}else{if(D.type=="incominglink"){Channels.Controllers.Link.Add(D.channeldocument_guid,D.link_url,D.website_title)}else{if(D.type=="usercreatedcontent"){window.setTimeout(Channels.Controllers.ChannelItem.AddUcc,1000,D.id,D.html)}else{if(D.type=="like"){Channels.Controllers.Like.Add(D.channeldocument_guid,D.html,D.guid)}else{if(D.type=="popular"){if(IS_POPULAR_VIEW){var E=new Channels.Models.Popular(D.popular_list);Channels.Controllers.Popular.UpdatePopular(E)}}else{if(D.type=="writingcomment"){if(CURRENT_USER_NAME!==D.user_name){var C=new Channels.Models.CommentNotification(D.user_name,D.document_id,D.state,D.html);Channels.Controllers.CommentNotification.NotifyUser(C)}}else{if(D.type=="addsubscription"){var C=new Channels.Models.Subscription(D.html,D.user_id,false);Channels.Controllers.Subscription.Add(C)}else{if(D.type=="incomingexternalcomment"){Channels.Controllers.ExternalComments.Add(D.channelDocumentGuid,D.externalCommentId,D.documentId,D.domId)}}}}}}}}}};this.stompClient.onRetryStatus=function(C){if(C==""){$("#logger").html("")}else{$("#logger").html($("<pre>"+C+"</pre>"))}}};Channels.Client.prototype.start=function(){this.stompClient.connect()};COMMENT_INPUT_PATTERN=".comments .commentform textarea";COMMENT_MORECOMMENTS_PATTERN=".comments:not(.external) .morecomments .showolder";EXTERNALCOMMENT_MORECOMMENTS_PATTERN=".external .morecomments a.showmore";EXTERNALCOMMENT_SHOWCOMMENTS_PATTERN=".external .morecomments a.show";EXTERNALCOMMENT_HIDECOMMENTS_PATTERN=".external .morecomments a.hider";DEFAULT_COMMENT_STRING="Write a comment";POST_INCOMING_ITEM_ITEM_PATTERN="#postform .inputarea";POST_INCOMING_ITEM_ITEM_LINK_PATTERN="#postform #urlarea";var delayed;Channels.extend({Events:{connectEvents:function(){$(".commentform .commentcontrols input").live("click",Channels.Events.onCommentSubmitClick);$(COMMENT_INPUT_PATTERN).keyup(Channels.Events.onCommentKeyUp);$(POST_INCOMING_ITEM_ITEM_PATTERN).keyup(function(A){var B=$("#postform #posttype").attr("value");Channels.Controllers.UserCreatedContentPost.Activate(B)});$(POST_INCOMING_ITEM_ITEM_LINK_PATTERN).keyup(function(B){var A=$("form#postform #urlarea").val();Channels.Controllers.UserCreatedContentPost.GetLinkTitle(A);if($(this).val().length==0){$("#postform #submitbutton").attr("disabled","disabled")}});$("form#postform #titlearea").keyup(function(A){$(this).addClass("manual");$("#titleloader").hide();if($(this).val().length>0){$("#postform #submitbutton").removeAttr("disabled")}else{$("#postform #submitbutton").attr("disabled","disabled")}});$("form#postform #contentarea").keyup(function(A){if($(this).val().length>0){$("#postform #submitbutton").removeAttr("disabled")}else{$("#postform #submitbutton").attr("disabled","disabled")}});$("#postform #posttype").change(function(A){var B=$("#postform #posttype").attr("value");Channels.Controllers.UserCreatedContentPost.SwitchType(B)});$("#postformcontroller #cancelpost").click(function(A){A.preventDefault();var B=$("#postform #posttype").attr("value");Channels.Controllers.UserCreatedContentPost.CancelPost(B)});$(".inlinks a.showmore").live("click",function(B){B.preventDefault();var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Link.ShowAll(A)});$(".likes a.showmore").live("click",function(B){B.preventDefault();var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Like.ShowAll(A)});$("#posttype").find("label").live("click",function(B){B.preventDefault();var A=$(this).find("input").attr("value");Channels.Controllers.UserCreatedContentPost.SwitchType(A)});$(EXTERNALCOMMENT_MORECOMMENTS_PATTERN).live("click",function(D){D.preventDefault();var C=$(this).closest(".channelitem");var B=Channels.Models.ChannelItem.GetGuidFromDomNode(C);var A=C.find(".external:first .commentitem:not(.morecomments)");Channels.Controllers.ExternalComments.GetMore(B,A.length,10)});$(EXTERNALCOMMENT_SHOWCOMMENTS_PATTERN).live("click",function(C){C.preventDefault();var B=$(this).closest(".channelitem");var A=Channels.Models.ChannelItem.GetGuidFromDomNode(B);Channels.Controllers.ExternalComments.Show(A)});$(EXTERNALCOMMENT_HIDECOMMENTS_PATTERN).live("click",function(C){C.preventDefault();var B=$(this).closest(".channelitem");var A=Channels.Models.ChannelItem.GetGuidFromDomNode(B);Channels.Controllers.ExternalComments.Hide(A)});$(COMMENT_MORECOMMENTS_PATTERN).live("click",function(B){B.preventDefault();var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Comment.ShowMore(A,3)});$(".itemfooter .actionlinks .comment a").live("click",function(B){B.preventDefault();var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Comment.Write(A)});$(".itemfooter .actionlinks .hide a").live("click",function(B){B.preventDefault();var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.ChannelItem.Hide(A)});$(".itemfooter .actionlinks .like a").live("click",function(B){B.preventDefault();var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Like.Create(A)});$(".itemfooter .deletespan a.deletelink").live("click",function(B){B.preventDefault();if(confirm("Do you really want to delete this item?")){var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.ChannelItem.Delete(CHANNEL_NAME,A)}});$(COMMENT_INPUT_PATTERN).focus(Channels.Events.onCommentFocus);$(COMMENT_INPUT_PATTERN).blur(Channels.Events.onCommentBlur);$(".cancelcomment").click(function(D){D.preventDefault();var B=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Comment.Cancel(B);var C="canceled";var A=new Channels.Models.CommentNotification("",B,C,"");Channels.Controllers.CommentNotification.NotifyServer(CHANNEL_NAME,A)});$("form#postform").submit(function(D){D.preventDefault();var C=$("#postform #posttype").attr("value");var E=$("#titlearea").val();var A=$("#urlarea").val();var B=$("#contentarea").val();Channels.Controllers.UserCreatedContentPost.Send(CHANNEL_NAME,E,A,B,C);Channels.Controllers.UserCreatedContentPost.CancelPost(C)});$("form#postform .inputarea").focus(function(){$(this).parent().find(".infield").hide()});$("form#postform .inputarea").change(function(){$(this).parent().find(".infield").hide()});$("form#postform .inputarea").blur(function(){if($(this).val()==""){$(this).parent().find(".infield").show()}});$("#sidebar a.subscribe").live("click",function(A){A.preventDefault();Channels.Controllers.Subscription.Create(CHANNEL_NAME)});$("#changetotemlink").click(function(A){A.preventDefault();Channels.Controllers.Channel.ChangeTotem();$(this).blur()});$(".animatebuttontext").hover(function(){$(this).animate({"padding-left":"15px"},100)},function(){$(this).animate({"padding-left":"10px"},100)});$("#moreincominglink").click(function(A){A.preventDefault();this.blur();Channels.Controllers.ChannelItem.ShowMoreIncoming(this,CHANNEL_NAME)});$.ajaxSetup({error:function(C,B){if(C.status==530){var A=jQuery.parseJSON(C.responseText);window.location.replace(A.redirectUrl)}}})},SendComment:function(C){var B=C.find(COMMENT_INPUT_PATTERN).val();var A=Channels.Models.ChannelItem.GetGuidFromDomNode(C);Channels.Controllers.Comment.Create(A,B);Channels.Controllers.Comment.Cancel(A)},onCommentKeyUp:function(F){var C=$(this).closest(".channelitem");var B=Channels.Models.ChannelItem.GetGuidFromDomNode(C);if(F.ctrlKey&&F.which&&F.which==13){Channels.Events.SendComment(C)}else{if(F.which&&F.which==27){Channels.Controllers.Comment.Cancel(B)}}var E=(F.target.value.length===0||F.target.value=="Write a comment");var D=E?"canceled":"writing";var A=new Channels.Models.CommentNotification("",B,D,"");Channels.Controllers.CommentNotification.NotifyServer(CHANNEL_NAME,A)},onCommentSubmitClick:function(A){Channels.Events.SendComment($(this).closest(".channelitem"))},onCommentFocus:function(){var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Comment.FocusInput(A)},onCommentBlur:function(){var A=Channels.Models.ChannelItem.GetGuidFromDomNode($(this).closest(".channelitem"));Channels.Controllers.Comment.BlurInput(A)},initializeEventsForNewChannelItem:function(A){$(COMMENT_INPUT_PATTERN,A).focus(Channels.Events.onCommentFocus);$(COMMENT_INPUT_PATTERN,A).blur(Channels.Events.onCommentBlur)}}});Channels.extend({DateTimeHelper:{GetTimespanString:function(G){var C=new Date();var K=C.getTimezoneOffset()*(60*1000);var F=Math.floor(((C.getTime()+K)-G.getTime())/1000);if(F<=0){F=1}var J=Math.floor(F/60);var B=Math.floor(J/60);var H=Math.floor(B/24);var I=Math.floor(H/365);var A=Math.floor(H/30)-(I*12);var E=H-(A*30);var M=B-(E*24);var L=J-(M*60);var D="";if(I>0){if(I==1){D+="1 year"}else{D+=I+" years"}if(A>0){if(A==1){D+=" and 1 month"}else{D+=" and "+A+" months"}}}else{if(A>0){if(A==1){D+="1 month"}else{D+=A+" months"}if(E>0){if(E==1){D+=" and 1 day"}else{D+=" and "+E+" days"}}}else{if(E>0){if(E==1){D+="1 day"}else{D+=E+" days"}if(M>0){if(M==1){D+=" and 1 hour"}else{D+=" and "+M+" hours"}}}else{if(M>0){if(M==1){D+="1 hour"}else{D+=M+" hours"}if(L>0){if(L==1){D+=" and 1 minute"}else{D+=" and "+L+" minutes"}}}else{if(L>0){if(L==1){D+="1 minute"}else{D+=L+" minutes"}}else{D+="Less than one minute"}}}}}D+=" ago";return D}}});Channels.Controllers.extend({ChannelItem:{Add:function(I,B,F,C,J,E,G,A,D,H){Channels.Models.ChannelItem.Get(I,B,F,C,J,E,G,A,D,H,function(K){Channels.Views.ChannelItem.Render(B,K);Channels.Views.ChannelItem.UpdateMoreIncomingLink(I)},Channels.Views.Error.Render)},AddUcc:function(C,B){var A=new Channels.Models.ChannelItem(B,false);Channels.Views.ChannelItem.Render(C,A)},CreateUserCreatedContent:function(A,E,B,D,C){Channels.Models.ChannelItem.CreateUserCreatedContent(A,E,B,D,C,function(G,F){Channels.Views.ChannelItem.Render(G,F)},Channels.Views.Error.Render)},Delete:function(A,B){Channels.Models.ChannelItem.Delete(A,B,Channels.Views.ChannelItem.Delete,Channels.Views.Error.Render)},Hide:function(A){Channels.Views.ChannelItem.Hide(A)},ShowMoreIncoming:function(B,A){$("#showmorearea a.showmore").hide();$("#showmorearea div.loader").show();var C=$(B).attr("href")+".json";Channels.Models.ChannelItem.GetMoreIncoming(C,function(E,D){Channels.Views.ChannelItem.RenderMoreIncoming(D);Channels.Views.ChannelItem.UpdateMoreIncomingLink(A);if(E){$("#showmorearea a.showmore").show();$("#showmorearea div.loader").hide()}else{$("#showmorearea").hide()}},Channels.Views.Error.Render)}}});Channels.Controllers.extend({Comment:{Add:function(B,E,D,A){var F=new Channels.Models.CommentNotification(B,E,"","");Channels.Controllers.CommentNotification.RemoveNotification(F);var C=new Channels.Models.Comment(B,E,D,false,A);Channels.Views.Comment.RenderComment(E,C,3)},Create:function(A,B){Channels.Models.Comment.Create(A,B,function(C){var D=new Channels.Models.CommentNotification(C.authorName,C.channelDocumentGuid,"","");Channels.Controllers.CommentNotification.RemoveNotification(D);Channels.Views.Comment.RenderComment(A,C,3)},function(C){Channels.Views.Error.Render(C)});Channels.Views.Comment.FocusCommentInput(A,true)},ShowMore:function(A,B){Channels.Views.Comment.ShowMoreComments(A,B)},Write:function(A){if(Channels.redirectIfNotSignedIn()){return }Channels.Views.Comment.RenderCommentInput(A,true);Channels.Views.Comment.FocusCommentInput(A)},FocusInput:function(A){Channels.Views.Comment.FocusCommentInput(A,false)},BlurInput:function(A){Channels.Views.Comment.BlurCommentInput(A)},Cancel:function(A){Channels.Views.Comment.CancelCommentInput(A)}}});Channels.Controllers.extend({CommentNotification:{NotifyUser:function(A){Channels.Views.CommentNotification.Render(A);setTimeout(Channels.Controllers.CommentNotification.RemoveNotification,60000,A)},NotifyServer:function(B,A){var E=Channels.Models.CommentNotificationGlobal.TimerMap;var D=E.get(A.cdocGuid);var C=(new Date()).getTime();if(A.state!=D.state){E.clear(A.cdocGuid);D.time=undefined}if(D.time===undefined||D.time<C-Channels.Models.CommentNotificationGlobal.SERVER_UPDATE_INTERVAL){Channels.Models.CommentNotification.SendWritingCommentNotification(B,A);E.update(A.cdocGuid,A.state)}},RemoveNotification:function(A){Channels.Views.CommentNotification.RemoveNotification(A);Channels.Models.CommentNotificationGlobal.TimerMap.clear(A.cdocGuid)}}});Channels.Controllers.extend({ExternalComments:{Add:function(C,A,B,D){Channels.Models.ExternalComments.Get(A,B,function(E){Channels.Views.ExternalComments.Add(C,D,E)})},Show:function(A){Channels.Views.ExternalComments.Show(A)},Hide:function(A){Channels.Views.ExternalComments.Hide(A)},GetMore:function(B,A,C){Channels.Models.ExternalComments.GetMore(B,A,C,function(D){Channels.Views.ExternalComments.Render(B,D)})}}});Channels.Controllers.extend({Like:{Add:function(C,B,A){var D=new Channels.Models.Like(B,A,false);Channels.Views.Like.Render(C,D)},Create:function(A){Channels.Models.Like.Create(A,function(B){Channels.Views.Like.RemoveLink(A,B);Channels.Views.Like.Render(A,B)},function(B){Channels.Views.Error.Render(B)})},ShowAll:function(A){Channels.Views.Like.ShowAll(A)}}});Channels.Controllers.extend({Link:{Add:function(C,A,D,B){Channels.Models.Link.Get(C,A,D,function(E){Channels.Views.Link.Render(C,E)})},ShowAll:function(A){Channels.Views.Link.ShowAll(A)}}});Channels.Controllers.extend({Login:{Login:function(B,A){},Logout:function(){},SignUp:function(D,B,A,C){},RequestInvitationCode:function(A){Channels.Models.Login.RequestInvitationCode(A)}}});Channels.Controllers.extend({Popular:{UpdatePopular:function(A){if(!Channels.Models.Popular.PopularListUpdate){Channels.Models.Popular.PopularListUpdate=A.popularList;Channels.Views.Popular.DetectPopularUpdates()}else{Channels.Models.Popular.PopularListUpdate=A.popularList}}}});Channels.Controllers.extend({Subscription:{Add:function(A){Channels.Views.Subscription.Render(A)},Create:function(A){if(Channels.redirectIfNotSignedIn()){return }Channels.Views.Subscription.RenderTrying();Channels.Models.Subscription.Create(A,function(B){Channels.Views.Subscription.RenderSubscriptionOk();Channels.Views.Subscription.Render(B);Channels.Views.Subscription.AddSelf()},function(B){Channels.Views.Subscription.RenderSubscriptionFailed(B);Channels.Views.Error.Render(B)})},ShowAll:function(){Channels.Views.Subscription.ShowAll()}}});Channels.Controllers.extend({UserCreatedContentPost:{Send:function(A,E,B,D,C){Channels.Controllers.ChannelItem.CreateUserCreatedContent(A,E,B,D,C)},SwitchType:function(B){var A=new Channels.Models.UserCreatedContentPost(B);Channels.Views.UserCreatedContentPost.Render(A)},Activate:function(B){var A=new Channels.Models.UserCreatedContentPost(B);Channels.Views.UserCreatedContentPost.Activate(A)},CancelPost:function(B){var A=new Channels.Models.UserCreatedContentPost(B);Channels.Views.UserCreatedContentPost.Cancel(A)},GetLinkTitle:function(A){Channels.Views.UserCreatedContentPost.GetLinkTitle(A)}}});Channels.Controllers.extend({Channel:{ChangeTotem:function(){Channels.Views.Channel.ShowChangeTotemScreen()}}});Channels.Models.ChannelItem=function(B,A){this.html=B;this.isPending=A};Channels.Models.ChannelItem.BuildDomId=function(A){return"#cd_"+A};Channels.Models.ChannelItem.GetGuidFromDomNode=function(C){var D=C.attr("id");var B=new RegExp("cd_([a-zA-Z0-9-]+)");var A=D.match(B);if(A.length==2){return A[1]}return null};Channels.Models.ChannelItem.Get=function(K,C,H,D,L,F,I,B,E,J,A,G){$.get(Channels.Api.Urls.GetNewIncomingDocumentEvent,{channelName:K,channelItemGuid:C,url:H,title:D.substr(0,200),content:L.substr(0,500),contentType:F,createdStr:I,websiteUrl:B,websiteTitle:E.substr(0,200),imageUrl:J},function(M,N){if(M!=null){if(M.error!=null){G(M.error)}else{A(new Channels.Models.ChannelItem(M.html,false))}}else{A("Could not get response")}},"json")};Channels.Models.ChannelItem.GetMoreIncoming=function(A,C,B){$.get(A,{count:10},function(E,G){if(E!=null){if(E.error!=null){B(E.error)}else{var F=[];for(var D=0;D<E.items.length;++D){F[D]=new Channels.Models.ChannelItem(E.items[D].html,false)}C(E.hasMoreItems,F)}}else{C("Could not get response")}},"json")};Channels.Models.ChannelItem.CreateUserCreatedContent=function(A,G,B,F,E,D,C){$.post(Channels.Api.Urls.CreateUserCreatedContent,{channelName:A,contentUrl:B,content:F,title:G,type:E},function(H,I){if(H!=null){if(H.error!=null){C(H.error)}else{D(H.id,new Channels.Models.ChannelItem(H.html,true))}}else{C("Could not get response")}},"json")};Channels.Models.ChannelItem.Delete=function(A,D,C,B){$.post(Channels.Api.Urls.DeleteChannelItem,{channelName:A,guid:D},function(E,F){if(E!==null){if(E.error!=null){B(E.error)}else{C(D)}}else{B("Could not get response")}},"json")};Channels.Models.Comment=function(A,E,D,B,C){this.authorName=A;this.channelDocumentGuid=E;this.html=D;this.isPending=B;this.guid=C};Channels.Models.Comment.BuildDomId=function(A){return"#comment_"+A};Channels.Models.Comment.Create=function(C,D,B,A){Channels.makeRequest(Channels.Api.Urls.CreateComment,{channelName:CHANNEL_NAME,channelItemGuid:C,content:D},function(E,F){if(E!=null){if(E.error!=null){A(E.error)}else{B(new Channels.Models.Comment(E.author_name,E.comment_on,E.html,true,E.comment_guid))}}else{A(F)}})};Channels.Models.CommentNotification=function(C,B,D,A){this.author=C;this.cdocGuid=B;this.state=D;this.html=A};Channels.Models.CommentNotification.prototype.key=function(){return this.author+"#"+this.cdocGuid};Channels.Models.CommentNotification.SendWritingCommentNotification=function(B,A){$.post(Channels.Api.Urls.SendWritingCommentNotification,{channelName:B,channelDocumentGuid:A.cdocGuid,state:A.state},function(C,D){},"json")};Channels.Models.extend({CommentNotificationGlobal:{EntryMap:{map:{},put:function(A,B){Channels.Models.CommentNotificationGlobal.EntryMap.map[A.key()]=B},get:function(A){var B=Channels.Models.CommentNotificationGlobal.EntryMap.map[A.key()];if(B===undefined){B={};Channels.Models.CommentNotificationGlobal.EntryMap.put(A,B)}return B},remove:function(A){delete Channels.Models.CommentNotificationGlobal.EntryMap.map[A.key()]}},TimerMap:{map:{},get:function(B){var A=Channels.Models.CommentNotificationGlobal.TimerMap.map[B];if(A===undefined){A={}}return A},update:function(B,C){var A=(new Date()).getTime();Channels.Models.CommentNotificationGlobal.TimerMap.map[B]={time:A,state:C}},clear:function(A){delete Channels.Models.CommentNotificationGlobal.TimerMap.map[A]}},SERVER_UPDATE_INTERVAL:20000}});Channels.Models.ExternalComments=function(C,A,B){this.commentsHtmlList=C;this.commentDomIds=B;this.hasMoreComments=A};Channels.Models.ExternalComments.GetMore=function(C,B,D,A){$.get(Channels.Api.Urls.GetMoreExternalComments,{channelItemGuid:C,startAt:B,count:D},function(E){if(E.comments!=null){var F=[];for(var G=0;G<E.comments.length;G++){F[G]=E.comments[G].html}A(new Channels.Models.ExternalComments(F,E.has_more_comments))}},"json")};Channels.Models.ExternalComments.Get=function(A,C,B){$.get(Channels.Api.Urls.GetNewExternalCommentEvent,{externalCommentId:A},function(D){if(D.html!=null){B(D.html)}},"json")};Channels.Models.Like=function(C,B,A){this.html=C;this.guid=B;this.isPending=A};Channels.Models.Like.BuildDomId=function(A){return"#like_"+A};Channels.Models.Like.Create=function(C,B,A){Channels.makeRequest(Channels.Api.Urls.CreateLike,{channelItemGuid:C},function(D,E){if(D!=null){if(D.error!=null){A(D.error)}else{B(new Channels.Models.Like(D.html,D.guid,true))}}else{A(E)}})};Channels.Models.Link=function(B,A){this.html=B;this.linkUrl=A};Channels.Models.Link.BuildDomId=function(A){return"#link_"+A};Channels.Models.Link.Get=function(C,A,D,B){$.get(Channels.Api.Urls.GetNewLinkEvent,{channelItemGuid:C,linkUrl:A,websiteTitle:D},function(E,F){if(E!=null){B(new Channels.Models.Link(E.html,A))}},"json")};Channels.Models.extend({Login:{RequestInvitationCode:function(A){$.post(Channels.Api.Urls.RequestInvitationCode,{email:A},function(B,C){Channels.Views.Login.SetMessage(B.message)})}}});Channels.Models.Popular=function(A){this.popularList=A};Channels.Models.Popular.GetCurrentPopularList=function(){var E=new Array();var A=$("#channelitems");var C=A.children();for(var B=0;B<C.length;++B){var F=C[B];var D={guid:F.id.substring(3),html:""};E.push(D)}return E};Channels.Models.Popular.InsertPopularItem=function(B,A){if(B.html.length>0){Channels.Views.Popular.CreatePopularItem(B,A)}else{$.get(Channels.Api.Urls.GetPopularChangedEvent,{guid:B.guid},function(C,D){if(C!=null){Channels.Views.Popular.CreatePopularItem(C.popular_list[0],A)}},"json")}};Channels.Models.Subscription=function(B,C,A){this.html=B;this.userGuid=C;this.isPending=A};Channels.Models.Subscription.BuildDomId=function(A){return"#subscription_"+A};Channels.Models.Subscription.Create=function(A,C,B){$.post(Channels.Api.Urls.CreateSubscription,{channelName:A},function(D,E){if(D!=null){if(D.error!=null){B(D.error)}else{C(new Channels.Models.Subscription(D.html,D.user_id,true))}}else{B(E)}},"json")};Channels.Models.UserCreatedContentPost=function(A){this.type=A};Channels.Models.UserCreatedContentPost.GetDomIdForType=function(A){return"#post"+A};Channels.Views.extend({ChannelItem:{VisibleItemCount:30,Render:function(E,B){var C=$(Channels.Models.ChannelItem.BuildDomId(E));if(C.length>0){if(!B.isPending&&C.hasClass("pending")){C.removeClass("pending")}if(B.isPending&&!C.hasClass("pending")){C.addClass("pending")}return }var D=$(B.html);if(B.isPending){D.addClass("pending")}D.hide();var A=$(".channelitem:gt("+(Channels.Views.ChannelItem.VisibleItemCount-2)+")");Channels.updateDocumentTimestamps();$("#userpostarea").after(D);Channels.Events.initializeEventsForNewChannelItem(D);A.remove();D.slideDown("fast")},RenderMoreIncoming:function(A){var D=$(".channelitem:last");var C=[];for(var B=0;B<A.length;++B){C[B]=A[B].html}$(C.join("")).insertAfter(D);Channels.updateDocumentTimestamps();Channels.Views.ChannelItem.VisibleItemCount+=A.length},UpdateMoreIncomingLink:function(A,C){var D=Channels.Models.ChannelItem.GetGuidFromDomNode($(".channelitem:last"));var B="/"+A+"/incoming/more/"+D;$("#moreincominglink").attr("href",B)},Hide:function(A){$(Channels.Models.ChannelItem.BuildDomId(A)).hide("fast")},Delete:function(B){var A=$(Channels.Models.ChannelItem.BuildDomId(B));A.slideUp("normal",function(){$(this).remove()})}}});Channels.Views.extend({CommentNotification:{Render:function(B){var F=B.author;var A=B.cdocGuid;var G=B.html;var C=B.state;var I=Channels.Models.CommentNotificationGlobal.EntryMap.get(B);var E=I.element;if(E===undefined){E=$(G).hide();var D=$("#cd_"+A+" .itemextra .comments.internal .commentform");var H=D.parent();if(H.is(":hidden")){H.show();D.hide()}E.insertBefore(D);Channels.Views.CommentNotification._FixDomStyling(H);I.element=E}E.find(".comment").hide();E.find(".comment."+C).show();if(C=="canceled"){E.customFadeOut("slow",function(){if(E.is(":hidden")){var J=E.parent();var K=J.find(".commentform");if(K.is(":hidden")){K.parent().hide()}E.remove();Channels.Models.CommentNotificationGlobal.EntryMap.remove(B);Channels.Views.CommentNotification._FixDomStyling(J)}})}else{E.customFadeIn("slow")}},_FixDomStyling:function(B){B.find(".commentitem:first").addClass("nocommentbg");var A=B.find(".commentitem").length;if(A==0&&B.children(":visible").length==0){B.hide()}else{B.show()}},RemoveNotification:function(B){var D=Channels.Models.CommentNotificationGlobal.EntryMap.get(B);if(D.element!==undefined){var C=D.element.parent();var A=C.find(".commentform");if(A.is(":hidden")){C.hide()}D.element.remove();Channels.Models.CommentNotificationGlobal.EntryMap.remove(B);Channels.Views.CommentNotification._FixDomStyling(C)}}}});Channels.Views.extend({Comment:{RenderComment:function(C,I,F){var D=$(Channels.Models.ChannelItem.BuildDomId(C)).find(".itemextra .comments.internal");var G=$(Channels.Models.Comment.BuildDomId(I.guid));if(G.length==0){var E=$(I.html);if(I.isPending){E.addClass("pending")}var H=D.find(".morecomments");var A=D.find(".commentitem:visible");var B=H.find(".commentscount");B.text(parseInt(B.text())+1);D.find(".commentform").before(E)}else{G.removeClass("pending")}Channels.Views.CommentNotification._FixDomStyling(D)},ShowMoreComments:function(F,G){var B=$(Channels.Models.ChannelItem.BuildDomId(F)).find(".itemextra .comments:not(.external):first");var A=B.find(".commentitem:hidden");var E=B.find(".commentitem:visible");var C=A.length-G;if(G>=A.length){B.find(".showolder").hide();C=0}$(E[0]).removeClass("nocommentbg");for(var D=A.length-1;D>=C;D--){if(D==C){$(A[D]).addClass("nocommentbg")}$(A[D]).show()}},RenderCommentInput:function(D,B){var A="Write a comment";var C=$(Channels.Models.ChannelItem.BuildDomId(D)).find(".comments .commentform textarea:last");if(B){C.parent().show().parent().show("fast",function(){C.focus()})}else{}},FocusCommentInput:function(C,A){var B=$(Channels.Models.ChannelItem.BuildDomId(C)).find(".comments .commentform textarea");B.parent().find(".commentcontrols").show();B.removeClass("inactive");if(B.val()==DEFAULT_COMMENT_STRING||A){B.val("")}},BlurCommentInput:function(B){var A=$(Channels.Models.ChannelItem.BuildDomId(B)).find(".comments .commentform textarea");if(A.val()==""){A.addClass("inactive");A.val(DEFAULT_COMMENT_STRING)}},CancelCommentInput:function(B){var A=$(Channels.Models.ChannelItem.BuildDomId(B)).find(".comments .commentform textarea");A.animate({height:"18px"},"fast");A.parent().find(".commentcontrols").slideUp();A.addClass("inactive");A.val(DEFAULT_COMMENT_STRING);A.blur()}}});Channels.Views.extend({Error:{Render:function(A){$("#logger").html($("<pre>"+A+"</pre>"))}}});Channels.Views.extend({ExternalComments:{Render:function(F,C){var A=$(Channels.Models.ChannelItem.BuildDomId(F)).find(".external");var B=A.find(".footer");B.remove();for(var E=0;E<C.commentsHtmlList.length;E++){var D=$(C.commentsHtmlList[E]);if(E==C.commentsHtmlList.length-1){D.addClass("nocommentbg")}A.append(D)}A.append(B);if(C.hasMoreComments){B.show()}else{B.hide()}},Add:function(D,C,H){var A=$(Channels.Models.ChannelItem.BuildDomId(D)).find(".external");if(A.length!=1){return }var J=A.find("#"+C);if(J.length!=0){return }$(A[0]).show();var K=$(A.find(".morecomments")[0]);K.after(H);var L=A.find(".footer :visible").length!=0;var G=A.find(".footer");var M=A.find(".commentitem");for(var F=1;F<M.length-1;F++){var E=$(M[F]);if(F==1){if(!E.hasClass("nocommentbg")){E.addClass("nocommentbg")}}else{if(E.hasClass("nocommentbg")){E.removeClass("nocommentbg")}}if(F<=3||L){E.show()}else{E.hide()}}if(M.length>(10+2)){$(M[M.length-2]).remove()}if(M.length>2&&L==false){K.show()}var B=A.find(".counter");if(B.length>0){var E=$(B[0]);var I=parseInt(E.text());I+=1;E.text(I)}},Show:function(D){var B=$(Channels.Models.ChannelItem.BuildDomId(D)).find(".external");var A=B.find(".commentitem:hidden");for(var C=0;C<A.length;C++){$(A[C]).show()}var E=B.find(".show");E.addClass("hider");E.html("Hide");B.find(".externalcommmentslist").show()},Hide:function(C){var A=$(Channels.Models.ChannelItem.BuildDomId(C)).find(".external");var E=A.find(".commentitem");for(var B=0;B<E.length;B++){$(E[B]).hide()}A.find(".morecomments.footer").hide();A.find(".controlarea").show();var D=A.find(".hider");D.removeClass("hider");D.html("Show")}}});Channels.Views.extend({Like:{RemoveLink:function(C,F){var E=$(Channels.Models.ChannelItem.BuildDomId(C));var B=E.find(".likes");var A=E.find("li.like a");var D=A.text();A.remove();E.find("li.like").append(D)},Render:function(G,A){var J=$(Channels.Models.ChannelItem.BuildDomId(G));var C=J.find(".likes");var D=$(Channels.Models.Like.BuildDomId(A.guid));if(D.length==0){var B=C.find(".showmore_count");if(B.length>0){var I=parseInt(B.text());B.text(I+1)}var H=$(A.html);var E=C.find(".likeitem:first");var F=C.find(".label");F.after(H).after(" ");if(E.length>0){C.find(".likeitem:first").after(", ")}if(A.isPending){H.addClass("pending")}C.find(".label").after(H)}else{D.removeClass("pending")}C.show("fast")},ShowAll:function(E){var A=$(Channels.Models.ChannelItem.BuildDomId(E)+" .likes");A.find(".showmore").hide();var D=A.find(".likeitem:hidden");var C=A.find(".likeitem:visible:last");C.append(", ");for(var B=0;B<D.length;B++){$(D[B]).show()}}}});Channels.Views.extend({Link:{Render:function(D,I){var J=$(Channels.Models.ChannelItem.BuildDomId(D));var A=J.find(".inlinks");if(A.find("a[href='"+I.linkUrl+"']").length>0){return }var C=A.find(".showmore_count");if(C.length>0){var H=parseInt(C.text());C.text(H+1)}var E=$(I.html);var K=A.find(".discussion_item:first");var B=A.find(".label");var F=B.find(".labelcount");var G=parseInt(F.html());F.html(G+1);B.after(E).after(" ");if(K.length>0){A.find(".discussion_item:first").after(", ")}A.show("fast")},ShowAll:function(E){var A=$(Channels.Models.ChannelItem.BuildDomId(E)+" .inlinks");A.find(".showmore").hide();var D=A.find(".discussion_item:hidden");var C=A.find(".discussion_item:visible:last");C.parent().append(", ");for(var B=0;B<D.length;B++){$(D[B]).parent().show()}}}});Channels.Views.extend({Login:{SetMessage:function(B){var A=$("#loginmessage");A.empty().append("<p>"+B+"</p>")}}});Channels.Views.extend({Popular:{DetectPopularUpdates:function(B){if(Channels.Models.Popular.PopularListUpdate){var A=Channels.Models.Popular.PopularListUpdate;if(Channels.Views.Popular.DetectExpiredPopularItems(A)){return }if(Channels.Views.Popular.DetectNewOrRepositionedPopularItems(A)){return }Channels.Models.Popular.PopularListUpdate=false}},DetectExpiredPopularItems:function(F){var D=Channels.Models.Popular.GetCurrentPopularList();for(var C=0;C<D.length;++C){var E=D[C];var A=true;for(var B=0;B<F.length;++B){if(F[B].guid==E.guid){A=false;break}}if(A){Channels.Views.Popular.DeletePopularItem($("#cd_"+E.guid));return true}}return false},DetectNewOrRepositionedPopularItems:function(E){var C=Channels.Models.Popular.GetCurrentPopularList();for(var B=0;B<E.length;++B){if(B>=C.length||E[B].guid!=C[B].guid){var D=$("#cd_"+E[B].guid);if(D.length>0){var A=$("#cd_"+C[B].guid);Channels.Views.Popular.MovePopularItem(D,A);return true}else{var A=$("#channelitems > div:eq("+B+")");Channels.Models.Popular.InsertPopularItem(E[B],A);return true}}}return false},DeletePopularItem:function(A){Channels.Views.Popular.NotifyPopularItem(A,"This item is about to be removed from popular.",function(B){A.animate({height:"hide",opacity:"hide",marginBottom:0},3000,function(){A.remove();Channels.Views.Popular.DetectPopularUpdates()})})},MovePopularItem:function(B,A){Channels.Views.Popular.NotifyPopularItem(B,"This item is about to move up!",function(){B.animate({opacity:0},"slow",function(){$("#tw_popnotification").remove();var C=$("<div>&nbsp;</div>").css({height:B.height()+30}).hide().insertBefore(A).slideDown(3000);B.animate({height:0,marginBottom:0},3000,function(){B.css({height:"auto",opacity:0,marginBottom:"30px"}).insertBefore(A);C.remove();B.animate({opacity:1},"slow",function(){Channels.Views.Popular.DetectPopularUpdates()})})})})},CreatePopularItem:function(B,A){if(A.length>0){var C=$(B.html).hide().insertBefore(A).css({marginBottom:0}).animate({height:"show",marginBottom:"30px"},"slow",function(){Channels.Views.Popular.DetectPopularUpdates()})}else{var C=$(B.html).hide().appendTo($("#channelitems")).css({marginBottom:0}).animate({height:"show",marginBottom:"30px"},"slow",function(){Channels.Views.Popular.DetectPopularUpdates()})}},NotifyPopularItem:function(C,E,D,F){var B=$("<div id='tw_popnotification'>"+E+" <span id='tw_countdown'></span></div>").css({position:"absolute",top:C.offset().top,left:C.offset().left,border:"5px solid #eee",padding:"5px",backgroundColor:"#fff"}).hide().appendTo(C).customFadeIn("slow");if(F!=false){var A=new Date();A.setTime(A.getTime()+9500);$("#tw_countdown").countdown({target:A,onTick:function(K,G,I,H,J){K.text("("+J+" s)")},onFinish:D})}}}});Channels.Views.extend({Subscription:{Render:function(I){var D=Channels.Models.Subscription.BuildDomId(I.userGuid);var F=$(D);if(F.length==0){var K=$("#sidebar .subscriberlist");var E=$(I.html);var B=K.find("li");var A=$("#subscribers .metainfo a");var H=parseInt(A.html());A.html(H+1);var C=$("#subscribers .footermetainfo a .number");var J=parseInt(C.html());C.html(J+1);if(B.length==70){var G=$(B[B.length-1]);G.remove()}K.prepend(E)}F=$(D);if(I.isPending){F.addClass("pending")}else{F.removeClass("pending")}},ShowAll:function(E){var A=$(Channels.Models.ChannelItem.BuildDomId(E)+" .likes");A.find(".showmore").hide();var D=A.find(".likeitem:hidden");var C=A.find(".likeitem:visible:last");C.parent().append(", ");for(var B=0;B<D.length;B++){$(D[B]).parent().show()}},AddSelf:function(){var D=$("#sidebar a.subscribe");var B=D.closest("div.subscribetop");var C=D.parent();C.find("a").remove();C.append("<span class='subscribed'>You are subscribed to this channel.</span>");var A=encodeURIComponent("I just subscribed to http://twingly.com/"+CHANNEL_NAME);B.after('<a href="http://twitter.com/home?status='+A+'" class="tweetlink">Tweet about this channel!</a>')},PopupSetTitle:function(B,A){$("#"+B+" .title").html(A)},PopupSetContent:function(B,A){$("#"+B+" .content").html(A)},CreatePopup:function(E,D,C){var B=$("#"+E);if(B.length>0){Channels.Views.Subscription.PopupSetTitle(E,D);Channels.Views.Subscription.PopupSetContent(E,C);return }var A=$('<div id="'+E+'" class="jqmWindow" style="display: none;"><div class="title">'+D+'</div><a href="#" class="jqmClose jqmCloseButton">&nbsp;</a><div class="content">'+C+'</div><div class="tweetlinks centercontent"><a href="http://twitter.com/home?status=I just subscribed to http://twingly.com/'+CHANNEL_NAME+'" id="tweetlink">OK, tweet my subscription</a><br /><a href="#" id="subclose" class="jqmClose">No thanks, just subscribe me</a></div></div>');$("body").append(A);$("#"+E).jqm({onHide:function(F){F.o.remove();$("#"+E).remove()}});$("#"+E).jqmShow();$("#"+E).jqmAddClose("#subclose")},RenderTrying:function(){Channels.Views.Subscription.CreatePopup("subpopupjqm","Trying to subscribe","Trying to subscribe to "+$("#sidebarchannelname").html())},RenderSubscriptionOk:function(){$(".jqmWindow").addClass("successfulSubscription");Channels.Views.Subscription.PopupSetTitle("subpopupjqm","You are now subscribed");Channels.Views.Subscription.PopupSetContent("subpopupjqm","You are now subscribed to "+$("#sidebarchannelname").html())},RenderSubscriptionFailed:function(A){Channels.Views.Subscription.PopupSetTitle("subpopupjqm","Subscription failed");Channels.Views.Subscription.PopupSetContent("subpopupjqm","Error occured during subscription: "+A)},}});Channels.Views.extend({UserCreatedContentPost:{Render:function(A){$("#titlearea").val("").focus().blur();$("#urlarea").val("").focus().blur();$("textarea.inputarea").val("").focus().blur();$("#postform #submitbutton").attr("disabled","disabled");switch(A.type){case"link":$("#postbox_title").slideDown("fast");$("#postbox_url").slideDown("fast");$("#postbox_content").slideUp("fast");break;case"note":$("#postbox_title").slideUp("fast");$("#postbox_url").slideUp("fast");$("#postbox_content").slideDown("fast");break;default:$("#postbox_title").css("display","none");$("#postbox_url").css("display","block");$("#postbox_content").css("display","none");break}$("#postformcontroller").slideDown("fast")},Activate:function(A){$("#postform #submitbutton").attr("disabled","disabled");switch(A.type){case"link":$("#postbox_title").slideDown("fast");$("#postbox_url").slideDown("fast");$("#postbox_content").slideUp("fast");break;case"note":$("#postbox_title").slideUp("fast");$("#postbox_url").slideUp("fast");$("#postbox_content").slideDown("fast");break;default:$("#postbox_title").css("display","none");$("#postbox_url").css("display","block");$("#postbox_content").css("display","none");break}$("#postformcontroller").slideDown("fast")},Cancel:function(A){$("#titlearea").val("").focus().blur();$("#urlarea").val("").focus().blur();$("textarea.inputarea").val("").focus().blur();switch(A.type){case"link":$("#postbox_title").slideUp("fast");$("#postbox_url").slideDown("fast");$("#postbox_content").slideUp("fast");break;case"note":$("#postbox_title").slideUp("fast");$("#postbox_url").slideUp("fast");$("#postbox_content").slideDown("fast");$("textarea.inputarea").animate({height:"18px"},"fast");break;default:$("#postbox_title").css("display","none");$("#postbox_url").css("display","block");$("#postbox_content").css("display","none");break}$("#postformcontroller").slideUp("fast")},GetLinkTitle:function(A){$("form#postform #titlearea").removeClass("manual");clearTimeout(delayed);$("#titleloader").fadeOut("fast",function(){var B='Fetching title <img src="http://localhost.static.twingly.com/content/images/channel/loader-title.gif" alt="" height="16" width="16" style="margin-top: 3px;" />';$("#titleloader").html(B)});delayed=setTimeout(function(){if(!$("form#postform #titlearea").hasClass("manual")){$("#titleloader").fadeIn("normal")}$.getJSON("/usercreatedcontent/gettitleforurl?url="+A,function(B){if(!$("form#postform #titlearea").hasClass("manual")){$("form#postform #titlearea").val(B.title);$("form#postform #titlearea").parent().find(".infield").hide();$("#titleloader").fadeOut("normal",function(){if(B.title==""){$("#titleloader").html("Please enter a title");$("#titleloader").fadeIn("normal")}else{$("#postform #submitbutton").removeAttr("disabled")}})}})},1000)}}});Channels.Views.extend({Channel:{ShowChangeTotemScreen:function(){$("#changetotemform").slideToggle("fast")}}});(function(A){A.fn.customFadeIn=function(B,C){A(this).fadeIn(B,function(){if(jQuery.browser.msie&&parseInt(A.browser.version)==7){A(this).get(0).style.removeAttribute("filter")}if(C!=undefined){C()}})};A.fn.customFadeOut=function(B,C){A(this).fadeOut(B,function(){if(jQuery.browser.msie&&parseInt(A.browser.version)==7){A(this).get(0).style.removeAttribute("filter")}if(C!=undefined){C()}})}})(jQuery);$(document).ready(function(){if(typeof CHANNEL_TOPIC_NAME!="undefined"&&CHANNEL_TOPIC_NAME!=null){try{var A=new Channels.Client(QUEUE_SERVER,CHANNEL_TOPIC_NAME);A.start()}catch(B){Channels.Views.Error.Render("Failed to init channels client")}Channels.Events.connectEvents();setInterval("Channels.updateDocumentTimestamps()",60*1000)}$("#contentarea").autoResize({extraSpace:20})});Channels.Views.extend({Login:{SetMessage:function(A){Channels.Views.Login._SetMessage("messagearea",A)},SetErrorMessage:function(A){Channels.Views.Login._SetMessage("errorarea",A)},_SetMessage:function(B,C){function A(){var D=$("."+B);if(D.length==0){$('<div class="'+B+'">'+C+"</div>").appendTo("#messages")}else{D.empty().append(C).customFadeIn("slow")}}$("#messages .messagearea, #messages .errorarea").hide();A()},SetErrorContactingServerMessage:function(){Channels.Views.Login.SetErrorMessage("Could not contact server, try again in a few minutes.")},FillOutLogin:function(B,A){$("#loginusername").val(B);$("#loginpassword").val(A);$("#loginsubmit").focus()},FocusFirstInputField:function(){$(".registerform:visible").find("input:visible:first").focus()},ShowTab:function(B,A){var C=$("#signinform");if(B=="signup"){C=$("#signupform")}else{if(B=="password"){C=$("#requestpasswordform")}}var D="fast";var E=C.parent().children(".signinformarea:visible");function F(){if(A==null||A==""){Channels.Views.Login.FocusFirstInputField()}else{C.find("[name='"+A+"']").focus()}}if(E[0]!=C[0]){E.customFadeOut(D,function(){C.customFadeIn(D,function(){F()})})}else{F()}}}});Channels.Models.extend({Login:{SignUp:function(C,E,B,A){var D={};D["User.Name"]=E;D["User.Email"]=B;D.password=A;$.post(C,D,function(F,G){if(G!="success"){Channels.Views.Login.SetErrorContactingServerMessage()}else{if(F.success){Channels.Views.Login.SetMessage(F.message);Channels.Views.Login.FillOutLogin(E,A);Channels.Views.Login.ShowTab("signin")}else{Channels.Views.Login.SetErrorMessage(F.message)}}},"json")}}});Channels.Controllers.extend({Login:{SignUp:function(D,E,C,B){var A=$(D).attr("action")+".json";Channels.Models.Login.SignUp(A,E,C,B)},ShowTab:function(B,A){Channels.Views.Login.ShowTab(B,A)}}});$(document).ready(function(){$("#signupform form").submit(function(D){D.preventDefault();var C=this;var E=$("#signupname").val();var B=$("#signupemail").val();var A=$("#signuppassword").val();Channels.Controllers.Login.SignUp(C,E,B,A)});$(".signupbutton").bind("click",function(A){A.preventDefault();Channels.Controllers.Login.ShowTab("signup",null)});$(".signinbutton").bind("click",function(A){A.preventDefault();Channels.Controllers.Login.ShowTab("signin",null)});$(".passwordrequestbutton").bind("click",function(A){A.preventDefault();Channels.Controllers.Login.ShowTab("password",null)})});
