var NewSiteApplication=function(){return function(){this.initialize.apply(this,arguments)}}();NewSiteApplication.prototype={initialize:function(){this.comps=[];this.obs={};this.addedElements={};this._readyEventFired=false;this._componentLoadComplete=false;this._videoPlayerComponentReady=false;this._playerContainerName=null;this._responseJSON=null;this.componentJSON=null;this.configJSON=null;this.queryString=null;this.onLoadCallbacks=[];this._partnerGuid=null;this._defaultClipId=null;this._prefix="NS_";this._flashEmbedPrefix="NS_FLASH_";this._PIDLength=32;this._scriptTagId="NS_GUID_JS";this._guidURLParam="guid";this._jsonServiceTimeoutID=null;this._jsonServiceTimeoutLength=10000;this._guidJSurl="http://config.cnbcvideo.cnbc.com/js/";this._urlJSON="http://player.cnbcvideo.cnbc.com/player/vs?callback=NewSite.loadComponents";this.DEBUG=false;this.LOGGER=null;this.VERSION="$Id$";if(!window.opera&&document.all){this.unloadSet=false;if(!this.unloadSet){window.attachEvent("onbeforeunload",this._prepUnload);this.unloadSet=true}}},_prepUnload:function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};var A=function(){var C=document.getElementsByTagName("OBJECT");for(var D=C.length-1;D>=0;D--){C[D].style.display="none";for(var B in C[D]){if(typeof C[D][B]=="function"){C[D][B]=function(){}}}}};window.attachEvent("onunload",A)},getComponentServiceUrl:function(){var B=this._urlJSON;var A=this.getUrlSeparator(B);try{if(B.toLowerCase().indexOf(this._guidURLParam)==-1){B+=A+this._guidURLParam+"="+this.getPartnerGuid()}}catch(C){this.reportError(C)}return B},run:function(){var A=this;this._jsonServiceTimeoutID=window.setTimeout(function(){A.fireJSONError(A)},A._jsonServiceTimeoutLength);this.loadExternalJS(this.getComponentServiceUrl())},ping:function(){return true},fireJSONError:function(A){var B={code:"NS_JS_001",type:"JSON",displayMessage:"Page components failed to load.",description:"Page component JSON service timed out."};A.updateObservers("newsiteError",B)},loadExternalJS:function(D){try{if(!D){throw ("url parameter is required")}var B=Math.random()+"";B.replace(/\./g,"");var G=this.getUrlSeparator(D);var C=document.createElement("script");C.setAttribute("type","text/javascript");C.setAttribute("src",D);C.setAttribute("id",B);var E=document.getElementsByTagName("head");if(!E){throw ("No head tag found.")}var A=E.item(0);A.appendChild(C);return B}catch(F){this.reportError(F,"NewSite.loadExternalJS")}},registerReady:function(A){this.traceMsg("registerReady: "+A);if(this.addedElements[A]){this.addedElements[A].isReady=true}if(A=="videoPlayerComponent"){this.traceMsg("incoming: "+A);this._videoPlayerComponentReady=true;for(var C in this.addedElements){var B=this.addedElements[C];if(B&&B.isReady&&!B.isTracked){this.videoPlayerComponent.trackComponent([B.trackingInfo]);B.isTracked=true}}}this.fireReady(A)},getComponents:function(){return this.componentJSON},isComponentReady:function(A){var B=this.addedElements[A];if(!B||B.isReady===true){this.traceMsg("isComponentReady: "+A+" true");return true}this.traceMsg("isComponentReady: "+A+" false");return false},loadComponents:function(H){clearTimeout(this._jsonServiceTimeoutID);var F=this;try{if(H.error){window.setTimeout(function(){F.fireJSONError(F);F.reportError("Service error: "+H.error.errorMessage)},500)}this._responseJSON=H;var D=this.componentJSON=this._responseJSON.components;var C=this.configJSON=this._responseJSON.config;for(var A in D){var G=D[A];var B=this.initializeComponent(A,G);if(this.EL(A)){B=this.addComponentToDom(B)}this.extendComponent(B);this.comps.push(A)}this.traceMsg("ComponentLoadComplete");this._componentLoadComplete=true;this.fireReady()}catch(E){this.reportError(E,"loadComponents")}},initializeComponent:function(A,B){return this[A]={instance:null,compName:A,parent:this,options:B}},addComponentToDom:function(C){var A=C.compName;this.traceMsg("addComponentToDom: "+A);var B=C.options;if(this.EL(A)){var D=this._flashEmbedPrefix+A;if(!this.EL(D)){this.addedElements[A]={};this.addedElements[A].isReady=false;this.addedElements[A].isTracked=false;this.EL(A).innerHTML=this.getFlashTag(D,B);this.addedElements[A].trackingInfo=this.getTrackingInfo(A,B);C.instance=this.registerFlashObject(D)}}return C},extendComponent:function(B){var A=B.compName;this.extend(B,this["commonComponentMethods"]);if(this[A+"Methods"]){this.extend(B,this[A+"Methods"])}},registerFlashObject:function(B){var A=null;if(navigator.appName.indexOf("Microsoft")!=-1){A=window[B]}else{A=document[B]}return A?A:false},addListener:function(F,E,C){this.traceMsg("addListener: "+F+"\n<br>callbackObj "+E+"\n<br>callbackFunc "+C);E=this._stringToObject(E);if(!C){C=F}if(!this.obs[F]){this.obs[F]=[]}var H=this.obs[F];var B=H.length;for(var D=0;D<B;D++){try{if(H[D].obj&&H[D].obj==E&&H[D].func==C){throw"Addition of duplicate listener ignored."}}catch(G){this.reportError(G)}}var A;if(E&&E.id){A=E.id}else{A=E}this.traceMsg("addListener: "+F+"\n<br>callbackObj "+A+"\n<br>callbackFunc "+C);this.obs[F].push({obj:E,func:C});return F},addFlashListener:function(C,B,A){B=this.registerFlashObject(B);this.addListener(C,B,A)},removeListener:function(E,D,B){D=this._stringToObject(D);if(!B){B=E}this.traceMsg("removeListener:\ncallbackObj "+D+"\ncallbackFunc "+B);if(!this.obs[E]){return false}var G=this.obs[E];var A=G.length;for(var C=0;C<A;C++){try{if(G[C].obj&&G[C].obj==D&&G[C].func==B){return G.splice(C,1)}}catch(F){this.reportError(F)}}return false},updateObservers:function(C,E){this.traceMsg("updateObservers : eventType "+C+" "+E);var H=this.obs[C];if(!H){return }var A=H.length;for(var B=0;B<A;B++){try{var G=this._stringToObject(H[B].obj);var D=H[B].func;if(G&&D){if(typeof G!="object"){throw"Object missing: "+G}if(D==undefined||D==null){D=C}if(typeof G[D]=="function"){G[D](E)}else{G.toComponent(D,E)}}}catch(F){this.reportError(F,"updateObservers("+C+")")}}},_stringToObject:function(D){var C;if(typeof D=="string"){var A=D.split(".");var B=0;while(A.length>0){var E=A.shift();if(!B++){C=window[E]}else{C=C[E]}}if(C){return C}}return D},setPlayerContainer:function(A){this.traceMsg("setPlayerContainer : "+A);if(this.EL(A)){this._playerContainerName=A;return A}return null},getPlayerContainerName:function(){return this._playerContainerName},setDefaultClipId:function(A){this._defaultClipId=A},getDefaultClipId:function(){return this._defaultClipId},_parseVideoId:function(B){try{B=B+"";B=B.replace(/.*pid=([^&]+).*/i,"$1");if(B.length!=this._PIDLength){throw"Invalid Video PID: "+B}}catch(A){this.reportError(A,"")}return B},getNPMLObject:function(){return this._responseJSON},EL:function(A){if(typeof A=="string"){A=document.getElementById(A)}return A},extend:function(B,C){for(var A in C){B[A]=C[A]}return B},readyEventFired:function(){return this._readyEventFired},fireReady:function(A){this.traceMsg("fireReady: "+A);if(!this.readyEventFired()){if(this._componentLoadComplete&&this.allComponentsReady()){this.traceMsg("componentLoadComplete: "+A);this.updateObservers("newsiteReady",{});this._readyEventFired=true;this.onComponentsLoaded()}}},allComponentsReady:function(){this.traceMsg("allComponentsReady?");for(var A in this.addedElements){if(this.isComponentReady(A)!=true){this.traceMsg(A+" is Not ready");return false}}this.traceMsg("allComponentsReady!! "+this._videoPlayerComponentReady);return this._videoPlayerComponentReady},onComponentsLoaded:function(){while(this.onLoadCallbacks.length>0){var B=this.onLoadCallbacks.pop();try{if(B){B()}}catch(A){this.reportError(A)}}},onLoad:function(A){this.onLoadCallbacks.push(A)},getQueryString:function(){if(!this.queryString){this.queryString=this._parseQueryString()}return this.queryString},_parseQueryString:function(B){var E={};var A=B?B:window.location.search;if(A.charAt(0)=="?"){A=A.slice(1,A.length)}if(A.length<1){return E}A=A.replace(/\&amp\;/gi,"&");A=A.split("&");for(var C=0;C<A.length;C++){var D=A[C].split("=");E[D[0]]=D[1]}return E},getPartnerGuid:function(){if(!this._partnerGuid){try{var C=this.EL(this._scriptTagId).src;var A=this._parseQueryString(C.split("?")[1]);this._partnerGuid=A.guid}catch(B){this.reportError(B)}}return this._partnerGuid},getUrlSeparator:function(A){return A.indexOf("?")==-1?"?":"&"},getEnvironment:function(){var A=this.getQueryString();var F=document.referrer;var B=document.URL;var D=navigator.userAgent;var E={queryString:A,referrer:F,url:B,userAgent:D};var H=["availHeight","availWidth","colorDepth","height","width"];for(var C=0;C<H.length;C++){var G=H[C];E[G]=screen[G]}return E},getTrackingInfo:function(A,B){try{var D={};D.componentName=A;D.url=document.URL;D.pixelArea=B.width*B.height;D.version=1}catch(C){this.reportError(C)}return D},loadGuidJS:function(){this.loadExternalJS(this._guidJSurl+this._parseQueryString(this.EL(this._scriptTagId).src.split("?")[1]).guid+".js")},getFlashTag:function(E,B){var D=this.getFlashBuilder();D.setId(E);D.setAttributes(B);var C=(navigator.appName.indexOf("Microsoft")!=-1);var A=C?D.getObjectTag():D.getEmbedTag();D.cleanup();delete D;return A},getFlashBuilder:function(){var A={errorHandler:null,id:"",attributes:[],allowedAttributes:{width:{req:true,def:null},height:{req:true,def:null},url:{req:true,def:null},wmode:{req:false,def:"transparent"},bgcolor:{req:false,def:"#FFFFFF"},allowScriptAccess:{req:false,def:"always"},menu:{req:false,def:"false"}},setId:function(B){this.id=B},getId:function(){return this.id},setErrorHandler:function(B){this.errorHandler=B},setAttributes:function(B){for(var C in B){this.setAttribute(C,B[C])}},setAttribute:function(B,C){this.attributes[B]=C},getAttribute:function(B){return this.attributes[B]||this.getDefaultValue(B)||false},getAllowedAttributes:function(){return this.allowedAttributes},isRequired:function(C){var B=this.allowedAttributes[C];return B&&B.req?true:false},getDefaultValue:function(C){var B=this.allowedAttributes[C];return B&&B.def||null},getEmbedTag:function(){try{var G=this.getId();var B='<embed quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ';B+='name="'+G+'" id="'+G+'" ';var F=this.getAllowedAttributes();for(var C in F){var D=this.getAttribute(C);if(this.isRequired(C)&&!this.getAttribute(C)){throw"Missing required attribute for "+G+": "+C}if(C.toLowerCase()=="url"){C="src"}B+=C+'="'+D+'" '}B+="></embed>"}catch(E){this.handleError(E);return""}return B},getObjectTag:function(){try{var F=this.getAllowedAttributes();var B='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';B+='name="'+this.getId()+'" id="'+this.getId()+'" ';B+='width="'+this.getAttribute("width")+'" height="'+this.getAttribute("height")+'"><param name="quality" value="high" />';for(var C in F){var D=this.getAttribute(C);if(this.isRequired(C)&&!this.getAttribute(C)){throw"Missing required attribute: "+C}if(C.toLowerCase()!="width"&&C.toLowerCase()!="height"){if(C.toLowerCase()=="url"){C="movie"}B+='<param name="'+C+'" value="'+D+'" />'}}B+="</object>"}catch(E){this.handleError(E);return""}return B},handleError:function(B){if(this.errorHandler!=null){this.errorHandler(B)}},cleanup:function(){this.errorHandler=null;for(var B in this){this[B]=null}}};A.setErrorHandler(this.reportError);return A},hideAllComponents:function(){try{var A=this.comps.length;for(var B=0;B<A;B++){this[this.comps[B]].hide()}}catch(C){}},showAllComponents:function(){try{var A=this.comps.length;for(var B=0;B<A;B++){this[this.comps[B]].show()}}catch(C){}},pingImgUrl:function(C){try{var A=Math.random()+"";A.replace(/\./g,"");var B=document.createElement("IMG");B.width=1;B.height=1;B.src=C;B.id=A;B.onload=B.onerror=function(){var E=this.parentNode.removeChild(this);delete E};document.body.appendChild(B)}catch(D){}},reportError:function(C,F){try{var A=NewSite,E;if(!A.DEBUG||!A.LOGGER){return false}if(navigator.appName.indexOf("Microsoft")!=-1){E=C.message+"\n"+C.name+"\n"+C.number+"\n"+C.description+"\n"}else{E=C}if(F){E=F+"\n\n"+E}var D=new Date().getMilliseconds();var B=document.createElement("P");B.style.backgroundColor="red";B.style.color="white";B.innerHTML=D+": Error caught: \n\n"+E;A.LOGGER.insertBefore(B,A.LOGGER.firstChild)}catch(C){}},traceMsg:function(E,D){try{if(!this.DEBUG||!this.LOGGER){return false}if(D){E=D+"\n\n"+E}var C=new Date().getMilliseconds();var B=document.createElement("P");B.innerHTML=C+": Trace: \n\n"+E;this.LOGGER.insertBefore(B,this.LOGGER.firstChild)}catch(A){}},getTimer:function(){}};NewSiteApplication.prototype.commonComponentMethods={show:function(){var A=this.getInstance();try{A.width=this.options.width;A.height=this.options.height}catch(B){}this.toComponent("show")},hide:function(){var A=this.getInstance();try{A.width=1;A.height=1}catch(B){}this.toComponent("hide")},getFlashMethod:function(A){if(!this.parent){return A}return this.parent._prefix+this.compName+"_"+A},info:{},getInfo:function(){return this.info},setInfo:function(A){this.info=A},getInstance:function(){return this.instance},toComponent:function(C,F){try{var B=this.parent;var A=this.getInstance();var D=this.getFlashMethod(C);if(typeof A[D]=="function"){A[D](F);B.traceMsg("toComponent("+D+")")}else{if(typeof A[C]=="function"){A[C](F);B.traceMsg("toComponent("+C+")")}else{if(typeof A.toFlash=="function"){A.toFlash(C,F);B.traceMsg("toComponent.toFlash("+C+")")}else{throw"Function not found"}}}}catch(E){B.reportError(E,"NewSiteApplication.toComponent<br>"+C+"<br>"+D+"<br>"+A)}}};NewSiteApplication.prototype.videoPlayerComponentMethods={properties:{},playVideo:function(B,A){B=this.parent._parseVideoId(B);this.toComponent("playVideo",B)},pauseVideo:function(){this.toComponent("pauseVideo")},stopVideo:function(){this.toComponent("stopVideo")},resumeVideo:function(){this.toComponent("resumeVideo")},next:function(){this.toComponent("nextVideo")},previous:function(){this.toComponent("previousVideo")},seek:function(A){this.toComponent("seekVideo",A)},getProperty:function(A){return this.properties[A]},getProperties:function(){return this.properties},setProperties:function(B){for(var A in B){this.properties[A]=B[A]}},mute:function(){this.toComponent("muteVideo")},setVolume:function(A){this.toComponent("setPlayerVolume",A)},trackComponent:function(A){this.toComponent("trackComponent",A)},submitToUrl:function(A){this.toComponent("submitToUrl",A)},closeConnection:function(){this.toComponent("closeConnection")},getInstance:function(){if(!this.instance){this.instance=this.parent.registerFlashObject(this.parent.getPlayerContainerName())}return this.instance}};NewSiteApplication.prototype.linkComponentMethods={newLink:function(A){this.setInfo(A);this.toComponent("newLink",A)}};NewSiteApplication.prototype.logoComponentMethods={};NewSiteApplication.prototype.adComponentMethods={videoAdBegin:function(A){this.setInfo(A);this.toComponent("videoAdBegin",A)}};NewSiteApplication.prototype.metadataComponentMethods={videoMetadata:function(A){this.setInfo(A);this.toComponent("videoMetadata",A)}};NewSiteApplication.prototype.relatedVideosComponentMethods={relatedVideos:function(A){this.setInfo(A);this.toComponent("relatedVideos",A)}};if(!NewSite){var NewSite=new NewSiteApplication;NewSite.run();NewSite.loadGuidJS()}
