
function autoScroller(containerId, scrollDistance, scrollDirection)
{
  this.smoothMovement  = new SmoothMovement(0, 0);
  this.containerId     = containerId;
  this.scrollDistance  = scrollDistance;
  this.scrollDirection = scrollDirection;
};

autoScroller.prototype.init = function()
{
  this.divs = new Array();
  
  var parent = document.getElementById(this.containerId);
  if (!parent)
    return;
    
  var child = parent.firstChild;
  var leftmost = null;
  
  while (child)
  {
    if (child.nodeType == 1)
    {
      this.divs.push(child);
    }
    child = child.nextSibling;
  }
  
  if (this.divs.length < 2)
    return;
  
  window.setInterval(
    this.createTriggerClosure(),
    8000);
};

autoScroller.prototype.createTriggerClosure = function()
{
  var me = this;
  
  return function() {me.trigger();};
};

autoScroller.prototype.trigger = function()
{
  this.smoothMovement.target += this.scrollDistance;
  this.smoothMovement.animate(20, this.createUpdateClosure(), function(){});
};

autoScroller.prototype.createUpdateClosure = function()
{
  var me = this;
  
  return function() {me.update();};
};

autoScroller.prototype.update = function()
{
  while (this.smoothMovement.position >= this.scrollDistance)
  {
    var leftmost = this.divs.shift();
    
    if (this.scrollDirection == 0)
      leftmost.style.left = this.scrollDistance + 'px';
    else
      leftmost.style.top = this.scrollDistance + 'px';
    
    this.divs.push(leftmost);
    
    this.smoothMovement.position -= this.scrollDistance;
    this.smoothMovement.target -= this.scrollDistance;
  }
  
  
  if (this.scrollDirection == 0)
  {
    this.divs[0].style.left =  (0                   - this.smoothMovement.position) + 'px';
    this.divs[1].style.left =  (this.scrollDistance - this.smoothMovement.position) + 'px';
  }
  else
  {
    this.divs[0].style.top =  (0                   - this.smoothMovement.position) + 'px';
    this.divs[1].style.top =  (this.scrollDistance - this.smoothMovement.position) + 'px';
  }
  
};

