//Script: Scrollbar 0.9.1
var ScrollBar = new Class({
  
  Extends: Slider,
 
  options: {
    fx: {}
  },
 
  initialize: function(scroller, slider, knob, options){
    this.knob = $(knob).set('tween', options.fx);
    this.slider = $(slider);
    this.scroller = $(scroller);
    this.scrollElement = this.scroller.getFirst();
    this.parent(this.slider, this.knob, options);
    this.steps = this.scrollElement.getSize()[this.axis] - this.scroller.getSize()[this.axis];
    this.scroll = new Fx.Scroll(this.scroller, options.fx);
	// - test 
	//this.addEvent('complete', function(event){
    //  if (event.target !== knob) this.move();
    //});
    this.ratio = this.steps / (this.slider.getSize()[this.axis] - this.knob.getSize()[this.axis]);
  },
 
  set: function(position){
    if($type(position) === 'element') position = position.getPosition(this.scrollElement)[this.axis] / this.ratio;
    position = position.limit(-this.options.offset, this.full -this.options.offset);
    this.move(position * this.ratio);
    this.knob.tween(this.property, position)
	//alert('position ' + position );
	
  },
 
  move: function(position){
    if (this.options.mode === 'vertical') this.scroll.cancel().start(0, $chk(position) ? position : this.step);
    else this.scroll.cancel().start($chk(position) ? position : this.step);
  },
 
  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(event){
    if (event.target === this.knob) {
      this.knob.get('tween').cancel();
      return;
    }
    var position = event.page[this.axis] - this.element.getPosition()[this.axis] - this.half;
    position = position.limit(-this.options.offset, this.full -this.options.offset);
    this.set(position);
  }
 
});