registerNS("TSCM.comment");YAHOO.util.Event.onDOMReady(function(){TSCM.comment=function(){var UTIL=YAHOO.util;var LANG=YAHOO.lang;var DOM=YAHOO.util.Dom;var EVENT=YAHOO.util.Event;var commentCounts={};var storyIdsFromAnchors=[];var hasCommentCountAnchors=[];var onCommentResultsSuccess=new UTIL.CustomEvent("comment results success");var onCommentResultsFailure=new UTIL.CustomEvent("comment results failure");var handleCommentResults={success:function(o){var resultObj=eval("("+o.responseText+")");if(!LANG.isObject(resultObj)||!LANG.isArray(resultObj.results)||(resultObj.results.length<1)){handleCommentResults.failure();return}for(i=0;i<resultObj.results.length;i++){var resultId=resultObj.results[i].id.toString();var messageCount=resultObj.results[i].messageCount.toString();commentCounts[resultId]=messageCount}onCommentResultsSuccess.fire()},failure:function(o){onCommentResultsFailure.fire()},scope:this,argument:null};return{requestCounts:function(sId){if(LANG.isValue(sId)){var url="/proxy/comment.ajaxaction?id="+sId;UTIL.Connect.asyncRequest("GET",url,handleCommentResults,null)}else{hasCommentCountAnchors=DOM.getElementsByClassName("hasCommentCount","a","bd");for(i=0;i<hasCommentCountAnchors.length;i++){storyIdsFromAnchors.push(hasCommentCountAnchors[i].id)}if(storyIdsFromAnchors.length<1){return}var idParam=new String(storyIdsFromAnchors.join());var url="/proxy/comment.ajaxaction?id="+idParam;UTIL.Connect.asyncRequest("GET",url,handleCommentResults,null)}},getCountById:function(sId){if(!LANG.isValue(commentCounts[sId])){return false}return commentCounts[sId]},displayHeadlineCounts:function(){for(i=0;i<hasCommentCountAnchors.length;i++){var count=TSCM.comment.getCountById(hasCommentCountAnchors[i].id);var link=hasCommentCountAnchors[i];if(count){link.innerHTML=["<em>",count,"</em>"].join("");DOM.addClass(link,"showCount")}}TSCM.ads.positionToPlaceholder({ad:"customUnit",placeholder:"cauContainer",flexibleHeight:true})},enableSeeAllCommentsLink:function(elLink){if(LANG.isUndefined(elLink)||LANG.isNull(elLink)){return}var count=TSCM.comment.getCountById(elLink.id);var linkText;if(!count){return}else{if(count==1){linkText=["<strong>",count,"</strong> Comment"].join("")}else{if(count>=2){linkText=["<strong>",count,"</strong> Comments"].join("")}}}elLink.innerHTML=linkText;elLink.style.visibility="visible"},enableAddCommentLink:function(elLink){if(LANG.isUndefined(elLink)||LANG.isNull(elLink)){return}var widgetAvailableCallback=function(){var commentBox=document.getElementById("PTWidgetComment_Talkback_Submit")||document.getElementById("ptwidgetcomment_Talkback_Submit");var commentBoxPosition=DOM.getXY(commentBox);elLink.onclick=function(){window.scrollTo(0,commentBoxPosition[1]);return false};if(elLink.id!="shareLinksComment"){elLink.innerHTML="Add Comment"}elLink.style.visibility="visible"};EVENT.onAvailable("PTWidgetComment_Talkback_Submit",widgetAvailableCallback);EVENT.onAvailable("ptwidgetcomment_Talkback_Submit",widgetAvailableCallback)},hideLoader:function(elUL){if(LANG.isUndefined(elUL)||LANG.isNull(elUL)){return}var loader_LI=DOM.getElementsByClassName("loading","li",elUL)[0];loader_LI.style.display="none"},init:function(){try{if(!DOM.get("story")){TSCM.comment.requestCounts();onCommentResultsSuccess.subscribe(function(){TSCM.comment.displayHeadlineCounts()})}}catch(e){}try{if(DOM.get("story")){if(TSCM.cfg.commentCountOn==="true"){TSCM.comment.requestCounts(TSCM.cfg.story.id)}else{var communityLinks_ULs=DOM.getElementsByClassName("communityLinks","ul","bd");for(i=0;i<communityLinks_ULs.length;i++){var seeAllComments_LI=DOM.getElementsByClassName("seeAllComments","li",communityLinks_ULs[i])[0];var addComment_LI=DOM.getElementsByClassName("addComment","li",communityLinks_ULs[i])[0];var addCommment_A;(addComment_LI)?addCommment_A=addComment_LI.firstChild:addCommment_A=null;TSCM.comment.hideLoader(communityLinks_ULs[i]);TSCM.comment.enableAddCommentLink(addCommment_A);if(!LANG.isUndefined(seeAllComments_LI)){seeAllComments_LI.style.display="none"}}}var resultsReadyCallback=function(){var currentStoryCommentCount=TSCM.comment.getCountById(TSCM.cfg.story.id);var communityLinks_ULs=DOM.getElementsByClassName("communityLinks","ul","bd");for(i=0;i<communityLinks_ULs.length;i++){var seeAllComments_LI=DOM.getElementsByClassName("seeAllComments","li",communityLinks_ULs[i])[0];var addComment_LI=DOM.getElementsByClassName("addComment","li",communityLinks_ULs[i])[0];var seeAllComments_A;var addCommment_A;(seeAllComments_LI)?seeAllComments_A=seeAllComments_LI.firstChild:seeAllComments_A=null;(addComment_LI)?addCommment_A=addComment_LI.firstChild:addCommment_A=null;if(!currentStoryCommentCount){seeAllComments_LI.style.display="none";TSCM.comment.hideLoader(communityLinks_ULs[i]);TSCM.comment.enableAddCommentLink(addCommment_A)}if(currentStoryCommentCount==1){DOM.get("recentComments").style.display="block";if(DOM.get("widget")){DOM.get("widget").style.display="block"}TSCM.comment.enableSeeAllCommentsLink(seeAllComments_A);TSCM.comment.hideLoader(communityLinks_ULs[i]);TSCM.comment.enableAddCommentLink(addCommment_A);if(communityLinks_ULs[i].id=="widget"){seeAllComments_LI.style.display="none"}}if(currentStoryCommentCount>=2){DOM.get("recentComments").style.display="block";if(DOM.get("widget")){DOM.get("widget").style.display="block"}TSCM.comment.enableSeeAllCommentsLink(seeAllComments_A);TSCM.comment.hideLoader(communityLinks_ULs[i]);TSCM.comment.enableAddCommentLink(addCommment_A)}}TSCM.comment.enableAddCommentLink(DOM.get("shareLinksComment"))};onCommentResultsFailure.subscribe(resultsReadyCallback);onCommentResultsSuccess.subscribe(resultsReadyCallback)}}catch(e){}}}}();TSCM.comment.init()});
