var Videobox={init:function(a){this.options=Object.extend({resizeDuration:500,initialWidth:250,initialHeight:250,defaultWidth:425,defaultHeight:350,animateCaption:true,flvplayer:"/macarons/video/flvplayer.swf"},a||{});this.anchors=[];$A($$("a")).each(function(c){if(c.rel&&c.href&&c.rel.test("^vidbox","i")){c.addEvent("click",function(d){d=new Event(d);d.stop();this.click(c)}.bind(this));this.anchors.push(c)}},this);this.overlay=new Element("div").setProperty("id","lbOverlay").injectInside(document.body);this.center=new Element("div").setProperty("id","lbCenter").setStyles({width:this.options.initialWidth+"px",height:this.options.initialHeight+"px",marginLeft:"-"+(this.options.initialWidth/2)+"px",display:"none"}).injectInside(document.body);this.bottomContainer=new Element("div").setProperty("id","lbBottomContainer").setStyle("display","none").injectInside(document.body);this.bottom=new Element("div").setProperty("id","lbBottom").injectInside(this.bottomContainer);new Element("a").setProperties({id:"lbCloseLink",href:"#"}).injectInside(this.bottom).onclick=this.overlay.onclick=this.close.bind(this);this.caption=new Element("div").setProperty("id","lbCaption").injectInside(this.bottom);this.number=new Element("div").setProperty("id","lbNumber").injectInside(this.bottom);new Element("div").setStyle("clear","both").injectInside(this.bottom);var b=this.nextEffect.bind(this);this.overlayFx=new Fx.Tween(this.overlay,{duration:this.options.resizeDuration}).set("opacity",0);this.centerFx=new Fx.Morph(this.center,{duration:this.options.resizeDuration,transition:Fx.Transitions.Sine.easeOut,onComplete:b});this.bottomFx=new Fx.Tween(this.bottomContainer,{duration:2000,transition:Fx.Transitions.Sine.easeOut})},click:function(a){if(pageTracker){pageTracker._trackEvent("Videos","Play",a.href)}return this.open(a.href,a.title,a.rel)},open:function(b,a,c){this.href=b;this.title=a+'<br /><a href="contact-us.aspx'+window.location.search+'">Contact us</a> for more information.';this.rel=c;this.position();this.setup();this.video(this.href);this.top=Window.getScrollTop()+(Window.getHeight()/15);this.center.setStyles({top:this.top+"px",display:""});this.overlayFx.start("opacity",0.8);this.step=1;this.center.setStyle("background","#fff url(/macarons/images/videobox/loading.gif) no-repeat center");var d=b.substring(b.lastIndexOf("/")+1,b.length);this.caption.innerHTML=this.title;this.centerFx.start({height:this.options.contentsHeight})},setup:function(){var a=this.rel.match(/[0-9]+/g);this.options.contentsWidth=(a&&(a[0]>0))?a[0]:this.options.defaultWidth;this.options.contentsHeight=(a&&(a[1]>0))?a[1]:this.options.defaultHeight},position:function(){this.overlay.setStyles({top:window.getScrollTop()+"px",height:window.getHeight()+"px"})},video:function(a){if(a.match(/\.flv/i)){this.flash=true;this.so=new SWFObject(this.options.flvplayer+"?file="+a+"&autostart=true","flvvideo",this.options.contentsWidth,this.options.contentsHeight,"0","#000");this.so.addParam("allowfullscreen","true")}else{this.flash=true;this.videoID=a;this.so=new SWFObject(this.videoID,"flvvideo",this.options.contentsWidth,this.options.contentsHeight,"0")}},nextEffect:function(){switch(this.step++){case 1:this.centerFx.start({width:[this.options.contentsWidth],marginLeft:[this.options.contentsWidth/-2]});break;case 2:this.center.setStyle("background","#fff");this.flash?this.so.write(this.center):this.center.setHTML(this.other);this.bottomContainer.setStyles({top:(this.top+this.center.clientHeight)+"px",marginLeft:this.center.style.marginLeft,width:this.options.contentsWidth+"px",display:""});if(this.options.animateCaption){this.bottomFx.set("margin-top",-250);this.bottomFx.start("margin-top",0);break}this.step++}},close:function(){this.overlayFx.start("opacity",0);this.center.style.display=this.bottomContainer.style.display="none";this.center.innerHTML="";return false}};window.addEvent("domready",Videobox.init.bind(Videobox));
