var CartScroller = new Class({

  ELEMENT_IN_PAGE: 4,
  ELEMENT_SIZE: 39,
  elements: 0,
  actual_page: 0,
  scrollDuration: 600,
  
  
  
  initialize: function(container,push_left,push_right,fn_getelements) {
    this.elements = fn_getelements;
    this.push_left = $(push_left);
    this.push_right = $(push_right);
    
    this.push_left.addEvent('click',function(e){
      this.change(-1); 
    }.bind(this));
    
    this.push_right.addEvent('click',function(e){
      this.change(+1); 
    }.bind(this));
    
    this.scroller = new Fx.Scroll($(container),{
                          transition: Fx.Transitions.Sine.easeInOut,
                          duration: this.scrollDuration,
                          wait: false,
                          onComplete: function(){this.checkPush();}.bind(this)
                          });
    this.scroller.toLeft();
    this.checkPush();
  },
  
  
  change: function(relative){
    var temp = this.actual_page + relative;
    if(temp < 0 || temp > this.elements().length/this.ELEMENT_IN_PAGE)
      return;
      
    this.scroller.scrollTo(temp * this.ELEMENT_IN_PAGE * this.ELEMENT_SIZE,0);
    this.actual_page = temp;
  },
  
  
  checkPush: function() {
    if(this.actual_page == 0) 
      this.push_left.addClass('unactive');
    else
      this.push_left.removeClass('unactive');
      
    if(this.actual_page == Math.floor(this.elements().length/this.ELEMENT_IN_PAGE))
      this.push_right.addClass('unactive');
    else
      this.push_right.removeClass('unactive');
  }

});

CartScroller.implement(new Events);

