function Slider(_sSliderId, _iSlideWidth, _sAlign, _iVisibleSlideCount, _iSliderSpeed) {
  this.objSlider = document.getElementById(_sSliderId);
  this.iSlideWidth = _iSlideWidth;
  this.iSlideCount = 0;
  this.iVisibleSlideCount = _iVisibleSlideCount || 3;
  this.iSliderSpeed = _iSliderSpeed || 5;
  this.iActualSliderSpeed = Math.round(this.iSlideWidth / this.iSliderSpeed);
  this.sAlign = _sAlign || "center";
  this.timer = null;
  this.bIsSliding = false;
  this.iVisibleSliderWidth = this.iVisibleSlideCount * this.iSlideWidth;
  this.iActualSliderWidth = 0;
  var iCenter = Math.floor(this.iVisibleSlideCount / 2);
  if (this.sAlign == "left") {
    this.iCurrentSlide = iCenter;
    this.iStartPos = 0;
    this.iEndPos = this.iVisibleSliderWidth - this.iSlideWidth;
    this.objSlider.style.left = '0px';
  } else if (this.sAlign == "right") {
    this.iCurrentSlide = -1 * iCenter;
    this.iStartPos = 0;
    this.iEndPos = this.iVisibleSliderWidth - this.iSlideWidth;
    this.objSlider.style.left = this.iSlideWidth * (this.iVisibleSlideCount - 1) + 'px';
  } else {
    this.iCurrentSlide = 0;
    this.iStartPos = this.iSlideWidth * iCenter;
    this.iEndPos = this.iStartPos;
    this.objSlider.style.left = this.iStartPos + 'px';
  }
}
Slider.prototype = new Object();
Slider.prototype.addSlide = function() {
  this.iSlideCount++;
  this.iActualSliderWidth = (this.iSlideCount + this.iVisibleSlideCount - 1) * this.iSlideWidth;
  if (this.iSlideCount > this.iVisibleSlideCount) {
    this.objSlider.style.width = this.iVisibleSlideCount * this.iSlideWidth + 'px';
  } else {
    this.objSlider.style.width = this.iSlideCount * this.iSlideWidth + 'px';
  }
}
Slider.prototype.getCurrent = function() {
  return this.iCurrentSlide;
}
Slider.prototype.getCount = function() {
  return this.iSlideCount;
}
Slider.prototype.slideTo = function(_iSlide) {
  if (_iSlide != null) {
    if (!this.bIsSliding && _iSlide != this.iCurrentSlide) {
      this.bIsSliding = true;
      var iDelta = _iSlide - this.iCurrentSlide;
      clearInterval(this.timer);
      _iSlideCount = 1;
      if (iDelta > 0) {
        this.timer = setInterval(function(_this){return function(){_this.slideLeft.call(_this, iDelta)}}(this), this.iSliderSpeed * 10);
      }
      else if (iDelta < 0) {
        this.timer = setInterval(function(_this){return function(){_this.slideRight.call(_this, -1 * iDelta)}}(this), this.iSliderSpeed * 10);
      }
    }
  }
}
Slider.prototype.slideLeft = function(_count) {
  if ((-1 * parseInt(this.objSlider.style.left)) + this.iVisibleSliderWidth + this.iEndPos < this.iActualSliderWidth) {
    this.objSlider.style.left = (parseInt(this.objSlider.style.left) - this.iActualSliderSpeed) + "px";
    if (parseInt(this.objSlider.style.left) % this.iSlideWidth == 0) {
      if (_iSlideCount >= _count) {
        clearInterval(this.timer);
        ++this.iCurrentSlide;
        this.bIsSliding = false;
        return;
      } else {
        _iSlideCount++;
        this.iCurrentSlide++;
      }
    }
  } else {
    clearInterval(this.timer);
    this.bIsSliding = false;
    return;
  }
}
Slider.prototype.slideRight = function(_count) {
  if (parseInt(this.objSlider.style.left) < this.iStartPos) {
    this.objSlider.style.left = (parseInt(this.objSlider.style.left) + this.iActualSliderSpeed) + "px";
    if (parseInt(this.objSlider.style.left) % this.iSlideWidth == 0) {
      if (_iSlideCount >= _count) {
        clearInterval(this.timer);
        --this.iCurrentSlide;
        this.bIsSliding = false;
        return;
      } else {
        _iSlideCount++;
        this.iCurrentSlide--;
      }
    }
  } else {
    clearInterval(this.timer);
    this.bIsSliding = false;
    return;
  }
}

