function SliderBar(callBack, orientation) {
  this.id = 'slide-bar-'+ ++ids;
  this.callBack = callBack;
  this.orientation = orientation || 'x';
};

SliderBar.prototype = new ObjectEvents();

SliderBar.prototype.build = function() {
  var slider = make_el('SPAN', {unselectable:true, id:this.id, className:'slider'}, this.fragDoc);
  make_el('SPAN', {unselectable:true, className:'slider-bar'}, slider);
  this.addEvent(slider,'mousedown', 'mouseDown');
  return slider;
};

SliderBar.prototype.getSlider = function() {
  return get_by_id(this.id) || this.build();
};

SliderBar.prototype.getSliderBar = function() {
  return get_by_id(this.id).firstChild;
};

SliderBar.prototype.mouseDown = function(e) {
  preventDefault(e);
  this.dragId = this.addEvent(document,'mousemove','drag');
  this.dragEndId = this.addEvent(document,'mouseup','dragEnd');
  this.drag(e);
};

SliderBar.prototype.drag = function(e) {
  if(!this.sliderPos) this.sliderPos = FindXY(this.getSlider())[this.orientation];
  this.callCallBack(FindMouseXY(e)[this.orientation]- this.sliderPos);
};

SliderBar.prototype.dragEnd = function() {
  this.removeEvent(document, this.dragId);
  this.removeEvent(document, this.dragEndId);
  this.sliderPos = this.sliderSize = null;
};

SliderBar.prototype.posSliderBar = function(val) {
  if(this.orientation == 'x')
    this.getSliderBar().style.left = val +'px';
  else
    this.getSliderBar().style.top = val +'px';
};

SliderBar.prototype.callCallBack = function(val) {
  val = this.normalizeValue(val);
  this.posSliderBar(val);
  this.callBack(val/this.getSliderSize());
};

SliderBar.prototype.normalizeValue = function(val) {
  var sliderSize = this.getSliderSize();
  if(val < 0) return 0;
  else if(val >= sliderSize)
  return sliderSize;
  else
  return val;
};

SliderBar.prototype.setValue = function(val) {
  val *= this.getSliderSize();
  this.posSliderBar(val);
};

SliderBar.prototype.getSliderSize = function() {
  if ( !this.sliderSize ) {
    if(this.orientation == 'x')
      this.sliderSize = this.getSlider().clientWidth;
    else
      this.sliderSize = this.getSlider().clientHeight;
  };
  return this.sliderSize;
};

