var MGFX=MGFX||{};
MGFX.Rotater=new Class({Implements:[Options,Events],options:{slideInterval:5E3,transitionDuration:1E3,startIndex:0,autoplay:true,hover:true,hash:true,onAutoPlay:$empty,onRotate:$empty,onShowSlide:$empty,onStop:$empty,onPause:$empty,onResume:$empty},initialize:function(a,b){this.setOptions(b);this.slides=$$(a);this.createFx();this.showSlide(this.options.startIndex);if(this.slides.length<2)this.options.autoplay=false;this.options.autoplay&&this.autoplay();return this},createFx:function(){if(!this.slideFx)this.slideFx=new Fx.Elements(this.slides,
{duration:this.options.transitionDuration,link:"cancel"});this.slides.each(function(a){a.setStyle("display","block","opacity",1)})}.protect(),setupHover:function(){var a=new Date,b,d=this.options.slideInterval,c,f=this._onRotate=function(){if(this.slideshowInt)a=new Date,d=this.options.slideInterval},g=this._onMouseEnter=function(){this.stop();b=new Date;$clear(c);this.fireEvent("onPause")}.bind(this),h=this._onMouseLeave=function(){var e=b-a;a=new Date-e;c=function(){this.autoplay();this.rotate();
this.fireEvent("onResume")}.delay(d-e,this)}.bind(this);this.addEvent("onRotate",f);this.slides.addEvents({mouseenter:g,mouseleave:h})}.protect(),removeHover:function(){this.removeEvent("onRotate",this._onRotate);this.slides.removeEvents({mouseenter:this._onMouseEnter,mouseleave:this._onMouseLeave})},showSlide:function(a){if(a==this.currentSlide)return this;var b={};this.slides.each(function(d,c){b[c.toString()]=c==a&&c!=this.currentSlide?{opacity:1,display:"block"}:{opacity:0,display:"none"}},this);
this.fireEvent("onShowSlide",a);this.currentSlide=a;this.slideFx.start(b);return this},autoplay:function(){this.options.hover&&this.setupHover();this.slideshowInt=this.rotate.periodical(this.options.slideInterval,this);this.fireEvent("onAutoPlay");return this},stop:function(a){$clear(this.slideshowInt);this.fireEvent("onStop");a&&this.options.hover&&this.removeHover();return this},rotate:function(){var a=this.getNext();this.showSlide(a);this.fireEvent("onRotate",a);return this},random:function(){var a=
Math.floor(Math.random()*this.slides.length),a=a==this.currentSlide?this.getNext():a;this.showSlide(a);this.fireEvent("onRandom",a);return this},getNext:function(){var a=this.currentSlide;return a+1>=this.slides.length?0:a+1}.protect()});
