function onYouTubePlayerReady(t){var e=$("#"+t);e.mb_setMovie()}function playerState(t,e){var a=$("#"+e).get(0),i=$("#"+a.id+"_data").get(0);0==t&&i.isBgndMovie&&a.playVideo(),-1!=t&&3!=t||!i.isBgndMovie||($(a).css({opacity:0}),$(".mbYTP_raster").css({opacity:.5,backgroundColor:"black"}).fadeIn(),$(".mbYTP_bufferImg").css({opacity:.2}).fadeIn(),$.browser.msie||$("#wrapper_"+a.id).css({opacity:0})),1==t&&i.isBgndMovie&&($(a).css({opacity:i.opacity}),$(".mbYTP_raster").css({opacity:1,backgroundColor:"transparent"}),$(".mbYTP_bufferImg").fadeOut(),$.browser.msie||$("#wrapper_"+a.id).animate({opacity:1},1e3)),1!=t||i.isBgndMovie||(a.totalBytes=a.getVideoBytesTotal()),0!=t||i.isBgndMovie||$(a).stopYTP()}!function(t){t.YTPlayer={name:"jquery.mb.YTPlayer",version:1.2,author:"Matteo Bicocchi",width:450,controls:{play:"",pause:"",mute:"",unmute:""},rasterImg:"images/raster.png",setYTPlayer:function(){var e=this;t.getScript("http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js",function(){e.each(function(){if(t(this).is("a")){t(this).attr("id")||t(this).attr("id","YTP_"+(new Date).getMilliseconds());var e=t(this).attr("id"),a=t("");a.attr("id",e+"_data").hide();var i=a.get(0);i.opacity=1,i.isBgndMovie=!1,i.width=t.YTPlayer.width,i.quality="default",i.muteSound=!1,i.hasControls=!1,i.ratio="16/9",i.bufferImg=!1;var s="undefined"!=typeof document.YTPBG;t.metadata&&(t.metadata.setType("class"),t(this).metadata().quality&&(i.quality=t(this).metadata().quality),t(this).metadata().width&&(i.width=t(this).metadata().width),t(this).metadata().opacity&&(i.opacity=t(this).metadata().opacity),t(this).metadata().isBgndMovie&&!s&&(i.isBgndMovie=t(this).metadata().isBgndMovie,i.width=t(this).metadata().isBgndMovie.width?t(this).metadata().isBgndMovie.width:"window"),t(this).metadata().muteSound&&(i.muteSound=t(this).metadata().muteSound),t(this).metadata().hasControls&&(i.hasControls=t(this).metadata().hasControls),t(this).metadata().ratio&&(i.ratio=t(this).metadata().ratio),t(this).metadata().bufferImg&&(i.bufferImg=t(this).metadata().bufferImg),t(this).metadata().ID&&(i.ID=t(this).metadata().ID));var o=t(i.ID?"#"+i.ID:"body");"window"==i.width?(i.height="100%",i.width="100%",i.ID&&(i.height=o.outerHeight()+40,i.width=o.outerWidth())):i.height=Math.ceil("16/9"==i.ratio?9*i.width/16:3*i.width/4);var r="";if(t(o).append(a),i.isBgndMovie){if(t.browser.msie&&t.browser.version<8||i.ID){var n=t("
").css({position:"relative",zIndex:0});t(o).wrapInner(n),t(o).prepend(t(this))}else t(o).after(t(this));var d=i.ID?"absolute":"fixed";if(r=t("").attr("id","wrapper_"+e).css({overflow:"hidden",position:d,left:0,top:0,width:"100%",height:"100%"}),t(this).wrap(r),-1==!i.width.toString().indexOf("%")){var l=t("").css({position:d,top:"4/3"!=i.ratio||i.ID?0:-(i.height/4),left:0,display:"block",width:i.width,height:i.height});t(this).wrap(l)}}else r=t("").attr("id","wrapper_"+e).css({width:i.width,height:i.height,position:"relative"}).addClass("mb_YTVPlayer"),t(this).wrap(r);var u={allowScriptAccess:"always",wmode:"transparent",allowFullScreen:"true"},m={id:e};i.movieURL=t(this).attr("href").match(/[\\?&]v=([^]*)/)[1],swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid="+e,e,i.width,i.height,"8",null,null,u,m)}})})},setMovie:function(){var e=t(this).get(0),a=t("#"+e.id+"_data").get(0),i="undefined"!=typeof document.YTPBG,s=a.movieURL;t(e).css({opacity:a.opacity});var o=a.ID?"absolute":"fixed";if(a.isBgndMovie&&!i){{var r=t("").addClass("mbYTP_raster").css({position:o,top:0,left:0,width:"100%",height:"100%",background:"url("+t.YTPlayer.rasterImg+")"}).hide(),n=a.bufferImg?t("").addClass("mbYTP_bufferImg").css({position:o,top:0,left:0,width:"100%",height:"100%",background:"url("+a.bufferImg+")"}).hide():!1,d=t(e).parents("div:first");a.ratio}a.ID||(document.YTPBG=!0),t(d).after(r),a.bufferImg&&r.after(n)}a.isBgndMovie?(e.loadVideoByUrl("http://www.youtube.com/v/"+s,0),a.isBgndMovie.mute&&e.mute()):(e.cueVideoByUrl("http://www.youtube.com/v/"+s,0),t(e).buildYTPControls()),e.setPlaybackQuality(a.quality),e.addEventListener("onStateChange",'(function(state) { return playerState(state, "'+e.id+'"); })')},playYTP:function(){var e=t(this).get(0),a=t(e).parent().find(".mb_YTVPPlaypause");a.html(t.YTPlayer.controls.pause),e.playVideo()},stopYTP:function(){var e=t(this).get(0),a=t(e).parent().find(".mb_YTVPPlaypause");a.html(t.YTPlayer.controls.play),e.pauseVideo()},pauseYTP:function(){var e=t(this).get(0),a=t(e).parent().find(".mb_YTVPPlaypause");a.html(t.YTPlayer.controls.play),e.pauseVideo()},setYTPVolume:function(e){{var a=t(this).get(0);t(a).parent().find(".mb_YTVPVolume")}a.setVolume(e)},muteYTPVolume:function(){var e=t(this).get(0),a=t(e).parent().find(".mb_YTVPMuteUnmute");a.html(t.YTPlayer.controls.unmute),e.mute()},unmuteYTPVolume:function(){var e=t(this).get(0),a=t(e).parent().find(".mb_YTVPMuteUnmute");a.html(t.YTPlayer.controls.mute),e.unMute()},manageYTPProgress:function(){var e=t(this).get(0),a=t(e).parent(".mb_YTVPlayer"),i=a.find(".mb_YTVPProgress"),s=a.find(".mb_YTVPLoaded"),o=a.find(".mb_YTVTime"),r=i.outerWidth(),n=e.getVideoStartBytes(),d=e.getVideoBytesTotal(),l=e.getVideoBytesLoaded(),u=Math.floor(e.getCurrentTime()),m=Math.floor(e.getDuration()),p=u*r/m,h=0;n&&(h=e.timeW);var c=l*(r-h)/d;return s.css({left:h,width:c}),o.css({left:0,width:p}),{totalTime:m,currentTime:u}},buildYTPControls:function(){var e=t(this).get(0);if("undefined"==typeof e.isInit){e.isInit=!0;var a=t(this).parent(".mb_YTVPlayer"),i=t("").addClass("mb_YTVPBar").css({whiteSpace:"noWrap",position:"absolute"}).hide(),s=t(""+t.YTPlayer.controls.play+"").addClass("mb_YTVPPlaypause").click(function(){1==e.getPlayerState()?t(e).pauseYTP():t(e).playYTP()}),o=t(""+t.YTPlayer.controls.mute+"").addClass("mb_YTVPMuteUnmute").click(function(){e.isMuted()?t(e).unmuteYTPVolume():t(e).muteYTPVolume()}),r=t("").addClass("mb_YTVPTime"),n=t("").addClass("mb_YTVPProgress").css("position","absolute").click(function(t){l.css({width:t.clientX-l.offset().left}),e.timeW=t.clientX-l.offset().left,a.find(".mb_YTVPLoaded").css({width:0});var i=Math.floor(e.getDuration());e.goto=l.outerWidth()*i/n.outerWidth(),e.seekTo(e.goto,!0),a.find(".mb_YTVPLoaded").css({width:0})}),d=t("").addClass("mb_YTVPLoaded").css("position","absolute"),l=t("").addClass("mb_YTVTime").css("position","absolute");n.append(d).append(l),i.append(s).append(o).append(r).append(n),a.append(i),a.hover(function(){i.fadeIn(),clearInterval(e.getState),e.getState=setInterval(function(){var i=t(e).manageYTPProgress();t(".mb_YTVPTime").html(t.YTPlayer.formatTime(i.currentTime)+" / "+t.YTPlayer.formatTime(i.totalTime)),1==e.getPlayerState()&&t(".mb_YTVPPlaypause").html()!=t.YTPlayer.controls.pause&&a.find(".mb_YTVPPlaypause").html(t.YTPlayer.controls.pause),2==e.getPlayerState()&&a.find(".mb_YTVPPlaypause").html(t.YTPlayer.controls.play)},500)},function(){i.fadeOut(),clearInterval(e.getState)})}},formatTime:function(t){var e=Math.floor(t/60),a=t-60*e;return(9>e?"0"+e:e)+" : "+(9>a?"0"+a:a)}},t.fn.mb_YTPlayer=t.YTPlayer.setYTPlayer,t.fn.mb_setMovie=t.YTPlayer.setMovie,t.fn.buildYTPControls=t.YTPlayer.buildYTPControls,t.fn.playYTP=t.YTPlayer.playYTP,t.fn.stopYTP=t.YTPlayer.stopYTP,t.fn.pauseYTP=t.YTPlayer.pauseYTP,t.fn.muteYTPVolume=t.YTPlayer.muteYTPVolume,t.fn.unmuteYTPVolume=t.YTPlayer.unmuteYTPVolume,t.fn.manageYTPProgress=t.YTPlayer.manageYTPProgress}(jQuery);