﻿// JScript File
var ScrollTimer = null;

function ScrollDiv(order, content_id, container_id) 
{
	var step = 2;
	
	if ( !(containerDiv = document.getElementById(container_id)) ) 
	{
		return;
	}
	
	if ( !(movedDiv = document.getElementById(content_id)) ) 
	{
		return;
	}

	var top = movedDiv.style.top ? parseInt(movedDiv.style.top) : 0;
	var left = movedDiv.style.left ? parseInt(movedDiv.style.left) : 0;
	
	var scrollableSpace = containerDiv.offsetHeight - movedDiv.offsetHeight;
	var scrollableHSpace = containerDiv.offsetWidth - movedDiv.offsetWidth;
	
	//window.status = containerDiv.offsetWidth + ", " + movedDiv.offsetWidth + ", " + left;

	switch (order)
	{ 
		case "up" : 
			if ( top > scrollableSpace )
			{
				movedDiv.style.top = (top - step) + "px"; 
			}
			break; 
		case "down" : 
			if ( top < 0 )
			{
				movedDiv.style.top = (top + step) + "px"; 
			}
			break; 
		case "left" : 
			if ( left > scrollableHSpace )
			{
				movedDiv.style.left = (left - step) + "px"; 
			}
			break; 
		case "right" : 
			if ( left < 0 )
			{
				movedDiv.style.left = (left + step) + "px"; 
			}
			break; 
		default : 
			// Nothing 
			break;
	} 
	
	//window.status = 'containerDiv.offsetWidth: ' + containerDiv.offsetWidth + ', movedDiv.offsetWidth: ' + movedDiv.offsetWidth;
	
	ScrollTimer = setTimeout("ScrollDiv('" + order + "', '" + content_id + "', '" + container_id + "')", 8);
	//return false; 
}

function StopScrollDiv()
{
	clearTimeout(ScrollTimer);
}

function CustomScrollDiv(order, content_id, container_id, step)
{
	if ( !(containerDiv = document.getElementById(container_id)) ) 
	{
		return;
	}
	
	if ( !(movedDiv = document.getElementById(content_id)) ) 
	{
		return;
	}

	var top = movedDiv.style.top ? parseInt(movedDiv.style.top) : 0;
	var left = movedDiv.style.left ? parseInt(movedDiv.style.left) : 0;
	
	var scrollableSpace = containerDiv.offsetHeight - movedDiv.offsetHeight;
	var scrollableHSpace = containerDiv.offsetWidth - movedDiv.offsetWidth;
	
	switch (order)
	{ 
		case "up" : 
			if ( top > scrollableSpace )
			{
				movedDiv.style.top = (top - step) + "px"; 
			}
			break; 
		case "down" : 
			if ( top < 0 )
			{
				movedDiv.style.top = (top + step) + "px"; 
			}
			break; 
		case "left" : 
			if ( left > scrollableHSpace )
			{
				movedDiv.style.left = (left - step) + "px"; 
			}
			break; 
		case "right" : 
			if ( left < 0 )
			{
				movedDiv.style.left = (left + step) + "px"; 
			}
			break; 
		default : 
			// Nothing 
			break;
	}
}
