// Menu Setup Instructions
// -----------------------
// 1) Each of your menus should be in a seperate layer (DIV) with an ID of "menuNum#"
// where the "#" should start with 1, then continue with each consecutive menu (2, 3, 4...)
//
// 2) Each menu's DIV position should be absolute, and the left and top should correspond to
// the menus position when the browser window is closed past the width of the navigation
// (i.e. "menuNum1" will have a left of 18px and top of 15px since this is it's TRUE position
// when it is not centered elsewhere on the page)
//
// 3) Each menu should be activated by a button that has an onClick AND onMouseOver with their
// contents calling the function: showMenu(MENU NUMBER,MENU WIDTH,MENU HEIGHT,MENU CENTER OFFSET);
// (i.e. onClick="showMenu(1,150,100,-167);")
//
// 4) Update the global variables below to match your pages needs.

// Global Variables (edit these)
var numOfMenus = 6;
var fullNavWidth = 630;
var hotZoneBorder = 0;
var menuHideTimeoutMS = 500;
var NSvOffset = 4;
var NShOffset = 13; //9

// Initializers (don't edit these)
var activeMenu = 0;
var activeMenuStartPos = 0;
var mouseX = 0;
var mouseY = 0;
var hotZoneLeft = 0;
var hotZoneRight = 0;
var hotZoneTop = 0;
var hotZoneBottom = 0;
var mouseOnMenu = 0;

function setActiveMenu(menuNum) {
  activeMenu = menuNum;
}

function showMenu(menuNum,menuWidth,menuHeight,centerOffset) {
  // set current menu with mouseOnMenu flag
  mouseOnMenu = menuNum;
  // hide all other menus
  hideAll();
  var menuName = "menuNum" + menuNum
  if (document.all) {
    eval ("activeMenuStartPos = document.all." + menuName + ".style.left");
	if (document.body.clientWidth > fullNavWidth) {
	  centerLine = (document.body.clientWidth/2) - (menuWidth/2) + centerOffset;
	  eval ("document.all." + menuName + ".style.left = centerLine");
	}
  } else {
    eval ("activeMenuStartPos = document." + menuName + ".left");
	if (window.innerWidth > fullNavWidth) {
	  centerLine = (window.innerWidth/2) - (menuWidth/2) + centerOffset;
	  eval ("document." + menuName + ".left = centerLine - NShOffset");
	  eval ("document." + menuName + ".top = (document." + menuName + ".top) - NSvOffset");
	} else {
	  eval ("document." + menuName + ".left = (document." + menuName + ".left) - (NShOffset/2-2)");
	  eval ("document." + menuName + ".top = (document." + menuName + ".top) - NSvOffset");
	}
  }
  eval ("MM_showHideLayers('" + menuName + "','','show')");
  setActiveMenu(menuNum);
  setHotZone(menuName,menuWidth,menuHeight);
}

function setHotZone(menuName,menuWidth,menuHeight) {
  if (document.all) {
	eval ("hotZoneLeft = (document.all." + menuName + ".style.pixelLeft) - hotZoneBorder");
	eval ("hotZoneTop = (document.all." + menuName + ".style.pixelTop) - hotZoneBorder");
  } else {
	eval ("hotZoneLeft = (document." + menuName + ".left) - hotZoneBorder");
	eval ("hotZoneTop = (document." + menuName + ".top) - hotZoneBorder");
  }
  hotZoneRight = hotZoneLeft + menuWidth + (hotZoneBorder*2);
  hotZoneBottom = hotZoneTop + menuHeight + (hotZoneBorder*2);
}

function hideMenu() {
  setTimeout("hideIt()",menuHideTimeoutMS);
}

function hideIt() {
  if(activeMenu > 0 && mouseOnMenu == 0){
	var menuName = "menuNum" + activeMenu;
    eval ("MM_showHideLayers('" + menuName + "','','hide')");
    if (document.all) {
	  eval ("document.all." + menuName + ".style.left = activeMenuStartPos");
    } else {
	  eval ("document." + menuName + ".left = activeMenuStartPos");
	  eval ("document." + menuName + ".top = (document." + menuName + ".top) + NSvOffset");
    }
	for(i=0;i<numOfMenus;i++) {
	  menuToHide = "menuNum" + (i+1);
	  eval ("MM_showHideLayers('" + menuToHide + "','','hide')");
	}
    setActiveMenu(0);
    hotZoneLeft = 0;
  }
}

function hideAll() {
  if(activeMenu > 0){
    var menuName = "menuNum" + activeMenu;
    eval ("MM_showHideLayers('" + menuName + "','','hide')");
    if (document.all) {
      eval ("document.all." + menuName + ".style.left = activeMenuStartPos");
    } else {
      eval ("document." + menuName + ".left = activeMenuStartPos");
      eval ("document." + menuName + ".top = (document." + menuName + ".top) + NSvOffset");
    }
    setActiveMenu(0);
    for(i=0;i<numOfMenus;i++) {
      menuToHide = "menuNum" + (i+1);
      eval ("MM_showHideLayers('" + menuToHide + "','','hide')");
    }
  }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0

function getMouseXY(e) {
  if (IE) {
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {
    tempX = e.pageX
    tempY = e.pageY
  }  

  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  mouseX = tempX;
  mouseY = tempY;
  if (hotZoneLeft > 0) {
	if (tempX <= hotZoneLeft || tempX >= hotZoneRight || tempY <= hotZoneTop || tempY >= hotZoneBottom) {
	  // specifically for this site, we need a second hotzone to the left of the menu
	  if (tempX <= (hotZoneLeft - 111) || tempX >= (hotZoneRight-141) || tempY <= hotZoneTop || tempY >= hotZoneBottom) {
	    mouseOnMenu = 0;
	    hideMenu();
      } else {
	    mouseOnMenu = 1;
	  }
    } else {
	  mouseOnMenu = 1;
	}
  }
  return true;
}