

function clickScroller(containerId, imageId, scrollSize, scrollCount, scrollStep, scrollDirection)
{
  this.smoothMovement  = new SmoothMovement(0, 0);
  this.containerId     = containerId;
  this.imageId         = imageId;
  this.scrollSize      = scrollSize;
  this.scrollCount     = scrollCount;
  this.scrollStep      = scrollStep;
  this.scrollDirection = scrollDirection;
};

clickScroller.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;
    
  var img = document.getElementById(this.imageId);
  if (img)
  {
    if (img.addEventListener)
    {
      img.addEventListener('click', this.createTriggerClosure(), false);
    }
    else if (img.attachEvent)
    {
      img.attachEvent('onclick', this.createTriggerClosure());
    }
  }
};

clickScroller.prototype.createTriggerClosure = function()
{
  var me = this;
  
  return function() {me.trigger();};
};

clickScroller.prototype.trigger = function()
{
  this.smoothMovement.target += this.scrollSize * this.scrollStep;
  this.smoothMovement.animate(20, this.createUpdateClosure(), function(){});
};

clickScroller.prototype.createUpdateClosure = function()
{
  var me = this;
  
  return function() {me.update();};
};

clickScroller.prototype.update = function()
{
  while (this.smoothMovement.position >= this.scrollSize)
  {
    var leftmost = this.divs.shift();
    
    if (this.scrollDirection == 0)
      leftmost.style.left = (this.scrollSize * this.scrollCount) + 'px';
    else
      leftmost.style.top = (this.scrollSize * this.scrollCount) + 'px';
    
    this.divs.push(leftmost);
    
    this.smoothMovement.position -= this.scrollSize;
    this.smoothMovement.target -= this.scrollSize;
  }
  
  
  if (this.scrollDirection == 0)
  {
    for (var i=0; i<=this.scrollCount; i++)
    {
      this.divs[i].style.left =  (i*this.scrollSize - this.smoothMovement.position) + 'px';
    }
  }
  else
  {
    for (var i=0; i<=this.scrollCount; i++)
    {
      this.divs[i].style.top =  (i*this.scrollSize - this.smoothMovement.position) + 'px';
    }
  }
  
};

