var VideoBBCode=Class.create({initialize:function(){var videos=$$('.videoBBCodeInnerContainer');this.activeVideo=0;this.activeVideoData=new Array();if(videos.size()){this.langVars=Object.extend({zoomIn:'',copyright:'',defaultTitle:''},arguments[0]||{});if(!IS_IE){this.background=new Element('div').addClassName('videoBBCodeBackground');if(IS_SAFARI_MOBILE){this.background.setStyle('height: '+$$('body')[0].getHeight()+'px; width: '+$$('body')[0].getWidth()+'px;');}
this.background.hide();$$('body')[0].insert(this.background);this.caption=new Element('p').addClassName('videoBBCodeCaption').hide();this.background.insert(this.caption);this.copyright=new Element('div').addClassName('videoBBCodeCopyright').update(this.langVars.copyright);this.copyright.hide();$$('body')[0].insert(this.copyright);var videoID=0;videos.each(function(videoContainer){videoID++;element=videoContainer.select('.videoBBCodeZoom')[0];element.id='videoBBCodeZoom-'+videoID;element.alt='zoom';element.title=this.langVars.zoomIn;element.style.cursor='pointer';element.observe('click',this.zoomIn.bindAsEventListener(this));element.onmouseover=function(){this.src=this.src.replace(/videoM\.png/,'videoZoomM.png');}
element.onmouseout=function(){this.src=this.src.replace(/videoZoomM\.png/,'videoM.png');}
element=videoContainer.select('.containerContent h4 a')[0];element.id='videoBBCodeTitle-'+videoID;element=videoContainer.select('.videoBBCodeObjectContainer')[0];element.id='videoBBCodeObjectContainer-'+videoID;element=videoContainer.select('.videoBBCodeObject')[0];element.id='videoBBCodeObject-'+videoID;}.bind(this));this._resize=this.resize.bindAsEventListener(this);}
Event.observe(window,'beforeunload',this.suicide.bindAsEventListener(this));}},zoomIn:function(evt){if(this.activeVideo==0){var videoID=evt.findElement().id.split('-')[1];this.activeVideo=videoID;var titleElement=$('videoBBCodeTitle-'+this.activeVideo);var title=titleElement.innerHTML;if(titleElement.select('.highlight')[0]){title=titleElement.select('.highlight')[0].innerHTML;}
this.caption.update(title);this.background.onclick=function(){this.zoomOut();}.bind(this);$('videoBBCodeObject-'+this.activeVideo).hide();var video=$('videoBBCodeObject-'+this.activeVideo);this.activeVideoData['data']=video.readAttribute('data');this.activeVideoData['movieParam']=video.select('param[name="movie"]')[0].readAttribute('value');this.activeVideoData['flashVars']='';if(video.select('param[name="flashVars"]')[0]){this.activeVideoData['flashVars']=video.select('param[name="flashVars"]')[0].readAttribute('value');video.select('param[name="flashVars"]')[0].remove();}
this.activeVideoData['width']=video.readAttribute('width');this.activeVideoData['height']=video.readAttribute('height');var data=video.select('param[name="dataCache"]')[0].readAttribute('value');var movie=video.select('param[name="movieCache"]')[0].readAttribute('value');var flashVars=(this.activeVideoData['flashVars']!=''&&this.activeVideoData['flashVars']!='autoPlay=false'?this.activeVideoData['flashVars']+'&amp':'')+(movie.indexOf('http://www.metacafe.com')>-1?'playerVars=autoPlay=yes':'autorun=yes&amp;isAutoPlay=true&amp;autoPlay=true&amp;autorun=yes&amp;autostart=true');video.writeAttribute('data',data);video.select('param[name="movie"]')[0].writeAttribute('value',movie);var flashVarsParam=new Element('param').writeAttribute('name','flashVars').writeAttribute('value',flashVars);video.insert(flashVarsParam);this.background.appear({duration:1,to:0.9,afterFinish:function(){this.copyright.appear({duration:0.5});if(this.caption.innerHTML!=this.langVars.defaultTitle){this.caption.appear({duration:0.5});}
$('headerContainer').setStyle('visibility: hidden;');$('mainContainer').setStyle('visibility: hidden;');$('footerContainer').setStyle('visibility: hidden;');$('videoBBCodeObject-'+this.activeVideo).removeClassName('videoBBCodeObject').addClassName('videoBBCodeZoomedObject').show();this.resize();Event.observe(window,'resize',this._resize);}.bind(this)});}},zoomOut:function(){$('videoBBCodeObject-'+this.activeVideo).hide();var video=$('videoBBCodeObject-'+this.activeVideo);video.addClassName('videoBBCodeObject').removeClassName('videoBBCodeZoomedObject').setStyle('left: 0px; top: 0px;');video.width=this.activeVideoData['width'];video.height=this.activeVideoData['height'];video.writeAttribute('data',this.activeVideoData['data']);video.select('param[name="movie"]')[0].writeAttribute('value',this.activeVideoData['movieParam']);video.select('param[name="flashVars"]')[0].replace(new Element('param').writeAttribute('name','flashVars').writeAttribute('value',this.activeVideoData['flashVars']));$('headerContainer').setStyle('visibility: visible;');$('mainContainer').setStyle('visibility: visible;');$('footerContainer').setStyle('visibility: visible;');this.copyright.hide();this.caption.hide();this.background.fade({duration:1,afterFinish:function(){$('videoBBCodeObject-'+this.activeVideo).setStyle('display: block;');this.activeVideo=0;}.bind(this)});this.background.onclick='';Event.stopObserving(window,'resize',this._resize);},resize:function(){if(this.activeVideo){var width=600;var height=450;var maxWidth=document.viewport.getWidth()-document.viewport.getWidth()/10;var maxHeight=document.viewport.getHeight()-document.viewport.getHeight()/8;if(maxWidth>1200)maxWidth=1200;if(maxHeight>900)maxHeight=900;if(maxWidth>width)width=maxWidth;if(maxHeight>height)height=maxHeight;var left=document.viewport.getWidth()/2-width/2;var top=document.viewport.getHeight()/2-height/2+(IS_SAFARI_MOBILE?document.viewport.getScrollOffsets().top:0);var element=$('videoBBCodeObject-'+this.activeVideo);if(element){element.setStyle('left: '+left+'px; top: '+top+'px;');element.width=width
element.height=height}}},suicide:function(){$$('body')[0].select('.videoBBCodeObject, .videoBBCodeZoomedObject').invoke('remove');}});
