CBSi.namespace("app.GlobalNavigation");(function(){var Dom=YAHOO.util.Dom;var Event=YAHOO.util.Event;var Connect=YAHOO.util.Connect;var Log=YAHOO.log;var imageLoader=YAHOO.util.ImageLoader;CBSi.app.GlobalNavigation=function(args){if(typeof(args)!="object"){args={}}this.jsDebug=(typeof(args.jsDebug)!="undefined")?args.jsDebug:1;this.yuiLog=(typeof(args.yuiLog)!="undefined")?args.yuiLog:0;this.loggerId="yuiLogger";this.mediaDomain=(typeof(args.mediaDomain)!="undefined")?args.mediaDomain:"http://www.cbssports.com";this.navDataUrl=this.mediaDomain+"/data/common/navigation/global?as=json";this.imageDomain="http://sports.cbsimg.net";this.fantasyNewsDomain="http://fantasynews.cbssports.com";this.contentWidth=985;this.panelsContainerId=(typeof(args.panelsContainerId)!="undefined")?args.panelsContainerId:"globalNavPanels";this.navContainerId=(typeof(args.navContainerId)!="undefined")?args.navContainerId:"globalNavContainer";this.fastFactsContainerId=(typeof(args.fastFactsPanelsId)!="undefined")?args.navContainerId:"fastFactsPanels";this.navAnchorHoverClass="navHover";this.panelClass="panel";this.panelNewsClass="arenaNews";this.panelArenaClass="arena";this.newsClass="news";this.deferImageClass="gnDeferImage";this.navAnchorElPrefix="nav_";this.categoryElPrefix="gn_";this.panelElPrefix="dd_";this.newsElPrefix="news_";this.headlinesElPrefix="headlines_";this.coverElPrefix="cover_";this.isOver=false;this.panels=[];this.panelsLength=0;this.globalNavPanels=[];this.fastFactPanels=[];this.panelCoords=[100,158];this.xCoordOffset=(typeof(args.xCoordOffset)!="undefined")?args.xCoordOffset:-6;this.yCoordOffset=(typeof(args.yCoordOffset)!="undefined")?args.yCoordOffset:22;this.arenaPanelWidth=(typeof(args.maxArenaPanelWidth)!="undefined")?args.maxArenaPanelWidth:110;this.currCategoryEl;this.currPanelEl;this.isMouseOver=false;this.showPanelId=null;this.hideTimerId=null;this.showPanelTimeout=2000;this.hidePanelTimeout=300;this.delayImageLoad=(typeof(args.delayImageLoad)!="undefined")?args.delayImageLoad:true;this.headlinesLimit=(typeof(args.headlinesLimit)!="undefined")?args.headlinesLimit:7;this.navData={};this.categories=[];this.config={}};CBSi.app.GlobalNavigation.prototype={init:function(json){if(typeof(this.yuiLog)!="undefined"&&this.yuiLog==1){this.LogReader=new YAHOO.widget.LogReader(this.loggerId,{verboseOutput:false})}this.navData=json||{};this.debug("init navData",this.navData,1);this.config=this.navData.config;var navContainerEl=Dom.get(this.navContainerId);var listeners=Event.getListeners(navContainerEl);if(typeof(navContainerEl)!="undefined"&&!Event.getListeners(navContainerEl)){Event.addListener(navContainerEl,"mouseover",this.navEventHandler,null,this);Event.addListener(navContainerEl,"mouseout",this.navEventHandler,null,this);listeners=Event.getListeners(navContainerEl)}navContainerEl=null;this.getArenas();this.buildContent()},requestNavData:function(){this.debug("requestNavData",this.navDataUrl,0);var requestUrl=this.navDataUrl;var callback={success:function(o){var data=eval("("+o.responseText+")");this.init(data)},failure:function(o){},scope:this};var request=Connect.asyncRequest("GET",requestUrl,callback,null);return false},navEventHandler:function(e){this.debug("navClickHandler e",e,0);var elTarget=Event.getTarget(e);var nodeName,elNameArr,elName;nodeName=elTarget.nodeName.toLowerCase();elNameArr=elTarget.id.split("_");elName=elNameArr[1];var eventType=e.type;if(elTarget.nodeName.toLowerCase()==="a"){if(eventType=="mouseover"){this.showPanel(elName);this.setNavDisplay("active")}if(eventType=="mouseout"){this.hide()}}Event.stopEvent(e);elTarget=null;return},getMaxRightCoord:function(){var viewportWidth=Dom.getViewportWidth();var maxRightCoord=(this.contentWidth-10)+(viewportWidth-this.contentWidth)/2;return maxRightCoord},showPanel:function(category){this.debug("showPanel",category,0);this.hideAllPanels();this.isOver=true;clearTimeout(this.hideTimerId);var category=category;var anchorId=this.categoryElPrefix+category;var anchorEl=Dom.get(anchorId);var panelCoords=this.panelCoords;try{panelCoords=Dom.getXY(anchorId)}catch(e){this.debug("showPanel panelCoords ERROR",e,1)}var anchorContainerId=this.navAnchorElPrefix+category;var anchorContainerEl=Dom.get(anchorContainerId);this.currCategoryEl=anchorContainerEl;var panelId=this.panelElPrefix+category;var panelEl=Dom.get(panelId);this.currPanelEl=panelEl;if(typeof(panelEl)!="undefined"){var xCoord=panelCoords[0]+(+this.xCoordOffset);var yCoord=panelCoords[1]+(+this.yCoordOffset);var newCoords=[xCoord,yCoord];var maxRightCoord=this.getMaxRightCoord();var panelWidth=Dom.getStyle(panelEl,"width");var panelElWidth=parseInt(Dom.getStyle(panelEl,"width"),10);if((panelCoords[0]+panelElWidth)>maxRightCoord){var newXCoord=maxRightCoord-panelElWidth;newCoords=[newXCoord,yCoord]}Dom.setXY(panelEl,newCoords);Dom.setStyle(this.currPanelEl,"visibility","visible")}anchorEl=anchorContainerEl=panelEl=newCoords=maxRightCoord=null;return},hideAllPanels:function(){this.debug("hideAllPanels",this.panels,0);if(!this.panels.length||this.panels.length<1){this.globalNavPanels=Dom.getElementsByClassName(this.panelClass,"div",this.panelsContainerId);this.fastFactPanels=Dom.getElementsByClassName(this.panelClass,"div",this.fastFactsContainerId);this.panels=this.globalNavPanels.concat(this.fastFactPanels)}if(!this.isOver&&this.panels.length>0){this.setNavDisplay("inactive");for(i=0;i<this.panels.length;i++){Dom.setStyle(this.panels[i],"visibility","hidden")}}},hide:function(){this.debug("hide this.isOver",this.isOver,0);var thisObj=this;clearTimeout(this.hideTimerId);this.isOver=false;this.hideTimerId=setTimeout(function(){thisObj.hideAllPanels()},this.hidePanelTimeout)},show:function(){this.debug("show this.isOver",this.isOver,0);clearTimeout(this.hideTimerId);this.isOver=false},setNavDisplay:function(state){this.debug("setNavDisplay",this.currCategoryEl,0);if(typeof(this.currCategoryEl)!="undefined"){if(state=="active"){Dom.addClass(this.currCategoryEl,this.navAnchorHoverClass)}if(state=="inactive"){Dom.removeClass(this.currCategoryEl,this.navAnchorHoverClass)}}navAnchorEl=null;return},getArenas:function(){var categories=new Array();for(var key in this.navData){categories.push(key)}this.categories=categories;categories=null},buildContent:function(){this.debug("buildContent categories",this.config,0);var categoryLength=this.categories.length;for(k=0;k<categoryLength;k++){var category=this.categories[k];if(typeof(this.config[category])=="undefined"||this.config[category].active==0){continue}var domElName,newsId,newsEl;try{domElName=this.config[category].domEl;newsId=this.newsElPrefix+domElName;newsEl=Dom.get(newsId);if(!newsEl){continue}}catch(e){continue}if(this.config[category].active==1){var coverInd=this.config[category].cover;var headlinesInd=this.config[category].headlines;if(coverInd==false&&headlinesInd==false){continue}var hideCover=false;var hideHeadlines=false;if(coverInd==true&&this.navData[category].minicover){var cover;if(this.navData[category].minicover&&this.navData[category].minicover.body){cover=this.navData[category].minicover;this.buildCover(category,cover,domElName)}else{hideCover=true}cover=null}else{hideCover=true}if(headlinesInd==true&&this.navData[category].headlines){var headlines=new Array();headlines=this.navData[category].headlines;if(typeof(headlines)!="undefined"&&headlines.length>0){this.buildHeadlines(category,headlines,domElName)}else{hideHeadlines=true}headlines=null}else{hideHeadlines=true}}if(hideCover==true&&hideHeadlines==true){this.hideContentEl(category)}newsEl=null}},hideContentEl:function(category){this.debug("hideContentEl",category,0);var domElName,panelId,panelEl,newsId,newsEl;try{domElName=this.config[category].domEl;panelId=this.panelElPrefix+domElName;panelEl=Dom.get(panelId);newsId=this.newsElPrefix+domElName;newsEl=Dom.get(newsId);if(typeof(panelEl)!="undefined"&&Dom.hasClass(panelEl,this.panelNewsClass)){Dom.replaceClass(panelEl,this.panelNewsClass,this.panelArenaClass)}if(typeof(newsEl)!="undefined"){Dom.setStyle(newsEl,"visibility","hidden")}}catch(e){}panelEl=newsEl=null;return},buildHeadlines:function(category,headlines,domElName){this.debug("buildHeadlines headlines",headlines,0);var headlinesLength=headlines.length;if(headlinesLength!=0){try{headlinesId=this.headlinesElPrefix+domElName;var headlinesEl=Dom.get(headlinesId);if(headlinesEl&&typeof(headlinesEl)!="undefined"){var headlinesHTML="";headlinesHTML+="<h5>Top Stories</h5>";headlinesHTML+='<ul class="multiLine flush">';for(j=0;j<headlinesLength;j++){var linkString=new String(headlines[j].href);if((linkString.indexOf("http:")==-1)&&(linkString.indexOf("javascript")==-1)){linkString=this.mediaDomain+headlines[j].href}var headlinesContent=headlines[j].content;headlinesContent=headlinesContent.replace(/&lt;/gi,"<");headlinesContent=headlinesContent.replace(/&gt;/gi,">");if(j<this.headlinesLimit){headlinesHTML+='<li><a href="'+linkString+'">'+headlinesContent+"</a></li>"}}headlinesHTML+="</ul>";headlinesEl.innerHTML=headlinesHTML}headlinesEl=null}catch(e){}}headlinesLength=null;return},buildCover:function(category,cover,domElName){this.debug("buildCover category",category,1);try{var coverId=this.coverElPrefix+domElName;var coverEl=Dom.get(coverId);if(typeof(coverEl)!="undefined"){var coverLink="";var mediaDomain=this.mediaDomain;var coverAnchorStart="";var coverAnchorEnd="";if(cover.href&&typeof(cover.href)!="undefined"){if((cover.href.indexOf("http:")==-1)&&(cover.href.indexOf("javascript")==-1)){if(category=="fantasy news"){mediaDomain=this.fantasyNewsDomain}coverLink=mediaDomain+cover.href}else{coverLink=cover.href}}else{if(!cover.href&&category=="fantasy news"){coverLink=this.fantasyNewsDomain}}var coverHTML="";if(cover.photo&&cover.photo.href&&cover.photo.width&&cover.photo.height){var imgId=this.categoryElPrefix+"coverImg_"+domElName;var coverPhoto=cover.photo.href;coverPhoto=coverPhoto.replace("$IMAGE_SERVER",this.imageDomain);var srcAttribute=(this.delayImageLoad==true)?"deferredSrc":"src";coverHTML+='<div class="textCenter"><a href="'+coverLink+'">';coverHTML+='<img id="'+imgId+'" '+srcAttribute+'="'+coverPhoto+'" width="'+cover.photo.width+'" height="'+cover.photo.height+'" border="0" alt="'+category+' story thumbnail" title="'+cover.title+'">';coverHTML+="</a></div>"}coverHTML+='<h4><a href="'+coverLink+'">'+cover.title+"</a></h4>";coverHTML+="<p>"+cover.body;coverHTML+="</p>";coverEl.innerHTML=coverHTML;coverEl=null;if(typeof(imageLoader)!="undefined"&&this.delayImageLoad==true){var coverImageGroup=new imageLoader.group(this.navAnchorElPrefix+domElName,"mouseover");if(category==="fantasy news"){var fantasyPanelId=this.panelElPrefix+domElName;var productImgs=Dom.getElementsByClassName(this.deferImageClass,"img",fantasyPanelId);var productImgsLength=productImgs.length;for(i=0;i<productImgsLength;i++){var productImgId=productImgs[i].id;coverImageGroup.registerSrcImage(productImgId,Dom.get(productImgId).getAttribute("deferredSrc"))}coverImageGroup.registerSrcImage(imgId,Dom.get(imgId).getAttribute("deferredSrc"));productImgs=productImgsLength=null}else{coverImageGroup.registerSrcImage(imgId,Dom.get(imgId).getAttribute("deferredSrc"))}coverImageGroup=null}}}catch(e){}return},debug:function(str,value,showInd){var value=value||"";var showInd=showInd||"";if(!showInd||this.jsDebug!=1){return}var valueStr="";if(typeof(str)!="undefined"){if(typeof(value)!="undefined"&&value!=""){str=str+" = "}if(window.console&&window.console.firebug){console.log(str,value)}else{if(this.yuiLog&&this.yuiLog==1){Log(str+value)}}}loggerEl=null;return}}}());