var DimpSlider=Class.create({value:0,initialize:function(a,b){this.track=$(a);this.options=Object.extend({buttonclass:null,cursorclass:null,pagesize:0,totalsize:0},b||{});this.handle=new Element("DIV",{className:this.options.cursorclass}).makePositioned();this.track.insert(this.handle);if(this.options.buttonclass){this.sbup=new Element("DIV",{className:this.options.buttonclass.up});this.sbdown=new Element("DIV",{className:this.options.buttonclass.down}).makePositioned();this.handle.insert({before:this.sbup,after:this.sbdown});[this.sbup,this.sbdown].invoke("observe","mousedown",this._arrowClick.bindAsEventListener(this))}this.sbdownsize=this.sbupsize=this.value=0;this.active=this.dragging=false;if(this._showScroll()){this._initScroll()}this.eventMU=this._endDrag.bindAsEventListener(this);this.eventMM=this._update.bindAsEventListener(this);[this.handle,this.track].invoke("observe","mousedown",this._startDrag.bindAsEventListener(this))},_initScroll:function(){if(this.init){return false}this.init=true;this.track.show();if(this.sbup){this.sbupsize=this.sbup.offsetHeight;this.sbdownsize=this.sbdown.offsetHeight}this._updateHandleLength();return true},_startDrag:function(b){if(!b.isLeftClick()){return}var a,c=this.handle.cumulativeOffset();if(b.element()==this.track){a=(b.pointerY()<c[1])?-1:1;this.setScrollPosition(this.getValue()-a+(this.options.pagesize*a))}else{this.curroffsets=this.track.cumulativeOffset();this.offsetY=b.pointerY()-c[1]+this.sbupsize;this.active=true;document.observe("mouseup",this.eventMU);document.observe("mousemove",this.eventMM)}b.stop()},_update:function(a){if(this.active){this.dragging=true;this._setScrollPosition("px",Math.min(Math.max(0,a.pointerY()-this.offsetY-this.curroffsets[1]),this.handletop));if(this.options.onSlide){this.options.onSlide()}if(Prototype.Browser.WebKit){window.scrollBy(0,0)}a.stop()}},_endDrag:function(a){if(this.active&&this.dragging){this._updateFinished();a.stop();document.stopObserving("mouseup",this.eventMU);document.stopObserving("mousemove",this.eventMM)}this.active=this.dragging=false},_arrowClick:function(a){this.setScrollPosition(this.getValue()+((a.element()==this.sbup)?-1:1))},_updateFinished:function(){if(this.options.onChange){this.options.onChange()}},updateHandleLength:function(b,a){this.options.pagesize=b;this.options.totalsize=a;if(!this._showScroll()){this.value=0;this.track.hide();return}if(!this._initScroll()){this.track.show();this._updateHandleLength()}},_updateHandleLength:function(){var a=this.track.offsetHeight-this.sbupsize-this.sbdownsize;this.handle.setStyle({height:Math.max(10,Math.round((this.options.pagesize/this.options.totalsize)*a))+"px"});this.handletop=a-this.handle.offsetHeight;if(this.sbdown){this.sbdown.setStyle({top:this.handletop+"px"})}this._setScrollPosition("val",this.getValue())},getValue:function(){return this.value},setScrollPosition:function(b){if(this._showScroll()){var a=this.getValue();this._setScrollPosition("val",b);if(a!=this.getValue()){this._updateFinished()}}},_setScrollPosition:function(a,b){this.value=(a=="val")?Math.min(Math.max(0,b),this.options.totalsize-this.options.pagesize):Math.max(0,Math.round(Math.min(b,this.handletop)/this.handletop*(this.options.totalsize-this.options.pagesize)));this.handlevalue=(a=="px")?b:Math.round(this.getValue()/(this.options.totalsize-this.options.pagesize)*this.handletop);this.handle.setStyle({top:this.handlevalue+"px"})},_showScroll:function(){return(this.options.pagesize<this.options.totalsize)}});