var slideGallery=new Class({Version:"1.3",Implements:[Options,Events],options:{holder:".holder",elementsParent:"ul",elements:"li",nextItem:".next",prevItem:".prev",stop:".stop",start:".start",speed:600,duration:4E3,steps:1,current:0,transition:"sine:in:out",direction:"horizontal",mode:"callback",currentClass:"current",nextDisableClass:"next-disable",prevDisableClass:"prev-disable",paging:!1,pagingEvent:"click",pagingHolder:".paging",random:!1,autoplay:!1,autoplayOpposite:!1,stopOnHover:!0},initialize:function(a, b){this.gallery=a.length==null?a:a[0];if(!this.gallery)return!1;this.setOptions(b);this.holder=this.gallery.getElement(this.options.holder);this.itemsParent=this.holder.getElement(this.options.elementsParent);this.items=this.itemsParent.getElements(this.options.elements);this.next=this.gallery.getElement(this.options.nextItem);this.prev=this.gallery.getElement(this.options.prevItem);this.stop=this.gallery.getElement(this.options.stop);this.start=this.gallery.getElement(this.options.start);this.current= this.options.current;this.bound={rotate:this.rotate.bind(this)};Fx.implement({cancel:function(){this.callChain()||this.fireEvent("chainComplete",this.subject);if(this.stopTimer())this.onCancel();return this}});this.options.direction=="horizontal"?(this.direction="margin-left",this.size=this.items[0].getWidth(),this.visible=Math.round(this.holder.getWidth()/this.size)):(this.direction="margin-top",this.size=this.items[0].getHeight(),this.visible=Math.round(this.holder.getHeight()/this.size));if(this.items.length<= this.visible)return this.next&&this.next.addClass(this.options.nextDisableClass).addEvent("click",function(){return!1}),this.prev&&this.prev.addClass(this.options.prevDisableClass).addEvent("click",function(){return!1}),this.stop&&this.stop.addEvent("click",function(){return!1}),this.start&&this.start.addEvent("click",function(){return!1}),this.gallery.addClass("stopped no-active"),this.fireEvent("start",this.current,this.visible,this.items.length,this.items[this.current]),!1;this.options.steps=this.options.steps> this.visible?this.visible:this.options.steps;this.options.duration=this.options.duration<1E3?1E3:this.options.duration;this.options.speed=this.options.speed>6E3?6E3:this.options.speed;if(this.options.speed>this.options.duration)this.options.speed=this.options.duration;this.fx=new Fx.Tween(this.itemsParent,{property:this.direction,duration:this.options.speed,transition:this.options.transition,link:"cancel",fps:100});this.options.random&&this.shuffle();this.getInitialCurrent();if(this.options.mode== "circle"){for(;this.items.length<this.options.steps+this.visible;)this.itemsParent.innerHTML+=this.itemsParent.innerHTML,this.items=this.itemsParent.getElements(this.options.elements);for(var c=0;c<this.current;c++)this.items[c].inject(this.itemsParent,"bottom");this.options.paging=!1}else this.options.paging&&this.createPaging(),this.play(!1);this.next&&this.next.addEvent("click",function(){this.nextSlide();return!1}.bind(this));this.prev&&this.prev.addEvent("click",function(){this.prevSlide();return!1}.bind(this)); this.options.autoplay||this.options.autoplayOpposite?this.timer=this.bound.rotate.delay(this.options.duration):this.gallery.addClass("stopped");this.start&&this.start.addEvent("click",function(){clearTimeout(this.timer);this.gallery.removeClass("stopped");this.timer=this.bound.rotate.delay(this.options.duration);return!1}.bind(this));this.stop&&this.stop.addEvent("click",function(){this.gallery.addClass("stopped");clearTimeout(this.timer);return!1}.bind(this));this.options.stopOnHover&&(this.gallery.addEvent("mouseenter", function(){clearTimeout(this.timer)}.bind(this)),this.gallery.addEvent("mouseleave",function(){if(!this.gallery.hasClass("stopped"))clearTimeout(this.timer),this.timer=this.bound.rotate.delay(this.options.duration)}.bind(this)));this.fireEvent("start",this.current,this.visible,this.items.length,this.items[this.current])},getInitialCurrent:function(){var a=this.items.get("class").indexOf(this.options.currentClass);if(a!=-1)this.current=a;else if(this.current>this.items.length-1)this.current=this.items.length- 1;else if(this.current<0)this.current=0;if(this.options.mode!="circle"&&this.visible+this.current>=this.items.length)this.current=this.items.length-this.visible;return this},rotate:function(){this.options.autoplayOpposite?this.prevSlide():this.nextSlide();this.timer=this.bound.rotate.delay(this.options.duration);return this},play:function(a){this.options.mode=="line"&&this.sidesChecking();a?this.fx.start(-this.current*this.size):this.fx.set(-this.current*this.size);this.options.paging&&this.setActivePage(); this.fireEvent("play",this.current,this.visible,this.items.length,this.items[this.current]);return this},nextSlide:function(){if(this.options.mode!="circle"){if(this.visible+this.current>=this.items.length){if(this.options.mode=="callback")this.current=0}else this.visible+this.current+this.options.steps>=this.items.length?this.current=this.items.length-this.visible:this.current+=this.options.steps;this.play(!0)}else{var a=this.current;if((this.current+=this.options.steps)>=this.items.length)this.current-= this.items.length;this.fx.start(-this.items[a].getWidth()*this.options.steps).chain(function(){for(var b=0;b<this.options.steps;b++)a>=this.items.length&&(a=0),this.items[a++].inject(this.itemsParent,"bottom");this.fx.set(0)}.bind(this));this.fireEvent("play",this.current,this.visible,this.items.length,this.items[this.current])}return this},prevSlide:function(){if(this.options.mode!="circle"){if(this.current<=0){if(this.options.mode=="callback")this.current=this.items.length-this.visible}else this.current- this.options.steps<=0?this.current=0:this.current-=this.options.steps;this.play(!0)}else{if(this.current-1<0)this.current=this.items.length;for(var a=this.current,b=0;b<this.options.steps;b++){if(this.current-1<0)this.current=this.items.length;this.items[--this.current].inject(this.itemsParent,"top")}this.fx.set(-this.items[--a].getWidth()*this.options.steps).start(0);this.fireEvent("play",this.current,this.visible,this.items.length,this.items[this.current])}return this},sidesChecking:function(){this.next.removeClass(this.options.nextDisableClass); this.prev.removeClass(this.options.prevDisableClass);this.visible+this.current>=this.items.length?this.next.addClass(this.options.nextDisableClass):this.current==0&&this.prev.addClass(this.options.prevDisableClass);return this},createPaging:function(){this.paging=new Element("ul");var a=this.gallery.getElement(this.options.pagingHolder);a!=null?this.paging.injectInside(a):this.paging.injectInside(this.gallery).addClass("paging");for(var b=Math.ceil((this.items.length-this.visible)/this.options.steps)+ 1,a="",c=0;c<b;c++)a+='<li><a href="#">'+parseInt(c+1)+"</a></li>";this.paging=this.paging.set("html",a).getElements("a");this.paging.each(function(a,c){a.addEvent(this.options.pagingEvent,function(){this.current=c<b-1?c*this.options.steps:this.items.length-this.visible;this.play(!0);return!1}.bind(this))}.bind(this));return this},setActivePage:function(){this.paging.removeClass("active")[Math.ceil(this.current/this.options.steps)].addClass("active");return this},shuffle:function(){var a="";this.items.sort(function(){return 0.5- Math.random()}).each(function(b){a+=(new Element("div")).adopt(b).get("html")});this.items=this.itemsParent.set("html",a).getElements(this.options.elements);return this}}),fadeGallery=new Class({Extends:slideGallery,initialize:function(a,b){if(b.mode=="circle")b.mode="callback";this.parent(a,b);this.fxFade=[];this.items.each(function(a,b){this.fxFade[b]=new Fx.Tween(a,{property:"opacity",duration:this.options.speed,transition:this.options.transition,link:"cancel"});this.fxFade[b].set(0)}.bind(this)); this.play(!1)},play:function(a){if(this.previous==null)return this.previous=0,!1;this.options.mode=="line"&&this.sidesChecking();a?(this.fxFade[this.previous].start(0),this.fxFade[this.current].start(1)):(this.fxFade[this.previous].set(0),this.fxFade[this.current].set(1));this.previous=this.current;this.options.paging&&this.setActivePage();this.fireEvent("play",this.current,this.visible,this.items.length,this.items[this.current])}});
