/* MUST CHECK WRAPPER/CONTAINER LAYER NAME ON LINE 78 AND LINE 97 */

var timerID = null;
var timerOn = false;
var timecount = 2500;
var open = false;

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	{
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	}
	else if(obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	{
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	}
	else if(obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

function showMenu(menu, linkitem)
{
	hideAll();
	var message, xPos, yPos, marginleft;
	var marginTop = '30px';
	var obj, obj2;
/*
	Support for Netscape
	if(document.layers)
	{
		var obj = document.layers[menu];
		xPos = findPosX(linkitem);
		yPos = findPosY(linkitem);
		obj.position = 'absolute';		
		obj.left = xPos + 'px';
		obj.top = yPos + 'px';
		obj.visibility = 'show';
		
	}
	else
*/
	if(document.getElementById)
	{
		obj = document.getElementById(menu);
		obj2 = document.getElementById(linkitem);
		
		// GET ABS POS OF OBJ2
		xPos = findPosX(obj2);
		yPos = findPosY(obj2);		
		// GET LEFT MARGIN OF PGWRAPPER IF FIXED WIDTH
		marginleft = findPosX(document.getElementById('Wrapper'));
		// SET ABS POS OF SUBMENU
		obj.style.position = 'absolute';
		obj.style.left = xPos - marginleft + 'px';
		obj.style.top = marginTop;
		obj.style.zIndex = 10;
		obj.style.visibility = 'visible';

		//message = "MarginLeft: " + marginleft + "\n\n" + xPos + " : " + obj.style.left + "\n" + yPos + " : " + obj.style.top;
	}
	else
	{
		obj = document.all[menu];
		obj2 = document.all[linkitem];
		
		// GET ABS POS OF OBJ2
		xPos = findPosX(obj2);
		yPos = findPosY(obj2);		
		// GET LEFT MARGIN OF PGWRAPPER IF FIXED WIDTH
		marginleft = findPosX(document.all['Wrapper']);
		// SET ABS POS OF SUBMENU
		obj.style.position = 'absolute';
		obj.style.left = xPos - marginleft + 'px';
		obj.style.top = marginTop;
		obj.style.zIndex = 10;		
		obj.style.visibility = 'visible';

		//message = "MarginLeft: " + marginleft + "\n\n" + xPos + " : " + obj.style.left + "\n" + yPos + " : " + obj.style.top;	
	}
	//window.alert(message);
	stopTime();
	if(!open)
		startTime(menu, linkitem);
	else
		open = true;
}

function hideMenu(menu, linkitem)
{
//	window.alert(menu);
	var message, xPos, yPos;
/*	
	if(document.layers)
	{
		document.layers[menu].visibility = 'hide';		
	}
	else
*/
	if(document.getElementById)
	{
		var obj = document.getElementById(menu);
		obj.style.visibility = 'hidden';
	}
	else
	{
		document.all[menu].style.visibility = 'hidden';
	}
}

function hideAll()
{
	//
	for(i=0; i<10; i++)
	{
		if(document.getElementById)
		{
			if(document.getElementById('sub'+i))
				hideMenu('sub'+i, 'nav'+i);	
		}
		else
		{
			if(document.all['sub'+i])
				hideMenu('sub'+i, 'nav'+i);				
		}
	}
	open = false;
}

function startTime(menu, linkitem) 
{
	if (timerOn == false) 
	{
		timerID = setTimeout( "hideAll();" , timecount);
		timerOn = true;
	}
}

function stopTime() 
{
	if (timerOn) 
	{
		clearTimeout(timerID);
		timerID = null;
		timerOn = false;
	}
}
