IBSYS.using("media");IBSYS.media.relatedVid={init:function(el,config){var url=config.jsonEndPoint+"?contentId=urn:ibsys:content:"+config.video_coid+"&linkLevelsToResolve=1";YAHOO.util.Connect.asyncRequest("GET",url,{success:this.onContentService,scope:this});config.width=config.width||"240";if(!isNaN(config.height)){config.height=String(parseInt(config.height,10));}else{config.height="225";}IBSYS.media.vidPlayModule.init(el,config);},onContentService:function(r){this.currentVideo=YAHOO.lang.JSON.parse(r.responseText);this.currentVideo.coidValue=this.currentVideo.contentId.substring("urn:ibsys:content:".length);this.currentVideo.loadMediaOnly=true;this.sortStreams(this.currentVideo);},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;}}},sortStreams:function(meta,attempt){var self=this;var availableBPS=IBSYS.application.Application.getProperty("userBitsPerSec");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{self.prepStream(a);self.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);}}});IBSYS.media.genericFlash2.announceEventProxy("newMediaContent",meta);}else{attempt=attempt||1;attempt++;if(attempt<15){setTimeout(function(){self.sortStreams(meta,attempt);},500);}else{IBSYS.application.Application.setProperty("userBitsPerSec",56000);self.sortStreams(meta,attempt);}}}};