Event.observe(window, 'load', 
	function() 
	{
 		if ($('scrollbox'))
 		{
			var scrollbox = new ScrollArea('scrollbox','scrollbox_clip', 150, 5);
 		}
	}
);

function ScrollArea(element,element_content, sensitive_area, maxSpeed)
{	
	var pos       = Position.cumulativeOffset($(element));
	this.x        = pos[0];
	this.y        = pos[1];
	this.width    = $(element).getWidth();
	this.height   = $(element).getHeight();
	this.maxX     = this.x + this.width;
	this.maxY     = this.y + this.height;
	this.content  = $(element_content);
	this.speed    = 0;
	this.active   = false;
	this.maxSpeed = maxSpeed;
	this.sensitive_area = sensitive_area;
		
	Event.observe(document,'mousemove', this.activateScroller.bindAsEventListener(this));
} 

ScrollArea.prototype.activateScroller = function (event)
{
	this.mouseX = Event.pointerX(event);
	this.mouseY = Event.pointerY(event);
	
	if(this.isMouseOver())
	{
		if(!this.active)
		{
			this.active = true;
			this.pe = new PeriodicalExecuter(this.scroll.bindAsEventListener(this), 0.02);
		}
	}
	else
	{
		this.active = false;
		if(this.pe)
		{
			this.pe.stop();
		}
	}
}

ScrollArea.prototype.isMouseOver = function ()
{
	var y_dist = Math.min(this.mouseY - this.y, this.maxY - this.mouseY);
	if (this.x <= this.mouseX && this.maxX >= this.mouseX && y_dist <= this.sensitive_area && y_dist >= 0)
	{
		return true;
	}
	return false;
}

ScrollArea.prototype.calculateSpeed = function ()
{
	if (this.isMouseOver())
	{
		this.speed = ((this.mouseY - this.y) /	this.height);
	}
	this.speed = (this.speed - 0.5) * 2;
	this.speed = -this.speed * this.maxSpeed;
	return this.speed;
}

ScrollArea.prototype.scroll = function()
{
	this.calculateSpeed();
	
	var new_top =  Math.round(parseInt(this.content.getStyle('top')) + this.speed);
	if (new_top > 0) new_top = 0;
	
	var maxScrollOffset = this.content.getHeight() - this.height;
	if (maxScrollOffset < 0) maxScrollOffset = 0;

	if (new_top < - maxScrollOffset)
	{
		new_top = - maxScrollOffset;
	}
	this.content.style.top = new_top + 'px';
}