//document.onmouseup = stop_scroll;
   
var scrollTimer;  
var scrollData = new Array();	 
var scrollMaxSpeed = 5;

var scrollCurrentSpeed = 0;
var scrollDestinationSpeed = scrollMaxSpeed;

var mouseWheelObjId;
		 
function scroll_init(text,up,down,scrollHeight,mouseWheel)
{	 
	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";
	heightInt = parseInt(scrollData[text].elem.offsetHeight);

	if (heightInt > (scrollHeight)) 
	{
		scrollData[text].up.style.visibility = "hidden";
		scrollData[text].down.style.visibility = "visible";
	}		
	else
	{
		scrollData[text].up.style.visibility = "hidden";
		scrollData[text].down.style.visibility = "hidden";
	}		
	//document.onmouseup = stop_scroll;  

	// Mouse Wheel Support
	if ((typeof(mouseWheel) != "undefined") && (heightInt > (scrollHeight)))
	{
		//adding the event listerner for Mozilla
		if(window.addEventListener) document.addEventListener('DOMMouseScroll', mouseWheelCB, false);
		//for IE/OPERA etc
		document.onmousewheel = mouseWheelCB;
		mouseWheelObjId = text;
	}

}

function mouseWheelCB(event)
{
	var delta = 0;
	if (!event) event = window.event;
	// normalize the delta
	if (event.wheelDelta)
	{
		// IE & Opera
		delta = event.wheelDelta / 120;
	}
	else if (event.detail) // W3C
	{
		delta = -event.detail / 3;
	}
	var currPos=parseInt(document.getElementById(mouseWheelObjId).style.top);

	//calculating the next position of the object
	currPos=parseInt(currPos)+(delta*10);
	

	elem = document.getElementById(mouseWheelObjId);	   
	heightInt = parseInt(elem.offsetHeight);

	if (currPos > 0) 
	{
		currPos = 0;
		scrollData[mouseWheelObjId].up.style.visibility = "hidden";
	}
	if (currPos < scrollData[mouseWheelObjId].height-heightInt) 
	{
		currPos = scrollData[mouseWheelObjId].height-heightInt;
		scrollData[mouseWheelObjId].down.style.visibility = "hidden";
	}

	//moving the position of the object  
	document.getElementById(mouseWheelObjId).style.top=currPos+"px";
	
	if (currPos < 0) scrollData[mouseWheelObjId].up.style.visibility = "visible";
	if (currPos > scrollData[mouseWheelObjId].height-heightInt) scrollData[mouseWheelObjId].down.style.visibility = "visible";
}

function scrolldown(id) 
{
	elem = document.getElementById(id);	   
	heightInt = parseInt(elem.offsetHeight);
	topInt = parseInt(elem.style.top);
	if (scrollCurrentSpeed < scrollDestinationSpeed) scrollCurrentSpeed += 0.3;
	if (scrollCurrentSpeed > scrollDestinationSpeed) scrollCurrentSpeed -= 0.3;
	if (scrollCurrentSpeed <= 0) scroll_end();
	topInt -= scrollCurrentSpeed;
	if (topInt < scrollData[id].height-heightInt) 
	{
		topInt = scrollData[id].height-heightInt;
		scrollData[id].down.style.visibility = "hidden";
	}
	elem.style.top = topInt+"px";
	if (topInt < 0) scrollData[id].up.style.visibility = "visible";
}

function scrollup(id) 
{
	elem = document.getElementById(id);
	topInt = parseInt(elem.style.top);
	if (scrollCurrentSpeed < scrollDestinationSpeed) scrollCurrentSpeed += 0.3;
	if (scrollCurrentSpeed > scrollDestinationSpeed) scrollCurrentSpeed -= 0.3;
	if (scrollCurrentSpeed <= 0) scroll_end();
	topInt += scrollCurrentSpeed;
	if (topInt > 0) 
	{
		topInt = 0;
		scrollData[id].up.style.visibility = "hidden";
	}
	elem.style.top = topInt+"px";
	if (topInt > scrollData[id].height-heightInt) scrollData[id].down.style.visibility = "visible";
}

function start_scrolldown(id)
{							   
	scroll_end();  
	scrollTimer = setInterval("scrolldown('"+id+"')",10);	
}

function start_scrollup(id)
{		
	scroll_end();  
	scrollTimer = setInterval("scrollup('"+id+"')",10);
}						
					   
function scroll_end()
{
	scrollCurrentSpeed = 0;
	scrollDestinationSpeed = scrollMaxSpeed;
	clearInterval(scrollTimer);
}

function stop_scroll()
{	   							
	scrollDestinationSpeed = 0;
}