/* Scroller
*
*	outside container:
*		id:		'scroll__cntnr'
*
*		required inline style definitions:
*			position:	absolute
*			top:		*
*			left:		*
*			width:		*
*			height:		*
*			overflow:	hidden
*
*	inside container
*		id:		'scroll_elem'
*		
*/


var scroll_cntnr;		// outside container
var scroll_elem;		// inside container
var scroll_win_height;	// height value of 'scroll_cntnr' inline style definition
var bottom_space = -20; // vertical gap at bottom of 'scroll_elem'
var scrollInterval;		// setInterval return value		

function init_scroll()
{
	scroll_elem = MM_findObj('scroll_elem');
	scroll_win_height = parseInt(MM_findObj('scroll_cntnr').style.height);
}

function scroll_start(dir, elem, cntnr)
{
	scroll_elem = MM_findObj(elem);
	scroll_win_height = parseInt(MM_findObj(cntnr).style.height);
	
	if(!scrollInterval)
	{
		if(dir < 0) scrollInterval = setInterval("scrollup()", 60);
		else if(dir > 0) scrollInterval = setInterval("scrolldown()", 60);
	}
}

function scroll_stop()
{
	clearInterval(scrollInterval);
	scrollInterval = null;
}

function scrollup()
{	
	// first, check that were not at the bottom
	if(get_bottom() < (scroll_win_height - bottom_space) && scrollInterval != null)
	{
		clearInterval(scrollInterval);
		scrollInterval = null;
	}
	else // we've got room to scroll
	{
		var value = parseInt(scroll_elem.style.top) - 10;
		scroll_elem.style.top = value + "px";
	}
}
function scrolldown()
{
	// first, check that were not at the top
	if(!parseInt(scroll_elem.style.top) && scrollInterval != null)
	{
		clearInterval(scrollInterval);
		scrollInterval = null;
	}
	else // we've got room to scroll
	{
		var value = parseInt(scroll_elem.style.top) + 10;
		scroll_elem.style.top = value + "px";
	}
}

function get_bottom()
{
	var top = parseInt(scroll_elem.style.top);
	var height = scroll_elem.offsetHeight;
	return height + top;
}
