/*  Control.Scroller, version 1.1
 *  Copyright (c) 2008, Glenn Nilsson <glenn.nilsson@gmail.com>
 *  Control.Scroller is distributed under the terms of an Creative Commons Attribution license
 *  For details, see: <http://wailqill.com/projects/scroller/>*/
Control.Scroller=Class.create();Control.Scroller.scrollers=[];
Control.Scroller.prototype={initialize:function(a,d,e,f){this.id="scroller";this.content=$(a);this.handle=$(d);this.track=$(e);this.currentValue=0;this.options=Object.extend({axis:"vertical",onChange:function(b){c.updateView(b)},onSlide:function(b){c.updateView(b)}},f);var c=this;this.options=Object.extend({scrollOnHover:false,visibleHeight:this.isVertical()?300:this.content.offsetHeight,visibleWidth:this.isVertical()?this.content.offsetWidth:300,delta:20,autoHide:true,interval:100},this.options);
this.maxValue=this.isVertical()?this.content.offsetHeight-this.options.visibleHeight-this.handle.offsetHeight:this.content.offsetWidth-this.options.visibleWidth-this.handle.offsetWidth;this.options.range=$R(0,this.maxValue);this.buttons={up:$(this.options.up),down:$(this.options.down)};if(this.isVertical()&&this.content.offsetHeight<=this.options.visibleHeight||!this.isVertical()&&this.content.offsetWidth<=this.options.visibleWidth)this.options.autoHide&&[this.track,this.handle,this.buttons.up,this.buttons.down].invoke("hide");
else{this.content.style.height=this.options.visibleHeight+"px";this.eventMouseAction=this.buttonAction.bindAsEventListener(this);$H(this.buttons).values().each(function(b){if(c.options.scrollOnHover){Event.observe(b,"mouseover",c.eventMouseAction);Event.observe(b,"mouseout",c.eventMouseAction)}else{Event.observe(b,"mousedown",c.eventMouseAction);Event.observe(b,"mouseup",c.eventMouseAction)}});this.slider=new Control.Slider(this.handle,this.track,this.options)}},isVertical:function(){return this.options.axis==
"vertical"},buttonAction:function(a){this.multiplier=Event.element(a)==this.buttons.up?-1:1;switch(a.type){case "mouseover":case "mousedown":this.scroll();var d=this;this.timer=setInterval(function(){d.scroll()},d.options.interval);break;case "mouseout":case "mouseup":clearTimeout(this.timer);break}},scroll:function(){this.slider.setValue(this.currentValue+this.options.delta*this.multiplier,0)},updateView:function(a){this.currentValue=a;if(this.options.axis=="vertical"){this.content.style.marginTop=
-this.currentValue+"px";this.content.style.height=this.options.visibleHeight+this.currentValue+"px";this.content.style.clip="rect("+a+"px "+this.options.visibleWidth+"px "+(this.options.visibleHeight+this.currentValue)+"px 0px)"}else{this.content.style.marginLeft=-this.currentValue+"px";this.content.style.clip="rect(0 "+(this.options.visibleHeight+this.currentValue)+"px "+this.options.visibleHeight+"px "+a+"px)"}(this.options.onScroll||Prototype.emptyFunction)(a,this)}};