(function(){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);if(typeOf(this.element)!="element"){this.element=document.id(this.element.getDocument().body)}if(this.options.wheelStops){var stopper=this.element,cancel=this.cancel.pass(false,this);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);if(Browser.firefox){now=[Math.round(now[0]),Math.round(now[1])]}this.element.scrollTo(now[0],now[1]);return this},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 scroll=this.element.getScroll();return this.parent([scroll.x,scroll.y],[x,y])},calculateScroll:function(x,y){var element=this.element,scrollSize=element.getScrollSize(),scroll=element.getScroll(),size=element.getSize(),offset=this.options.offset,values={x:x,y:y};for(var z in values){if(!values[z]&&values[z]!==0){values[z]=scroll[z]}if(typeOf(values[z])!="number"){values[z]=scrollSize[z]-size[z]}values[z]+=offset[z]}return[values.x,values.y]},toTop:function(){return this.start.apply(this,this.calculateScroll(false,0))},toLeft:function(){return this.start.apply(this,this.calculateScroll(0,false))},toRight:function(){return this.start.apply(this,this.calculateScroll("right",false))},toBottom:function(){return this.start.apply(this,this.calculateScroll(false,"bottom"))},toElement:function(el,axes){axes=axes?Array.from(axes):["x","y"];var scroll=isBody(this.element)?{x:0,y:0}:this.element.getScroll();var position=Object.map(document.id(el).getPosition(this.element),function(value,axis){return axes.contains(axis)?value+scroll[axis]:false});return this.start.apply(this,this.calculateScroll(position.x,position.y))},toElementEdge:function(el,axes,offset){axes=axes?Array.from(axes):["x","y"];el=document.id(el);var to={},position=el.getPosition(this.element),size=el.getSize(),scroll=this.element.getScroll(),containerSize=this.element.getSize(),edge={x:position.x+size.x,y:position.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(position[axis]<scroll[axis]){to[axis]=position[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},toElementCenter:function(el,axes,offset){axes=axes?Array.from(axes):["x","y"];el=document.id(el);var to={},position=el.getPosition(this.element),size=el.getSize(),scroll=this.element.getScroll(),containerSize=this.element.getSize();["x","y"].each(function(axis){if(axes.contains(axis)){to[axis]=position[axis]-(containerSize[axis]-size[axis])/2}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.implement({scrollToCenter:function(){return this.toElementCenter.apply(this,arguments)},scrollIntoView:function(){return this.toElementEdge.apply(this,arguments)}});function isBody(element){return(/^(?:body|html)$/i).test(element.tagName)}})();