var currAlias = null;
var parObj = null;
var chiObj = null;
var menuVisible = false;

//IE 6 fix for menu positioning
var xOffset = (navigator.appVersion.indexOf("MSIE 6.") > 0) ? 14 : 0;
var yOffset = (navigator.appVersion.indexOf("MSIE 6.") > 0) ? 33 : 32;
var origClassNm = "menuLevel1";

function showMenu(d, classNm) {
	if (chiObj != null) hideMenu();
	origClassNm = classNm;
	
	currAlias = d;
	parObj = document.getElementById(d + "Menu");
	chiObj = document.getElementById(d + "SubMenu");

	parObj.className = "menuLevel1Show";
	chiObj.className = "menuLevel2Show";
	
	//auto-position the dropdown DIV.  This resolves browser issues across the board
	if (d != "well" && d != "sides" && d != "women") {
		chiObj.style.left = (parObj.offsetLeft-xOffset) + "px";
		chiObj.style.top = (parObj.offsetTop+yOffset) + "px";
	} else if (d == "women" && parObj.offsetLeft < 300) {  //probable wrapped menus
		chiObj.style.left = ((parObj.offsetTop+yOffset)-63) + "px";
		chiObj.style.top = (parObj.offsetTop+yOffset) + "px";
	} else {
		chiObj.style.top = (parObj.offsetTop+yOffset) + "px";
		chiObj.style.right = "0px";
	}

	//add event listeners and monitor cursor movement
	menuVisible = true;
	parObj.onmouseover = setFocus; 
	parObj.onmouseout = setBlur;
	chiObj.onmouseover = setFocus; 
	chiObj.onmouseout = setBlur;
	monitorFocus();
}
function hideMenu() {
	if (parObj != null) {
		parObj.className = origClassNm;
		parObj.onmouseover = new Function("showMenu('" + currAlias + "','" + origClassNm + "')");
	}
	if (chiObj != null) {
		chiObj.className = "menuLevel2";
	}
}
function setFocus() {
	menuVisible = true;
}
function setBlur() {
	menuVisible = false;
}
function monitorFocus() {
	if (!menuVisible) hideMenu();
	else setTimeout("monitorFocus()", 500);
}

//this runs at load time to add browser-specific CSS
if (window.devicePixelRatio) { //Safari
	document.write("<style type=\"text/css\" rel=\"stylesheet\">\n");
	document.write("#wellSubMenu TABLE { width: 413px; } \n");
	document.write("#searchForm input.button { padding: 3px 0 2px; } \n</style>");
} else if (navigator.appVersion.indexOf("X11") > 0 && navigator.appName == "Netscape") {  //Firefox on Linux
	document.write("<style type=\"text/css\" rel=\"stylesheet\">\n");
	document.write("#wellSubMenu TABLE { width: 405px; } \n");
	document.write("DIV.menuLevel1, DIV.menuLevel1Show { padding: 5px 9px 7px; } \n</style>");
} else if (navigator.appVersion.indexOf("X11") > 0 && navigator.appName == "Opera") {  //Opera on Linux
	document.write("<style type=\"text/css\" rel=\"stylesheet\">\n");
	document.write("#wellSubMenu TABLE { width: 411px; } \n");
	document.write("DIV.menuLevel1, DIV.menuLevel1Show { padding: 5px 10px 7px; } \n</style>");
} else if (navigator.appName.indexOf("Internet Explorer") > 0) {
	document.write("<style type=\"text/css\" rel=\"stylesheet\">\n");
	document.write(".png {	behavior: url('/binary/common/scripts/iepngfix.htc');	}\n");
	document.write("</style>");
}
