var Scroller = {
  animation: false,
  boxWidth: 500,
  boxCount: 5,
  
  scrollLeft: function() {
    if (Scroller.animation) return;
    if (! $('boxes')) return;
    if (Position.positionedOffset($('boxes'))[0] >= Position.positionedOffset($('scroller'))[0]) {
      Scroller.animation = true;
      new Effect.Move('boxes', {
        x: -((Scroller.boxCount-1)*Scroller.boxWidth),
        afterFinish: function(){
          Scroller.animation = false;
        }
      });
      return;
    }

    Scroller.animation = true;
    new Effect.Move('boxes', {
      x: Scroller.boxWidth,
      afterFinish: function(){
        Scroller.animation = false;
      }
    });
  },

  scrollRight: function() {
    if (Scroller.animation) return;
    if (! $('boxes')) return;
    if (Position.positionedOffset($('boxes'))[0] <= (Position.positionedOffset($('scroller'))[0])-(Scroller.boxCount-1)*Scroller.boxWidth) {
      Scroller.animation = true;
      new Effect.Move('boxes', {
        x: ((Scroller.boxCount-1)*Scroller.boxWidth),
        afterFinish: function(){
          Scroller.animation = false;
        }
      });
      return;
    }

    Scroller.animation = true;
    new Effect.Move('boxes', {
      x: -(Scroller.boxWidth),
      afterFinish: function(){
        Scroller.animation = false;
      }
    });
  }
}
