//Slideshow, <http://www.circlesquare.biz>. Copyright (c) 2008, circlesquare solutions ltd. BSD Style License.

var Slideshow=new Class({Implements:[Events,Options],options:{onLoad:function(){this.displayed(0);this.play();},onLoop:$empty,onPlay:$empty,onPause:$empty,onStop:$empty,onBeforeSwap:$empty,onAfterSwap:$empty,interval:4000,duration:1000,transition:"quad:out",random:false,images:[]},initialize:function(_1,_2){this.setOptions(_2);this.slideshow=$(_1);if(this.slideshow.getStyle("position")=="static"){this.slideshow.setStyle("position","relative");}this.current=this.slideshow.getElement("img");this.swapping=false;this.playing=false;this.paused=false;this.history=[];this.fireEvent("load");},play:function(){if(!this.playing){this.playing=true;this.queue();this.fireEvent("play");}},pause:function(){if(this.playing){this.playing=false;this.paused=true;$clear(this.jumper);this.fireEvent("pause");}},stop:function(){if(this.playing){this.playing=false;$clear(this.jumper);}if(this.playing||this.paused){this.history=[];this.fireEvent("stop");}},displayed:function(_3){this.i=_3;this.history[this.history.length]=_3;},jump:function(_4){this.displayed(_4.i);var _5=this.current.getPosition(this.slideshow);_4.image.setStyles({position:"absolute",top:(_5.y-this.slideshow.getStyle("border-top").toInt()),left:(_5.x-this.slideshow.getStyle("border-left").toInt()),opacity:0}).inject(this.slideshow);var fx=new Fx.Tween(_4.image,{wait:false,duration:this.options.duration,transition:this.options.transition,onComplete:(this.playing)?this.queue.pass(_4.image,this):this.swap.pass(_4.image,this)});this.swapping=true;this.fireEvent("beforeSwap");fx.start("opacity",1);},swap:function(_7){_7.setStyles(this.current.getStyles("position","top","left"));this.current.destroy();this.current=_7;this.swapping=false;this.fireEvent("afterSwap");},queue:function(_8){if($defined(_8)){this.swap(_8);}if(this.playing){if(this.history.length==this.options.images.length){this.history=[];this.fireEvent("loop");}this.jumper=this.jump.pass(this.next(),this).delay(this.options.interval);}},next:function(_9){if(!$defined(_9)){var _a=0;if(this.options.random){var _b=[];for(var i=0;i<this.options.images.length;i++){if(!this.history.contains(i)&&i!=this.i){_b[_b.length]=i;}}_a=_b[Math.floor(Math.random()*_b.length)];}else{if(this.i+1>=this.options.images.length){this.history=[];}if(this.history.length==0){_a=0;}else{_a=this.i+1;}}}var _d=new Image();var _e=$(_d)||new Element("img");_e.setProperties(this.options.images[_a]);return {i:_a,image:_e};},change:function(_f){this.i=((this.i+_f)%this.options.images.length);if(this.i<0){this.i=this.options.images.length+this.i;}if(!this.swapping){$clear(this.jumper);if(this.options.random){this.jump(this.next(),this);}else{this.jump(this.next(this.i),this);}}}});
