var speed = 10;
var waittime = 100;

function cScrollBox(newLayerId,newScrollId,newScrollBarId,newAreaId,newName)
{
	this.ypos = 0;
	this.ybarpos = 0;
	this.timerId = 0;
	this.LayerId = newLayerId;
	this.ScrollId = newScrollId;
	this.ScrollBarId = newScrollBarId;
	this.buttonspeed = 1;
	this.maxYShift = 100;
	this.ScrollBarHeight = 80;
	this.startScrollDown = moveDown;
	this.startScrollUp = moveUp;
	this.stopScroll = stopScrollFunc;
	this.name = newName;
	this.AreaId = newAreaId;

	var lay; 
	lay = getLayer(this.LayerId);
	var scroll; 
	scroll = getLayer(this.ScrollId);
	var bar; 
	bar = getLayer(this.ScrollBarId);
	var area; 
	area = getLayer(this.AreaId);

	this.maxYShift = -area.offsetHeight + lay.offsetHeight;


	if (this.maxYShift < 0) 
	{
		this.maxYShift = 0;
	}		

	this.ScrollBarHeight = bar.offsetHeight;

	this.buttonspeed = Math.round(((this.ScrollBarHeight-scroll.offsetHeight*2)/(this.maxYShift)) * speed); 

}

	function stopScrollFunc()
	{
		clearTimeout(this.timerId);
		this.timerId = 0;
	}
	function moveUp()
	{
		var lay; 
		lay = getLayer(this.LayerId);
		if (this.ypos<=-speed)
		{
			lay.style.top =(this.ypos + speed)+"px";
			this.ypos = this.ypos + speed;
		}

		lay = getLayer(this.ScrollId);
		if (this.ybarpos>=this.buttonspeed)
		{	
			lay.style.top =(this.ybarpos - this.buttonspeed)+"px";
			this.ybarpos = this.ybarpos - this.buttonspeed;
		}

		this.timerId = setTimeout(this.name+".startScrollUp();",waittime);
	}

	function moveDown()
	{
		var lay; 
		//if (this.ypos>=-lay.offsetHeight+this.maxYShift)
		//{
		//}

		lay = getLayer(this.ScrollId);

		if (this.ybarpos<this.ScrollBarHeight - lay.offsetHeight-2)
		{
			lay.style.top =(this.ybarpos + this.buttonspeed)+"px";
			this.ybarpos = this.ybarpos + this.buttonspeed;

		lay = getLayer(this.LayerId);

			lay.style.top =(this.ypos - speed)+"px";
			this.ypos = this.ypos - speed;

		}

		this.timerId = setTimeout(this.name+".startScrollDown();",waittime);

	}



function getLayer(layerID)
{
if (document.getElementById)
	return document.getElementById(layerID);
else if (document.all)
	return document.all[layerID];
else 
	return null;
}

