/**
 * MIT style license
 * @author Constantin Boiangiu (constantin[at]php-help.ro)
 * @version 1.0
 * @framework MooTools 1.2
 * script homepage: http://www.php-help.ro/mootools-12-javascript-examples/youtube-player-embed-with-attached-playlist/
 */
var YTPlayer=new Class({setPlayer:function(C,D){var B="http://www.youtube.com/v/"+C+"&enablejsapi=1&playerapiid=YTV_videoPlayer&rel="+this.options.playerConfig.showRelated+"&showsearch="+this.options.playerConfig.showSearch+"&showinfo="+this.options.playerConfig.showInfo;var A=this.items.players[D].getSize();this.swfObj=new Swiff(B,{id:"YTV_videoPlayer_"+D,container:this.items.players[D].get("id"),width:A.x,height:A.y,params:{wmode:"transparent",allowScriptAccess:"always"}})},playNew:function(A,B){$("YTV_videoPlayer_"+B).cueVideoById(A);$("YTV_videoPlayer_"+B).playVideo();return false}});
var MyTube=new Class({Implements:[Options,YTPlayer],options:{playerConfig:{showRelated:0,showSearch:0,showInfo:0},messageLoading:null,onlyEmbeddable:true,defaultDisplay:1},initialize:function(A){this.setOptions(A);this.items=this.scanPage();if(!this.items){return}this.items.playlists.each(function(D,G){var C=D.get("html").replace(/<!--|-->/g,"");var F=JSON.decode(C);D.empty();var B="http://gdata.youtube.com/feeds/api/";if(F.user){B+="users/"+F.user+"/uploads/?v=2&alt=json-in-script&orderby=published";if(F.list){B+="&max-results="+F.list}}else{if(F.movies){B+="videos/?v=2&alt=json-in-script&orderby=published&q="+F.movies}}var E=this.options.messageLoading||"Loading playlist, please wait...";D.addClass("loading").set({text:F.loadingMessage||E});this.setToggle(G,F.displayOnLoad||this.options.defaultDisplay,G);var H=$defined(F.onlyEmbeddable)?F.onlyEmbeddable:this.options.onlyEmbeddable;new Request.JSONP({url:B+(H?"&format=5":""),onComplete:function(J){var I=J.feed.entry;D.removeClass("loading").empty();this.setPlaylist(I,G,D)}.bind(this)}).send()}.bind(this))},setToggle:function(C,E,D){var B=new Fx.Slide(this.items.playlists[C]);var A=new Fx.Slide(this.items.players[C]);if(E==1){A.hide()}else{B.hide()}this.items.playlists[C].store("listFx",B);this.items.playlists[C].store("playerFx",A);this.items.togglers[C].addEvent("click",function(F){new Event(F).stop();B.toggle().chain(function(){if(B.open){if($("YTV_videoPlayer_"+D)){$("YTV_videoPlayer_"+D).pauseVideo()}}}.bind(this));A.toggle()}.bind(this))},setPlaylist:function(C,E,D){var B=[];C.each(function(H,F){if(F==0){this.setPlayer(H.media$group.yt$videoid.$t,E)}var G=new Element("a",{href:"#",title:H.media$group.media$title.$t,"class":"MyTube_Tippers",rel:"Click to view",styles:{display:"block",position:"relative","background-image":"url("+H.media$group.media$thumbnail[0].url+")",width:H.media$group.media$thumbnail[0].width,height:H.media$group.media$thumbnail[0].height},events:{click:function(I){new Event(I).stop();var J=this.items.playlists[E].retrieve("listFx");var K=this.items.playlists[E].retrieve("playerFx");J.toggle();K.toggle().chain(this.playNew.pass([H.media$group.yt$videoid.$t,E],this.player))}.bind(this)}});B[F]=new Element("div",{"class":"MyTube_video"}).adopt(G)}.bind(this));if(B.length>1){D.adopt(B);var A=new Tips(".MyTube_Tippers",{className:"MyTube_Tips"})}},scanPage:function(){var A=$$(".MT_youtube_player");var C=$$(".MT_playlist");var B=$$(".toggle");if(A.length==0){return false}return{players:A,playlists:C,togglers:B}}});function onYouTubePlayerReady(){return}window.addEvent("load",function(){this.YTVplayer=new MyTube({messageLoading:"Loading, please wait...",onlyEmbeddable:true,defaultDisplay:1})}.bind(this));