/*
 *	Silk - A Developer's Toolbox
 *	
 *	(c) 2007 - 2008 adamnfish
 *	http://silk.adamnfish.com
 *	
 *	MIT-style licence (http://silk.adamnfish.com/licence)
 *	
 *	Thanks to the MooTools devs, http://mootools.net
 */
var Silk=function(){};(function(){this.version=0.02;this.namespace="Silk";if(!B){var B=new Hash({image:function(K,J){J=$merge({onload:$empty,onabort:$empty,onerror:$empty},J);var L=new Image();var I=$(L)||new Element("img");["load","abort","error"].each(function(M){var N="on"+M;var O=J[N];delete J[N];L[N]=function(){if(!L){return}if(!I.parentNode){I.width=L.width;I.height=L.height}L=L.onload=L.onabort=L.onerror=null;O.delay(1,I,I);I.fireEvent(M,I,1)}});L.src=I.src=K;if(L&&L.complete){L.onload.delay(1)}return I.setProperties(J)},images:function(L,K){K=$merge({onComplete:$empty,onProgress:$empty},K);if(!L.push){L=[L]}var I=[];var J=0;L.each(function(N){var M=new B.image(N,{onload:function(){K.onProgress.call(this,J,L.indexOf(N));J++;if(J==L.length){K.onComplete()}}});I.push(M)});return new Elements(I)}})}var A=/^\.|^#|^.+\s.+$/;var C=function(J,I){J.each(function(K){$splat(I.options[K]).each(function(N){var M=[];switch($type(N)){case"string":var L=N.match(/.*\[([0-9]+)\]$/);if(L){L[1].split(",").each(function(O){M.push(O.trim())})}N=$(N)||N;case"array":N=$$(N);case"element":N.addEvent("click",function(O){O.preventDefault();I[K](M);this.blur()})}})})};Number.implement({mod:function(J){var I=this%J;return I<0?I+J:I}});Array.implement({shuffle:function(){for(var K=1,J=this.length;K<J;K++){var I=$random(0,J-K);this.push(this[I]);this.splice(I,1)}return this},permute:function(I){for(var K=0,J=this.length;K<J;K++){this[(K+I).mod(J)+J]=this[K]}this.splice(0,J);return this}});this.installed=function(I){return this.modules.some(function(J){return I.toLowerCase()==J.toLowerCase()})};this.modules=["player","scroll"];var F=["onFlowPlayerReady","onClipDone","onClipChanged","onLoadBegin","onStreamNotFound","onPlay","onStop","onPause","onResume","onCuePoint","onStartBuffering","onBufferFull","onBufferFlush","onMetaData"];var D={};var H=1;F.each(function(I){D[I]=[];window[I]=function(){var J=arguments;D[I].each(function(K){K.run(J)})}});var G=this.addCallback=function(K,I,J){D[K].push(I)};var E=this.addCallbacks=function(I){for(callback in I){D[callback].push(I[callback])}};this.Player=new Class({Implements:[Options,Events],flashVars:{type:"application/x-shockwave-flash",pluginspage:"http://www.adobe.com/go/getflashplayer",quality:"high",allowscriptaccess:"always",allowfullscreen:false,width:320,height:240,bgcolor:"#000000"},options:{playerVars:{autoPlay:false,loop:false,autoRewind:true,controlsOverVideo:"ease",initialScale:"scale",autoBuffering:true,useNativeFullScreen:true,usePlayOverlay:true,showMenu:false,showPlayButton:true,controlBarGloss:"low",showFullScreenButton:false,menuItems:"[1, 1, 1, 1, 0, 0, 0]"},thumb:false,onFail:$empty,onFlowPlayerReady:$empty,onClipDone:$empty,onClipChanged:$empty,onLoadBegin:$empty,onStreamNotFound:$empty,onPlay:$empty,onStop:$empty,onPause:$empty,onResume:$empty,onCuePoint:$empty,onBufferFull:$empty,onBufferFlush:$empty,onMetaData:$empty,onStartPlaying:$empty,onStopPlaying:$empty},initialize:function(J,N,M,K){this.container=$(J);this.current=0;this.ready=false;this.playing=false;this.stack=[];this.playlist=[];N=$type(N)=="string"?{src:N}:N;this.flashVars=$merge(this.flashVars,N);this.flashVars.onFail=this.options.onFail;this.setOptions(K);this.playerVars=this.options.playerVars;this.playerId=H++;C(["play","pause","toggle","forward","backwards","stop","prev","next"],this);this.thumb=this.options.thumb||this.playerVars.splashImageFile;if(this.playerVars.videoFile){this.playlist.push({url:this.playerVars.videoFile});if(this.playerVars.splashFileImage){this.playlist[0].thumb=this.playerVars.splashFileImage}}if(M){this.makePlaylist(M)}delete this.playerVars.splashImageFile;delete this.playerVars.videoFile;var L=(function(O){if(O.playerId==this.playerId){this.playing=true;if(this.ready&&this.api.getIsPlaying()){this.fireEvent("startPlaying",O)}}}).bind(this);var I=(function(O){if(O.playerId==this.playerId){this.playing=false;this.fireEvent("stopPlaying",O)}}).bind(this);E({onFlowPlayerReady:function(){(function(){if(this.api.getVersion){this.fireEvent("flowPlayerReady");this.fireEvent("stopPlaying");if(this.stack){this.stack.each(function(O){O()});this.stack=[]}this.api.setPlayerId(this.playerId);this.ready=true}}).delay(300,this)}.bind(this),onPlay:L,onResume:L,onClipDone:I,onClipChanged:I,onPause:I});F.each(function(O){if(O!="onFlowPlayerReady"){G(O,function(P){if(P.playerId==this.playerId){this.fireEvent(Events.removeOn(O),P)}}.bind(this))}},this);this.injectVideo(0)},injectVideo:function(K){this.ready=false;this.playing=false;var L=[];var J=this.playlist[K].url;var I=this.playlist[K].thumb||this.thumb;if(I&&this.playerVars.usePlayOverlay){L.push({url:I,overlayId:"play"})}else{if(I){L.push({url:I})}}L.push({url:J});this.api=this.embed(this.container,this.flashVars,{config:$merge(this.playerVars,{playList:L})});this.current=K},embed:function(I,K,J){return flashembed(I,K,J)},makePlaylist:function(L){switch($type(L)){case"object":this.playlist=[L];break;case"array":if(L.setStyle){L.each(this.addLinks,this)}else{this.playlist=L}break;case"string":var I=$$(L);if(I.length){I.each(function(N,M){this.addLink(N,M)}.bind(this));break}else{if(!$(L)){if(L!=this.playerVars.videoFile){this.playlist.push({url:L})}break}}case"element":var K=$(L);if(K.get("tag")=="ul"){var J=K.getElements("li");J.each(function(M,O){var N=M.getElement("a.play")||M.getElement("a");if(N){this.addLink(N,O)}}.bind(this));break}else{K.getElements("a").each(this.addLink,this)}default:return false}},addLink:function(K,J){this.playlist.push({url:K.href});if(this.thumb){this.playlist[this.playlist.length-1].thumb=this.thumb}var I=this.playlist.length-1;$(K).addEvent("click",function(L){L.preventDefault();this.play(I);$(K).blur()}.bind(this))},remote:function(J,I){if(this.ready){return this.api[J](I)||this}else{this.stack.push(this.remote.pass([J,I],this));return false}},play:function(I){if($chk(I)&&I!=this.current){this.injectVideo(I);this.stack.push(this.play.bind(this))}else{this.remote("DoPlay")}return this},pause:function(){this.remote("Pause");return this},toggle:function(){if(this.ready){if(this.playing){this.pause()}else{this.play()}}else{this.stack.push(function(){this.toggle()}.bind(this))}return this},seek:function(J){var I=this.remote("getDuration");return $type(I)=="number"?this.remote("Seek",J.limit(0,I.floor())):false},move:function(K,I){K=K||5;var J=this.remote("getTime");return $chk(J)?this.seek(J.toFloat()+(K*I)):false},forward:function(I){this.move(I,1);return this},backwards:function(I){this.move(I,-1);return this},stop:function(){this.remote("DoStop");return this},next:function(){this.fireEvent("stopPlaying");this.play((this.current+1).mod(this.playlist.length));return this},prev:function(){this.fireEvent("stopPlaying");this.play((this.current-1).mod(this.playlist.length));return this}});this.Scroll=new Class({Extends:Fx.Scroll,initialize:function(J,K){K=K||document;this.doc=K.getDocument(),win=K.getWindow();this.parent(this.doc,J);this.links=this.options.links?$$(this.options.links):$$(this.doc.links);var I=win.location.href.match(/^[^#]*/)[0]+"#";this.links.each(function(M){if(M.href.indexOf(I)!=0){return}var L=M.href.substr(I.length);if(L&&this.doc.getElement("a[name="+L+"]")){this.useLink(M,L)}},this)},useLink:function(J,I){J.addEvent("click",function(K){K.preventDefault();this.anchor=I;var L=this.doc.getElement("a[name="+I+"]");this.toElement(L);L.id+="_";window.setTimeout(function(){L.id=I},0);J.blur()}.bind(this))}})}).apply(Silk);