var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

function getObjectPos(objectid) {
	//*** get the x/y position of the browse products link
	//get the current document scroll amount	
	var scrollx=document.all? iebody.scrollLeft : window.pageXOffset
	var scrolly=document.all? iebody.scrollTop : window.pageYOffset
	var objectx = 0;
	var objecty = 0;
	
	theObject = $(objectid);
	
	while (theObject.offsetParent){
		objectx += theObject.offsetLeft;
		objecty += theObject.offsetTop;
		theObject = theObject.offsetParent;
	}
	
	objectx += theObject.offsetLeft;
	objecty += theObject.offsetTop;
	
	return {x:objectx, y:objecty};
}

/*
START - TOP NAV HOVER MENUS
*/
//initiate vars
var menuInit = false;
var showingMenu = false;
var menu_timer;
var menuArrow = new Image();
menuArrow.src = '/store/images/reloaded/top_navarrow.gif';
var menuArrowHover = new Image();
menuArrowHover.src = '/store/images/reloaded/top_navarrow_h.jpg';

//menu initialise function
function initMenu()
{	
	//get the menu objects
	menuLists = $$('div.top_nav_menu_list');
	for(m=0;m<menuLists.length;m++)
	{		
		//inspect each menu object and get all li items for the current menu
		menuItems = $(menuLists[m]).getElementsBySelector('li');
		for(i=0;i<menuItems.length;i++)
		{
			//apply mouse overs to each menu object
			menuItems[i].onmouseover = function()
			{
				highlight(this, 'on');				
			}
			menuItems[i].onmouseout = function()
			{
				highlight(this, 'off');
			}
		}
	}
	menuInit = true;
}

//show menu when hovered
function showMenu(selectedMenu)
{
	if(menuInit)
	{
		if(showingMenu)
		{
			killMenuTimer();
			hideMenusDo();		
		}
		showingMenu = selectedMenu;	
		//fiest get the x/y of the hovered menu
		
		menuPos = getObjectPos('button_'+selectedMenu);	
		menux = menuPos.x;
		menuy = menuPos.y + 30;
		
		$('menu_'+selectedMenu).setStyle({top:menuy+'px',left:menux+'px'});
		$('menu_'+selectedMenu).show();
		$('button_'+selectedMenu).addClassName('hover');
		$('arrow_'+selectedMenu).src = menuArrowHover.src;
	}
}

//start timer to hide menu
function hideMenus()
{
	menu_timer = setTimeout("hideMenusDo();",250);
}

//interupt hide timer - continues to show menu
function killMenuTimer() {
	if(menu_timer)
	{
		clearTimeout(menu_timer);
	}
}

//do the hiding of the currently open menu
function hideMenusDo()
{
	if(showingMenu)
	{	
		$('menu_'+showingMenu).hide();
		$('button_'+showingMenu).removeClassName('hover');
		$('arrow_'+showingMenu).src = menuArrow.src;
		showingMenu = false;
	}
}

//highlight menu items
function highlight(el, status) {
	if(status == 'on')
	{	
		$(el).setStyle({backgroundColor:'#7E9EDA'});			
	}
	else
	{
		$(el).setStyle({backgroundColor:'#8EAADF'});
	}
}


/*
END - TOP NAV HOVER MENUS
*/

/* START - LOAD OTHER SCRIPTS */
var loadScripts = Array('login').each(
	function(include)
	{
		document.write('<script type="text/javascript" src="/javascript/'+include+'.js"></script>');
	}
);
/* END - LOAD OTHER SCRIPTS */


