msImageScroller = Class.create();
msImageScroller.prototype =
{
  initialize: function (Options)
  {
    
    this.Options = {
      ContainerSize: 10000,
      ImageSize: 100,
      DisplaySize: 500
    };
    
    this.Scrolling = false;
    this.Hovering = false;
    
    Object.extend(this.Options, Options || {});
    
    $('image-inner-container').style.width = this.Options.DisplaySize + 'px';
  },

  moveToPrevious: function()
  {
    var scroller = this;
    
    if ($('image-inner-container').style.left.substr(0, $('image-inner-container').style.left.length - 2 ) < 0) {
      
      if (!this.Scrolling) {
        new Effect.Move('image-inner-container', { 
          x: this.Options.ImageSize, 
          y: 0, 
          duration: 0.2,
          fps: 50,
          transition: Effect.Transitions.linear,
          beforeStart: function()
          {
            scroller.Scrolling = true;
          },
          afterFinish: function()
          {
            scroller.Scrolling = false;
            scroller.start('left', true);
          }
        });
      }
    }
  },

  moveToNext: function()
  {
    var x = $('image-inner-container').style.left.substr(0, $('image-inner-container').style.left.length - 2 );
    
    var scroller = this;
    
    if (x > this.Options.ContainerSize) {
      if (!this.Scrolling) {
        new Effect.Move('image-inner-container', { 
          x: this.Options.ImageSize * -1, 
          y: 0, 
          duration: 0.2,
          fps: 50,
          transition: Effect.Transitions.linear,
          beforeStart: function()
          {
            scroller.Scrolling = true;
          },
          afterFinish: function()
          {
            scroller.Scrolling = false;
            scroller.start('right', true);
          }
        });
      }
    }
  },
  
  start: function (direction, loop)
  {
    
    if (!loop) {
      // only call this once on first move over
      this.Hovering = true;
    }
    
    if (this.Hovering) {
      switch(direction) {
        case 'left':
          this.moveToPrevious();
          break;
          
        case 'right':
          this.moveToNext();
          break;
      }
    }
  },
  
  stop: function()
  {
    this.Hovering = false;
  }
  
}
