function CScroll(ScrollDiv)
{
  this.ScrollDiv = ScrollDiv;
  this.containerHeight = -1;
  this.steps = 25;
  this.bMoveUp = false;
  this.bMoveDown = false;
}

CScroll.prototype.downward = function()     
{
  this.bMoveDown = true; 
  this.bMoveUp = false;
  this.down();
}

CScroll.prototype.down = function() {
    if (this.bMoveDown) {
        var Div = $("#" + this.ScrollDiv);
        if (this.containerHeight < 0) {
            this.containerHeight = Div.parent().height();
        }
        
        if(Div.height() < this.containerHeight)
        {
        	return;
        }
        
        var Current = parseInt(Div.css("top"));
        var _this = this;
        var nextPos = Current - this.steps;
        var maxPos = (Div.height() - this.containerHeight)*-1;
        if (nextPos < maxPos) {
            nextPos = maxPos;
            Div.animate({ top: nextPos + "px" }, 200, 'linear');
        } else {
            Div.animate({ top: nextPos + "px" }, 200, 'linear', function() { _this.down(); });
        }
    }
}

CScroll.prototype.upward = function()
{
  this.bMoveUp = true;
  this.bMoveDown = false; 
  this.up();
}
  
CScroll.prototype.up = function()    
{
  if(this.bMoveUp) {  
    var Div = $("#" + this.ScrollDiv); 

    var Current = parseInt(Div.css("top"));

    if(Div.height() < this.containerHeight)
    {
    	return;
    }

    if(Current < 0) {
      var nextPos = Current+this.steps;
      if(nextPos > 0) {
        nextPos = 0;  
      }
      var _this = this; 
      Div.animate({top: nextPos + "px"}, 200, 'linear', function(){ _this.up();} );
    }
  }
}

CScroll.prototype.stop = function()
{
  this.bMoveUp = false;
  this.bMoveDown = false;
}

CScroll.prototype.increaseSpeed = function()
{
   this.steps = 60;
}

CScroll.prototype.decreaseSpeed = function()
{
    this.steps = 20;
}

CScroll.prototype.reset = function()
{
 $("#" + this.ScrollDiv).css("top", "0px");
}


