var scrollTimer;  
var scrollData = new Array();	 

var scrollSpeed = 20;
var scrollStartTime;
var scrollStartPos;
		 
function scroll_init(text,up,down,scrollHeight)
{	 
	scrollData[text] = new Object(); 
	scrollData[text].elem = document.getElementById(text);
	scrollData[text].up = document.getElementById(up);
	scrollData[text].down = document.getElementById(down);	
	scrollData[text].height = scrollHeight;  

	scrollData[text].elem.style.top = "0px";
	set_scrollbutton_visibility(text);
}

function set_scrollbutton_visibility(id)
{
	heightInt = parseInt(scrollData[id].elem.offsetHeight);

	if (heightInt > (scrollData[id].height+10)) {
		scrollData[id].up.style.visibility = "hidden";
		scrollData[id].down.style.visibility = "visible";
	}		
	else
	{
		scrollData[id].up.style.visibility = "hidden";
		scrollData[id].down.style.visibility = "hidden";
	}	
	if (parseInt(scrollData[id].elem.style.top) < 0) scrollData[id].up.style.visibility = "visible";
}

function scrolldown(id) 
{
	var jetzt = new Date();
	elem = document.getElementById(id);	   
	heightInt = parseInt(elem.offsetHeight);
	topInt = parseInt(elem.style.top);
	topInt = scrollStartPos - (jetzt.getTime()-scrollStartTime)*scrollSpeed/100;
	if (topInt < scrollData[id].height-heightInt) 
	{
		topInt = scrollData[id].height-heightInt;
		scrollData[id].down.style.visibility = "hidden";
		clearInterval(scrollTimer);
	}
	elem.style.top = topInt+"px";
	if (topInt < 0) scrollData[id].up.style.visibility = "visible";
}

function scrollup(id) 
{
	var jetzt = new Date();
	elem = document.getElementById(id);
	topInt = parseInt(elem.style.top);
	topInt = scrollStartPos + (jetzt.getTime()-scrollStartTime)*scrollSpeed/100;
	if (topInt > 0) 
	{
		topInt = 0;
		scrollData[id].up.style.visibility = "hidden";
		clearInterval(scrollTimer);
	}
	elem.style.top = topInt+"px";
	if (topInt > scrollData[id].height-heightInt) scrollData[id].down.style.visibility = "visible";
}

function start_scrolldown(id)
{							
	var jetzt = new Date();
	clearInterval(scrollTimer); 
	scrollStartPos = parseInt(document.getElementById(id).style.top);
	scrollStartTime = jetzt.getTime();   
	scrollTimer = setInterval("scrolldown('"+id+"')",10);	
}

function start_scrollup(id)
{		
	var jetzt = new Date();
	clearInterval(scrollTimer);  
	scrollStartPos = parseInt(document.getElementById(id).style.top);
	scrollStartTime = jetzt.getTime();   
	scrollTimer = setInterval("scrollup('"+id+"')",10);
}						
					   
function stop_scroll()
{	   							
	clearInterval(scrollTimer);
}

function scroll_to(id,pos)
{
	scrollData[id].elem.style.top = "-"+pos+"px";
}
