/*
name: Scrollbar
version: 0.9.7
copyright: Enrique Erne (http://mild.ch)
license: MIT License
authors:
- Enrique Erne
*/

var ScrollBar=new Class({Extends:Slider,options:{scroll:{wheelStops:false},slider:{mode:'horizontal',wheel:true},knob:{}},initialize:function(b,c,d,e){this.knob=document.id(d).set('tween',e.knob);this.slider=document.id(c);this.scroller=document.id(b);this.scrollElement=this.scroller.getFirst();this.parent(this.slider,this.knob,$extend(this.options.slider,e.slider));this.steps=this.scrollElement.getSize()[this.axis]-this.scroller.getSize()[this.axis];this.scroll=new Fx.Scroll(this.scroller,$extend(this.options.scroll,e.scroll));this.scroller.addEvent('mousewheel',function(a){this.element.fireEvent('mousewheel',a)}.bind(this));this.ratio=this.steps/(this.slider.getSize()[this.axis]-this.knob.getSize()[this.axis])},move2:function(a){this.set(this.knob.getPosition(this.slider)[this.axis]+a)},set:function(a){if($type(a)==='element')a=a.getPosition(this.scrollElement)[this.axis]/this.ratio;a=a.limit(-this.options.offset,this.full-this.options.offset);this.move(a*this.ratio);this.knob.tween(this.property,a).get('tween').chain(function(){this.fireEvent('complete',Math.round(a*this.ratio)+'')}.bind(this))},move:function(a){var b=$chk(a)?a:this.step;if(this.options.mode==='vertical')this.scroll.cancel().start(0,b);else this.scroll.cancel().start(b,0)},draggedKnob:function(){this.parent();if(this.options.mode==='vertical')this.scroll.cancel().set(0,this.step);else this.scroll.cancel().set(this.step)},clickedElement:function(a){if(a.target===this.knob){this.knob.get('tween').cancel();return}var b=a.page[this.axis]-this.element.getPosition()[this.axis]-this.half;b=b.limit(-this.options.offset,this.full-this.options.offset);this.set(b)},scrolledElement:function(a){var b=(this.options.mode=='horizontal')?(a.wheel<0):(a.wheel>0);this.move2(b?-this.stepSize*100:this.stepSize*100);a.stop()}});
