IBSYS.using("media");Date.prototype.toISO8601String=function(format,offset){if(!format){var format=6;}if(!offset){var offset="Z";var date=this;}else{var d=offset.match(/([-+])([0-9]{2}):([0-9]{2})/);var offsetnum=(Number(d[2])*60)+Number(d[3]);offsetnum*=((d[1]=="-")?-1:1);var date=new Date(Number(Number(this)+(offsetnum*60000)));}var zeropad=function(num){return((num<10)?"0":"")+num;};var str="";str+=date.getUTCFullYear();if(format>1){str+="-"+zeropad(date.getUTCMonth()+1);}if(format>2){str+="-"+zeropad(date.getUTCDate());}if(format>3){str+="T"+zeropad(date.getUTCHours())+":"+zeropad(date.getUTCMinutes());}if(format>5){var secs=Number(date.getUTCSeconds()+"."+((date.getUTCMilliseconds()<100)?"0":"")+zeropad(date.getUTCMilliseconds()));str+=":"+zeropad(secs);}else{if(format>4){str+=":"+zeropad(date.getUTCSeconds());}}if(format>3){str+=offset;}return str;};IBSYS.media.selectContentModule={init:function(el,config){if(!swfobject.hasFlashPlayerVersion("6.0.65")){var legacyForFlash=this.getArchiveURL(config.video_coid);el.innerHTML='<div align="center" valign="middle"><p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#444444; line-height:1.5;">'+"This component requires <strong>Adobe Flash.</strong><br /><br />"+"After you install Flash, you may need to restart your browser.<br />"+"Copy this URL first, so that you can find your way back:<br />"+'<form><input type="text" size="30" maxlength="256" readonly="true" align="middle" value='+document.location.href+" /></form>"+'</p><br /><div id="FlashInstallPromptDiv"><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">'+'<img src="/sh/flex3MediaPlayer/images/getflash.jpg" alt="Get Flash" border="0" /></a></div><br />'+'<p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#444444; line-height:1.5;">';}else{if(!swfobject.hasFlashPlayerVersion("9.0.28")){document.title=document.title.slice(0,47)+" - Flash Player Installation";var legacyForFlash=this.getArchiveURL(config.video_coid);var eiSwf="/sh/flex3MediaPlayer/expressinstall_custom.swf?legacy="+legacyForFlash;var fv={MMredirectURL:window.location.href,MMplayerType:(typeof ActiveXObject=="function"?"ActiveX":"PlugIn"),MMdoctitle:document.title};var atts={id:el.id};swfobject.embedSWF(eiSwf,el.id,"640","405","6.0.65",eiSwf,fv,{},atts);}else{IBSYS.application.Application.addEventListener(this.onIBEvent,this);this.render(el,config);}}},related_coid:"",render:function(el,config){config.bg_clr=config.bg_clr||"#ffffff";var flashVars={showRelated:(typeof config.show_related!="undefined"?config.show_related:false),host:window.location.hostname,skin:config.skin_swf_url,contentService:config.contentEndPoint,swid:config.section_widget_coid,backgroundColor:config.bg_clr};if(config.related_coid){this.related_coid=config.related_coid;}if(config.thin=="true"){flashVars.usage="thin";}if(config.hlgt_clr){flashVars.highlightColor=config.hlgt_clr;}if(config.idx_label){flashVars.indexLabel=config.idx_label;}if(config.vid_link){flashVars.moreVideoLink=config.vid_link;}IBSYS.media.genericFlash2.init(el,{swfUrl:config.swfUrl,background:config.bg_clr,width:config.width||360,height:config.height||175,flashVars:flashVars,wmode:config.wmode});IBSYS.media.flashPlayer=IBSYS.media.flashPlayer||{};IBSYS.media.flashPlayer.onContentSelected=this.onContentSelected;},onIBEvent:function(e){switch(e.getName()){case"movieLoaded":if(e.eventData.name=="contentSelection"){if(this.related_coid){document.getElementById(e.eventData.uniqueId).relatedContentRequest(this.related_coid);}}break;}},prepStream:function(s){if(!s.bitsPerSecond||isNaN(s.bitsPerSecond)){if(!this.reRateFromPath){this.reRateFromPath=/\.(\d+)k\./;}s.bitsPerSecond=this.reRateFromPath.exec(s.href);if(!s.bitsPerSecond){s.bitsPerSecond=this.reRateFromPath.exec(s.streamId);}if(s.bitsPerSecond){s.bitsPerSecond=Number(s.bitsPerSecond[1])*1000;}else{s.bitsPerSecond=0;}}},onContentSelected:function(obj,loadMediaOnly,origin){function constructScheme(o){return(o.scheme+":"+o.schemeSpecificPart);}meta={coidValue:obj.contentId.schemeSpecificPart.split(":",3)[2],contentId:constructScheme(obj.contentId),headline:obj.headline,poolId:constructScheme(obj.poolId),showAds:obj.showAds,teaser:obj.teaser,isLive:obj.isLive,metadata:obj.metadata.source,dateCreated:obj.dateCreated.toISO8601String(5),dateModified:obj.dateModified.toISO8601String(5),content:(function(){arr=obj.contentPointers.source;var contentArray=[];for(var i=0;i<arr.length;i++){contentArray[i]={href:constructScheme(arr[i].href),poolId:constructScheme(arr[i].poolId),role:constructScheme(obj.contentPointers.source[0].role),resolvedContent:{image:{alt:obj.mainImage.teaser,contentId:constructScheme(obj.mainImage.contentId),credit:obj.mainImage.credit,headline:obj.mainImage.headline,poolId:constructScheme(obj.mainImage.poolId),teaser:obj.mainImage.teaser,rendition:(function(){var renditions=obj.mainImage.renditions.source;var ca=[];for(var j=0;j<renditions.length;j++){ca[j]={height:renditions[j].height,href:constructScheme(renditions[j].href),mimetype:renditions[j].mimetype.js,role:constructScheme(renditions[j].role),width:renditions[j].width};}return ca;})()}}};}return contentArray;})(),stream:(function(){var arr=obj.streams.source;var streams=[];for(var i=0;i<arr.length;i++){streams[i]={mimetype:arr[i].mimetype.js,bitsPerSecond:arr[i].bitsPerSecond,href:constructScheme(arr[i].href),streamId:arr[i].streamId};}return streams;})()};meta.origin=origin||(loadMediaOnly?"defaultVideo":"click_through");meta.loadMediaOnly=loadMediaOnly||false;IBSYS.media.selectContentModule.sortStreams(meta);},sortStreams:function(meta,attempt){if(!(this.suppressDefault&&meta.loadMediaOnly)){var availableBPS=IBSYS.application.Application.getProperty("userBitsPerSec");var that=this;if(availableBPS){if(meta.stream){meta.coidValue=meta.contentId.substring("urn:ibsys:content:".length);for(var i=0;i<meta.metadata.length;i++){switch(meta.metadata[i].type){case"urn:ibsys:taxonomy:topic":meta.topic=meta.metadata[i].tag.replace(/\//g,"");break;case"urn:ibsys:taxonomy:pool":meta.pool=meta.metadata[i].tag;break;case"urn:ibsys:taxonomy:videoCategory":meta.category=meta.metadata[i].tag;break;}}meta.category=meta.category||meta.topic;meta.stream.sort(function(a,b){if((a.mimetype=="video/x-flv")^(b.mimetype=="video/x-flv")){return(a.mimetype=="video/x-flv"?-1:1);}else{that.prepStream(a);that.prepStream(b);a.rateDiff=a.rateDiff||(availableBPS-a.bitsPerSecond);b.rateDiff=b.rateDiff||(availableBPS-b.bitsPerSecond);if((a.rateDiff<0)^(b.rateDiff<0)){return b.rateDiff-a.rateDiff;}else{return Math.abs(a.rateDiff)-Math.abs(b.rateDiff);}}});this.currentVideo=meta;IBSYS.media.genericFlash2.announceEventProxy("newMediaContent",meta);}else{alert("The stream for this video is currently unavailable.");}}else{attempt=attempt||1;if(attempt<120){setTimeout(function(){attempt++;that.sortStreams(meta,attempt);},500);}else{IBSYS.application.Application.setProperty("userBitsPerSec",56000);that.sortStreams(meta,attempt++);}}}else{delete this.suppressDefault;}},setSuppressDefault:function(value){this.suppressDefault=value;}};
