function SetupMenu() {
  if (!document.getElementsByTagName) return;
  items = getElementsByClassName("menu");
  for (i = 0; i < items.length; i++) {
    thelink = findChild(items[i],"A");
    thelink.onmouseover = ShowMenu;
    thelink.onmouseout = StartTimer;
    if (ul = findChild(items[i],"UL")) {
      ul.style.display = "none";
      for (j = 0; j < ul.childNodes.length; j++) {
        ul.childNodes[j].onmouseover = ResetTimer;
        ul.childNodes[j].onmouseout = StartTimer;
      }
    }
  }
  var noLink = getElementsByClassName("noLink");
  var currentAddress = window.location.href;
  for (i = 0; i < noLink.length; i++) {
    noLink[i].setAttribute("href", currentAddress);
  }
}

function findChild (obj, tag) {
  cn = obj.childNodes;
  for (k = 0; k < cn.length; k++) {
    if (cn[k].nodeName == tag) return cn[k];
  }
  return false;
}

function ShowMenu(e) {
  if (!e) var e = window.event;
  thislink = (e.target) ? e.target: e.srcElement;
  ResetTimer();
  if (current) HideMenu(current);
  thislink = thislink.parentNode;
  current = thislink;
  ul = findChild (thislink, "UL");
  if (!ul) return;
  ul.style.display = "block";
}

function HideMenu (thelink) {
  ul = findChild (thelink, "UL");
  if (!ul) return;
  ul.style.display = "none";
}

function ResetTimer () {
  if (timer) window.clearTimeout(timer);
}

function StartTimer () {
  timer = window.setTimeout ("HideMenu(current)", 500);
}

var timer = false, current;

// Onload
if (window.addEventListener) {
  window.addEventListener('load', SetupMenu, false);
}
else if (window.attachEvent) {
  window.attachEvent('onload', SetupMenu);
}
else {
  window.onload = SetupMenu;
}
