var ProtoTube=Class.create({initialize:function(a,b){this.element=$(a);var c=this.element.readAttribute("href");this.videoID=c.replace(/^[^v]+v.(.{11}).*/,"$1");this.body=$$("body")[0];this.html=$$("html")[0];Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;this.options={overlay:true,duration:0.5,opacity:0.8,imagePreview:true,imageID:1,playerWidth:425,playerHeight:350,fs:1,autoplay:0,loop:0,hd:0,showinfo:0,rel:1,youtubeVideoUrl:"http://www.youtube.com/v/",youtubeImageUrl:"http://img.youtube.com/vi/"};Object.extend(this.options,b||{});this.options.overlay?this.setupPreviewOverlay():this.directEmbed()},setupPreviewOverlay:function(){if(this.options.imagePreview){this.getImagePreview()}this.addOverlayMarkup();Event.observe(this.element,"click",this.showProtoTube.bindAsEventListener(this));Event.observe(this.overlay,"click",this.hideProtoTube.bindAsEventListener(this));Event.observe(this.ProtoTube,"click",function(a){Event.stop(a)})},directEmbed:function(){this.getVideoEmbed(this.element)},addOverlayMarkup:function(){this.ProtoTube=new Element("div",{className:"prototube"});this.wrapper=new Element("div").update("<p>Loading video from You Tube...</p>");this.ProtoTube.insert(this.wrapper);this.overlay=new Element("div",{className:"overlay"});this.overlay.insert(this.ProtoTube);this.body.insert(this.overlay.hide())},showProtoTube:function(a){Event.stop(a);this.toggleTroubleElements("hidden");this.getVideoEmbed(this.wrapper);this.ProtoTube.setStyle({width:this.options.playerWidth+"px",height:this.options.playerHeight+"px",marginTop:"-"+this.options.playerHeight/2+"px",marginLeft:"-"+this.options.playerWidth/2+"px"});if(Prototype.Browser.IE6){this.prepareIE("100%","hidden")}new Effect.Appear(this.overlay,{duration:this.options.duration,from:0,to:this.options.opacity})},hideProtoTube:function(){new Effect.Fade(this.overlay,{duration:this.options.duration,afterFinish:function(){this.toggleTroubleElements("visible");if(Prototype.Browser.IE6){this.prepareIE("auto","auto")}}.bind(this)})},getVideoEmbed:function(a){var b=a.identify();var c={fs:this.options.fs,autoplay:this.options.autoplay,loop:this.options.loop,hd:this.options.hd,showinfo:this.options.showinfo,rel:this.options.rel};var d={allowScriptAccess:"always",allowFullScreen:true,menu:false};var e={};swfobject.embedSWF(this.options.youtubeVideoUrl+this.videoID,b,this.options.playerWidth,this.options.playerHeight,"9",null,c,d,e)},getImagePreview:function(){this.image=new Image();this.element.update(this.image);this.image.src=this.options.youtubeImageUrl+this.videoID+"/"+this.options.imageID+".jpg"},toggleTroubleElements:function(a){$$("select","object","embed").each(function(b){b.style.visibility=a})},prepareIE:function(a,b){this.body.setStyle({height:a,overflow:b});this.html.setStyle({height:a,overflow:b})}})
