// (c)2009 Alan Lawson

PDQ.videoPopup=function(o){this.id=o.id;this.title=null;this.blockId=null;this.window=null;this.servers=[''];this.speeds=null;this.sizes=null;this.widths=null;this.server=false;this.bandWidth=null;this.spIndex=false;this.width=null;this.heights=null;this.height=null;this.xWidth=0;this.xHeight=0;this.openTask=null;this.fileRoot=null;this.file=o.file||null;}
PDQ.videoPopup.prototype.init=function(o){if(typeof o=='undefined'){return;}
var s='margin:4px;';var img='<img src="'+Page.portalDir+'/ajax-loader.gif?OpenImageResource"';img+=' id="InProcess" name="InProcess" border="0" alt="" style="'+s+'">';var s='';var nHtml='<DIV id='+this.id+'-video name='+this.id+'-video'+' width="100%" style="'+s+'">'+img+'</DIV>';o.html=nHtml;if(typeof o.renderTo=='undefined')o.renderTo=document.body;if(typeof o.title=='undefined')o.title='Loading...';if(o.blockId){this.blockId=o.blockId;}else{this.blockId=null;}
if(o.servers)this.servers=o.servers;if(o.speeds)this.speeds=o.speeds;if(o.sizes)this.sizes=o.sizes;if(o.widths)this.widths=o.widths;if(o.heights)this.heights=o.heights;if(o.servers.length==1){var spIndex=0;this.spIndex=0;this.server=this.servers[0];}else{var bwo=PDQ.bandWidth(this);if(bwo){var spIndex=bwo.spIndex;this.server=bwo.server;this.bandWidth=bwo.bandWidth;}else{var spIndex=0;}
if(!bwo){this.openTask=new Ext.util.DelayedTask(this.init,this);this.openTask.delay(200);return;}
this.spIndex=spIndex;}
if(o.file){if(!o.file.match(/(\.flv)|(.swf)/i)){this.fileRoot=o.file;o.file=this.fileRoot+' '+this.speeds[this.spIndex]+'kps.flv';}else{}
this.file=o.file;}
this.width=this.widths[spIndex];var w=this.width+this.xWidth;this.height=this.heights[spIndex]
var h=this.height+this.xHeight+28;o.width=w;o.height=h;o.shadowOffset=(typeof o.shadowOffset=='undefined')?14:o.shadowOffset;o.border=(typeof o.border=='undefined')?false:o.border;if(typeof o.resizable=='undefined')o.resizable=false;if(Ext.isGecko)o.animCollapse=false;PDQ.log('Opening video window '+o.id);this.window=new Ext.Window(o);this.window.show(this);this.window.center();this.window.addListener('move',this.move,this,true);this.window.addListener('beforeclose',this.beforeclose,this,true);this.window.addListener('hide',this.close,this,true);var delayTask=new Ext.util.DelayedTask();delayTask.delay(10,this.openLoad,this,[o]);}
PDQ.videoPopup.prototype.openLoad=function(o){if(Ext.isSecure){var video='https://';}else{var video='http://';}
if(this.server==''){video+=PDQ.host;}else{video+=this.server;}
video+=this.file
var src=PDQ.pathNSF+'/FlowPlayerLight.swf?OpenFileResource';var params={src:src,height:this.height};var config={autoPlay:true,videoFile:video,initialScale:'scale',useHwScaling:true,menuItems:[true,true,true,true,true,false],emailPostUrl:false};var nd=Ext.DomQuery.selectNode('div:first',this.window.body.dom);flashembed(nd,params,{config:config});}
PDQ.videoPopup.prototype.beforeclose=function(o){var p=this.window.getPosition();return true;}
PDQ.videoPopup.prototype.close=function(o){this.window.close();}
PDQ.videoPopup.prototype.move=function(){if(this.moved===null){this.moved=false;}else{this.moved=true;}}