var Slider = new Class(
{
  initialize: function(boxId, slideWidth, slideOffset, perPage)
  { 
    this.box = $(boxId);
    this.slides = this.box.getChildren('div');
    this.slideWidth = slideWidth;
    this.slideOffset = slideOffset;
    this.perPage = perPage;
    this.fx = new Fx.Tween(boxId, {link: 'cancel'}); 
    this.current = 0;
    this.nPages = Math.ceil(this.slides.length / this.perPage);
    
    this.box.setStyle('width', (this.slides.length + 1) * (this.slideWidth + this.slideOffset));
    
    this.slides.each(function(item, i)
    {
      item.setStyle('margin-right', this.slideOffset);
      item.setStyle('width', this.slideWidth);
    }, this);
  }, 
  
  getPage: function()
  {
    return Math.floor(this.current / this.perPage);
  }, 

  slideTo: function(index) 
  {
    if (index < 0)
      index = 0;
    
    var maxIndex = this.slides.length - this.perPage;
    
    if (index > maxIndex)
      index = maxIndex;
    
    var left = -index * (this.slideWidth + this.slideOffset);
    this.fx.start('margin-left', left);
    this.current = index;
  }, 
  
  slideToPage: function(index) 
  {
    this.slideTo(index * this.perPage);
  }, 
  
  slideLeft: function()
  {
    this.slideTo(this.current - 1);
  }, 
  
  slideRight: function()
  {
    this.slideTo(this.current + 1);
  }, 
  
  slidePageLeft: function()
  {
    this.slideToPage(this.getPage() - 1);
  }, 
  
  slidePageRight: function()
  {
    this.slideToPage(this.getPage() + 1);
  }
});