// JavaScript Document

var offset_left = 0;
var offset_top 	= 0;

function updateTgtPosition(tgt_id)
{
	var nx_id = document.getElementById(tgt_id);
	
	offset_left = nx_id.offsetLeft;
	offset_top	= nx_id.offsetTop;
	
	while (nx_id)
	{
		if	(nx_id.offsetParent)
		{ 
			offset_left = offset_left + nx_id.offsetParent.offsetLeft;
			offset_top  = offset_top + nx_id.offsetParent.offsetTop;
			
			nx_id  = nx_id.offsetParent; 
		}
		else
		{ nx_id = false; }
	}
}

window.autoScroller = new Array();

function autoScrollerSetup(par_id, cont_id, int_spacing)
{ clearTimeout(window.autoTimeout); window.autoTimeout = setTimeout("autoScrollerStart('"+par_id+"', '"+cont_id+"', '"+int_spacing+"')", 2000); }

window.scrollerRecord = new Array();

function autoScrollerStart(cont_id, par_id, int_spacing)
{ 
	var container = document.getElementById(par_id);
	var parent	  = document.getElementById(cont_id);
	
	if	((container.offsetTop+container.offsetHeight) < parent.offsetHeight)
	{ if (!window.autoScroller['direction']) { window.autoScroller['direction'] = 'up'; } clearInterval(window.scrollerRecord[par_id+'_vert']); window.scrollerRecord[par_id+'_vert'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', '"+window.autoScroller['direction']+"', "+int_spacing+")", 5); }
	else if	(container.offsetWidth < parent.offsetWidth)
	{ if (!window.autoScroller['direction']) { window.autoScroller['direction'] = 'neg'; } clearInterval(window.scrollerRecord[par_id+'_hor']); window.scrollerRecord[par_id+'_hor'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', '"+window.autoScroller['direction']+"', "+int_spacing+")", 5); }
}

function beginNavScroller(e, par_id, cont_id, horizontal_scroll, vertical_scroll, int_dist)
{	
	// Determine div's left and top position
	updateTgtPosition(par_id)
	// End of the above

	if (window.browserType == 'IE') 
	{ var mousX = event.clientX + document.body.scrollLeft; var mousY = event.clientY + document.body.scrollTop; }
	else 
	{ var mousX = e.pageX; var mousY = e.pageY; }

	var percentage_width 	= Math.floor(((mousX-offset_left)/document.getElementById(par_id).offsetWidth)*100);
	var percentage_height 	= Math.floor(((mousY-offset_top)/document.getElementById(par_id).offsetHeight)*100);

	if	(percentage_width && horizontal_scroll == 'true')
	{
		if	(percentage_width > 70)
		{ 
			if	(percentage_width > 85)
			{ clearInterval(window.scrollerRecord[par_id+'_hor']); window.scrollerRecord[par_id+'_hor'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'neg', "+int_dist+")", 5); }
			else
			{ clearInterval(window.scrollerRecord[par_id+'_hor']); window.scrollerRecord[par_id+'_hor'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'neg', "+int_dist+")", 10); }
		}
		else if	(percentage_width < 30)
		{ 
			if	(percentage_width < 15)
			{ clearInterval(window.scrollerRecord[par_id+'_hor']); window.scrollerRecord[par_id+'_hor'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'pos', "+int_dist+")", 5); }
			else
			{ clearInterval(window.scrollerRecord[par_id+'_hor']); window.scrollerRecord[par_id+'_hor'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'pos', "+int_dist+")", 10); }
		}
		else
		{ clearInterval(window.scrollerRecord[par_id+'_hor']); window.scrollerRecord[par_id+'_hor'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'neu')", 10); }
	} 
	
	
	if	(percentage_height && vertical_scroll == 'true')
	{ 
		if	(percentage_height > 70)
		{ 
			if	(percentage_height > 85)
			{ clearInterval(window.scrollerRecord[par_id+'_vert']); window.scrollerRecord[par_id+'_vert'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'up', "+int_dist+")", 5); }
			else
			{ clearInterval(window.scrollerRecord[par_id+'_vert']); window.scrollerRecord[par_id+'_vert'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'up', "+int_dist+")", 10); }
		}
		else if	(percentage_height < 30)
		{ 
			if	(percentage_height < 15)
			{ clearInterval(window.scrollerRecord[par_id+'_vert']); window.scrollerRecord[par_id+'_vert'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'down', "+int_dist+")", 5); }
			else
			{ clearInterval(window.scrollerRecord[par_id+'_vert']); window.scrollerRecord[par_id+'_vert'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'down', "+int_dist+")", 10); }
		}
		else
		{ clearInterval(window.scrollerRecord[par_id+'_vert']); window.scrollerRecord[par_id+'_vert'] = setInterval("realiseNavScroller('"+par_id+"', '"+cont_id+"', 'neu')", 10); }
	}
}


function scrollerSetPos(par_id, cont_id, align)
{
	var container = document.getElementById(cont_id);
	var parent	  = document.getElementById(par_id);
	
	if	(container.offsetHeight > parent.offsetHeight)
	{ 
		if	(align == 'bottom')
		{ container.style.top = (parent.offsetHeight-container.offsetHeight); }
	}
}


function realiseNavScroller(par_id, cont_id, direction, int_spacing)
{
	var container = document.getElementById(cont_id);
	var parent	  = document.getElementById(par_id);

	if	(container.offsetWidth > parent.offsetWidth && direction == 'pos' || container.offsetWidth > parent.offsetWidth && direction == 'neg')
	{
		if		((container.offsetLeft+container.offsetWidth) <= parent.offsetWidth)
		{
			if (direction == 'pos') 
			{ container.style.left = container.offsetLeft+int_spacing; navArrowController(par_id, 'left', 'on'); navArrowController(par_id, 'right', 'on'); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'neg'; } }
			else if	(direction == 'neg')
			{ navArrowController(par_id, 'right', 'off'); clearInterval(window.scrollerRecord[par_id+'_hor']); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'pos'; autoScrollerSetup(cont_id, par_id, int_spacing); } }
		}
		else if	((container.offsetLeft+container.offsetWidth) >= parent.offsetWidth)
		{
			if (direction == 'pos' && container.offsetLeft <= 0) 
			{
				if	(container.offsetLeft+int_spacing > 0)
				{ container.style.left = '0px'; navArrowController(par_id, 'left', 'off'); clearInterval(window.scrollerRecord[par_id+'_hor']); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'neg'; autoScrollerSetup(cont_id, par_id, int_spacing); } }
				else
				{ container.style.left = container.offsetLeft+int_spacing; navArrowController(par_id, 'left', 'on'); navArrowController(par_id, 'right', 'on'); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'neg'; } }
			} 
			else if (direction == 'neg') 
			{  container.style.left = container.offsetLeft-int_spacing; navArrowController(par_id, 'right', 'on'); navArrowController(par_id, 'left', 'on'); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'neg'; } }
		}
	}
	else if	(container.offsetHeight > parent.offsetHeight && direction == 'up' || container.offsetHeight > parent.offsetHeight && direction == 'down')
	{	
		if		((container.offsetTop+container.offsetHeight) <= parent.offsetHeight)
		{ 
			if (direction == 'down') 
			{ container.style.top = container.offsetTop+int_spacing; navArrowController(par_id, 'up', 'on'); navArrowController(par_id, 'down', 'on'); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'down'; } }
			else if	(direction == 'up')
			{ container.style.top = (parent.offsetHeight-container.offsetHeight); navArrowController(par_id, 'down', 'off'); clearInterval(window.scrollerRecord[par_id+'_vert']); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'up'; autoScrollerSetup(cont_id, par_id, int_spacing); } }
		}
		else if	((container.offsetTop+container.offsetHeight) >= parent.offsetHeight)
		{ 
			if (direction == 'down' && container.offsetTop <= 0) 
			{ 
				if	(container.offsetTop+int_spacing > 0)
				{ container.style.top = '0px'; navArrowController(par_id, 'up', 'off'); clearInterval(window.scrollerRecord[par_id+'_vert']); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'up'; autoScrollerSetup(cont_id, par_id, int_spacing); } }
				else
				{ container.style.top = container.offsetTop+int_spacing; navArrowController(par_id, 'down', 'on'); navArrowController(par_id, 'up', 'on'); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'down'; } }
			} 
			else if (direction == 'up') 
			{ 
				if	((container.offsetTop-int_spacing) > (parent.offsetHeight-container.offsetHeight))
				{ container.style.top = container.offsetTop-int_spacing; navArrowController(par_id, 'up', 'on'); navArrowController(par_id, 'left', 'on'); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'up'; } }
				else
				{ container.style.top = (parent.offsetHeight-container.offsetHeight); navArrowController(par_id, 'down', 'off'); clearInterval(window.scrollerRecord[par_id+'_vert']); if (window.autoScroller['direction']) { window.autoScroller['direction'] = 'down'; autoScrollerSetup(cont_id, par_id, int_spacing); } }
			}
		}
	}
}

	
function navArrowController(par_id, dir, action)
{
	if	(document.getElementById(par_id) && document.getElementById(par_id+'_'+dir))
	{
		if	(action == 'on')
		{ document.getElementById(par_id+'_'+dir).style.display = ''; }
		else
		{ document.getElementById(par_id+'_'+dir).style.display = 'none'; }
	}
}

function clearNavScroller(par_id)
{ clearInterval(window.scrollerRecord[par_id]); }
