var timer = "";
var openMenu = null;

/* d closes all menus and drops the selected one */
function d(id, containerId){
  if (document.getElementById){
    window.clearTimeout(timer);
    document.getElementById('nav1').style.display = 'none';
    document.getElementById('nav2').style.display = 'none';
    document.getElementById('nav3').style.display = 'none';
    document.getElementById('nav4').style.display = 'none';
    
	document.getElementById('subnav1').style.display = 'none';
	document.getElementById('subnav2').style.display = 'none';
	document.getElementById('subnav3').style.display = 'none';
	document.getElementById('subnav4').style.display = 'none';
	document.getElementById('subnav5').style.display = 'none';
    
    
    
    var dropDownItem = document.getElementById(id);

    var parentItem = document.getElementById(containerId);
    var location = getPageXY(parentItem);
    
    dropDownItem.style.left = location.x + 30 + 'px'; //30 is for the margin on the items
    dropDownItem.style.top = location.y + parentItem.offsetHeight + 'px';
    //alert(parentItem.offsetHeight);
    //setPageXY(dropDownItem, location.x, location.y);
    dropDownItem.style.display = 'block';
    
    //alert('x: ' + dropDownItem.style.top + ' y: ' + dropDownItem.style.left);
    //alert(location.x + 'y: ' + location.y);
    openMenu = id;
  }
}

/* h holds the menu open */
function h(id){
  openMenu = id;
}

/* t tries to close the menu */
function t(id){
  if (document.getElementById){
    openMenu = null;
    var funcToCall = "closeMenu('"+id+"')"
    timer = setTimeout(funcToCall, 600);
  }
}

/* closeMenu closes the menu if it's not held open */
function closeMenu(id){
  if (document.getElementById){
    if (openMenu == null)
     document.getElementById(id).style.display = 'none';
  }
}






////////////////////////////////

function getPageXY(elm)
{
  var point = { x: 0, y: 0 };
  while (elm)
  {
    point.x += elm.offsetLeft;
    point.y += elm.offsetTop;
    elm = elm.offsetParent;
  }
  return point;
}

function setPageXY(elm, x, y)
{
  var parentXY = {x: 0, y: 0 };

  if (elm.offsetParent)
  {
    parentXY = getPageXY(elm.offsetParent);
  }

  elm.style.left = (x - parentXY.x) + 'px';
  elm.style.top  = (y - parentXY.y) + 'px';
}