function CBSTimeConverter(C,B,A){var D=this.parseTime(C,B);var E=A*60*60*1000;D.setTime(D.getTime()+E);return D;}CBSTimeConverter.prototype.parseTime=function(D,C){if(D==""){return null;}var G=new Date();var E=D.match(/(\d+)(?::(\d\d))?\s*(p?)/i);var A=parseInt(E[1]);if(A<12&&E[3]!=""){A=A+12;}else{if(E[1]==12&&E[3]==""){A=0;}}var B=new Date();if(A<B.getUTCHours()+C){G.setUTCDate(B.getDate()+1);}G.setUTCHours(A);G.setUTCMinutes(parseInt(E[2],10)||0);G.setUTCSeconds(0,0);var F=Math.abs(C)*60*60*1000;G.setTime(G.getTime()+F);return G;};cbsNewsAffiliatePlayer={feedUrl:"http://www.cbsnews.com/feedfiles/livefeed2.json",options:{interval:60,playerUrl:"http://www.cbsnews.com/video/watch/?id=2n",timezone:-5,timezoneLabel:"",customCss:false},liveNow:false,init:function(){this.setOptions();this.createWidget();this.injectCss();this.fetchFeed();},fetchFeed:function(){this.feed=document.createElement("script");this.feed.type="text/javascript";this.feed.src=this.feedUrl;this.feed.id="CBSNEWS_AFFILIATE_PLAYER";(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(this.feed);},loadResponse:function(A){this.removeElement(this.feed.id);if(A[0].publicize=="true"&&A[0].liveNow!=null){this.headline=A[0].liveNow;this.liveNow=true;}else{if(typeof A[0].feed.feedItem[0]!="undefined"&&A[0].feed.feedItem[0].text!=null){this.headline=A[0].feed.feedItem[0].text;this.liveNow=false;this.time=A[0].feed.feedItem[0].timeString;}}if(this.headline){this.printWidget();}var C=this,B=function(){C.fetchFeed();};setTimeout(B,this.options.interval*1000);},printWidget:function(){if(this.headline==null){this.widget.style.display="none";}else{this.fillWidget();this.widget.style.display="block";}},createWidget:function(){this.divId="cbsnewsAffiliateWidgetLiveNow";var A='<div id="'+this.divId+'"></div>';document.open();document.write(A);document.close();this.widget=this.gebid(this.divId);},formatTime:function(B){var A=B.getUTCHours();var C="AM";if(A>11){C="PM";}if(A>12){A=A-12;}var D=B.getUTCMinutes();if(D<10){D="0"+D;}return A+":"+D+C;},fillWidget:function(){var B,A;if(this.liveNow){B='<h2 class="liveNow">Live Now:</h2>';A=this.headline;}else{B='<h2 class="comingUp">Coming Up:</h2>';var C=this.time;if(this.options.timezone!=-5){C=this.formatTime(new CBSTimeConverter(this.time,-5,this.options.timezone));}A=C+this.options.timezoneLabel+" : "+this.headline;}B+='<div class="headline"><div class="headlineInner"><p><a href="'+this.options.playerUrl+'">'+A+"</a></p></div></div>";B+="</div>";this.widget.innerHTML=B;},injectCss:function(){if(this.options.customCss){return ;}var A=document.createElement("link");A.rel="stylesheet";A.type="text/css";A.href="http://i.i.com.com/cnwk.1d/css/rb/cbsnews/widget.affiliate.css";(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(A);},setOptions:function(){if(typeof CBSNEWS_AFFILIATE_PLAYER_URL!="undefined"){this.options.playerUrl=CBSNEWS_AFFILIATE_PLAYER_URL;}if(typeof CBSNEWS_AFFILIATE_PLAYER_TIMEZONE!="undefined"){this.options.timezone=CBSNEWS_AFFILIATE_PLAYER_TIMEZONE;}if(typeof CBSNEWS_AFFILIATE_PLAYER_TIMEZONE_LABEL!="undefined"){this.options.timezoneLabel=CBSNEWS_AFFILIATE_PLAYER_TIMEZONE_LABEL;}if(typeof CBSNEWS_AFFILIATE_PLAYER_CUSTOMCSS!="undefined"){this.options.customCss=CBSNEWS_AFFILIATE_PLAYER_CUSTOMCSS;}},gebid:function(A){return document.getElementById(A);},removeElement:function(B){var A=this.gebid(B);A.parentNode.removeChild(A);}};cbsNewsAffiliatePlayer.init();
