Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(element,options){this.element=this.subject=document.id(element);this.parent(options);var cancel=this.cancel.bind(this,false);if($type(this.element)!='element')this.element=document.id(this.element.getDocument().body);var stopper=this.element;if(this.options.wheelStops){this.addEvent('start',function(){stopper.addEvent('mousewheel',cancel);},true);this.addEvent('complete',function(){stopper.removeEvent('mousewheel',cancel);},true);}},set:function(){var now=Array.flatten(arguments);this.element.scrollTo(now[0],now[1]);},compute:function(from,to,delta){return[0,1].map(function(i){return Fx.compute(from[i],to[i],delta);});},start:function(x,y){if(!this.check(x,y))return this;var offsetSize=this.element.getSize(),scrollSize=this.element.getScrollSize();var scroll=this.element.getScroll(),values={x:x,y:y};for(var z in values){var max=scrollSize[z]-offsetSize[z];if($chk(values[z]))values[z]=($type(values[z])=='number')?values[z].limit(0,max):max;else values[z]=scroll[z];values[z]+=this.options.offset[z];}
return this.parent([scroll.x,scroll.y],[values.x,values.y]);},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start('right',false);},toBottom:function(){return this.start(false,'bottom');},toElement:function(el){var position=document.id(el).getPosition(this.element);return this.start(position.x,position.y);},scrollIntoView:function(el,axes,offset){axes=axes?$splat(axes):['x','y'];var to={};el=document.id(el);var pos=el.getPosition(this.element);var size=el.getSize();var scroll=this.element.getScroll();var containerSize=this.element.getSize();var edge={x:pos.x+size.x,y:pos.y+size.y};['x','y'].each(function(axis){if(axes.contains(axis)){if(edge[axis]>scroll[axis]+containerSize[axis])to[axis]=edge[axis]-containerSize[axis];if(pos[axis]<scroll[axis])to[axis]=pos[axis];}
if(to[axis]==null)to[axis]=scroll[axis];if(offset&&offset[axis])to[axis]=to[axis]+offset[axis];},this);if(to.x!=scroll.x||to.y!=scroll.y)this.start(to.x,to.y);return this;}});;Fx.Scroll.Carousel=new Class({Extends:Fx.Scroll,options:{mode:'horizontal',childSelector:false,loopOnScrollEnd:true},initialize:function(element,options){this.parent(element,options);this.cacheElements();this.currentIndex=0;},cacheElements:function(){var cs=this.options.childSelector;if(cs){els=this.element.getElements(cs);}else if(this.options.mode=='horizontal'){els=this.element.getElements(':first-child > *');}else{els=this.element.getChildren();}
this.elements=els;return this;},toNext:function(){if(this.checkLink())return this;this.currentIndex=this.getNextIndex();this.toElement(this.elements[this.currentIndex]);this.fireEvent('next');return this;},toPrevious:function(){if(this.checkLink())return this;this.currentIndex=this.getPreviousIndex();this.toElement(this.elements[this.currentIndex]);this.fireEvent('previous');return this;},getNextIndex:function(){this.currentIndex++;if(this.currentIndex==7||this.checkScroll()){this.fireEvent('loop');this.fireEvent('nextLoop');return 0;}else{return this.currentIndex;};},getPreviousIndex:function(){this.currentIndex--;var check=this.checkScroll();if(this.currentIndex<0||check){this.fireEvent('loop');this.fireEvent('previousLoop');return(check)?this.getOffsetIndex():this.elements.length-1;}else{return this.currentIndex;}},getOffsetIndex:function(){var visible=(this.options.mode=='horizontal')?this.element.getStyle('width').toInt()/this.elements[0].getStyle('width').toInt():this.element.getStyle('height').toInt()/this.elements[0].getStyle('height').toInt();return this.currentIndex+1-visible;},checkLink:function(){return(this.timer&&this.options.link=='ignore');},checkScroll:function(){if(!this.options.loopOnScrollEnd)return false;if(this.options.mode=='horizontal'){var scroll=this.element.getScroll().x;var total=this.element.getScrollSize().x-this.element.getSize().x;}else{var scroll=this.element.getScroll().y;var total=this.element.getScrollSize().y-this.element.getSize().y;}
return(scroll==total);},getCurrent:function(){return this.elements[this.currentIndex];}});;var horizontal;var bottom;var periodical;window.addEvent('domready',function(){bottom=new Fx.Scroll.Carousel('bottom',{mode:'horizontal'});bottom.options.loopOnScrollEnd=true;var fx=function(){bottom.toNext();}
periodical=fx.periodical(5000);});
