/* Adapted from menuDropdown.js by Dave Lindquist (dave@gazingus.org) */
var currentMenu = null;
if (!document.getElementById)
  document.getElementById = function() { return null; }
function initializeMenu(menuitem) {
  var actuator = menuitem.getElementsByTagName('a')[0];
  var menu = menuitem.getElementsByTagName('ul')[0];
  var gone = 1;
  var beginner = 0;
  disappear = setTimeout('',100000);
  if (menu == null || actuator == null) return;
  actuator.onmouseover = function() {
    if (currentMenu == null) {
      this.showMenu();
    }
    else {
      currentMenu.style.visibility = "hidden";
      currentMenu = null;
    }
    this.showMenu();
    if (gone == 1) {
      clearInterval(disappear);
    }
    gone = 0;
    return false;
  }
  actuator.onmouseout = function() {
    gone = 1;
    disappear = setTimeout(hide,50);
  }
  hide = function() {
    currentMenu.style.visibility = "hidden";
    currentMenu = null;
  }
  actuator.showMenu = function() {
    menu.style.left = this.offsetLeft + "px";
    menu.style.top = this.offsetTop + this.offsetHeight + "px";
    menu.style.visibility = "visible";
    currentMenu = menu;
  }
  menu.onmouseover = function() {
    if (gone == 1) {
      clearInterval(disappear);
      gone = 0;
    }
  }
  menu.onmouseout = function() {
    gone = 1;
    disappear = setTimeout(hide,500);
  }
}

window.onload = function() {
  //this allows us to drill through the DOM to the actuators and menus
  //the path through the DOM to the menu
  var pt1 = document.getElementById('shortcuts').getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  //the first actuator
  var actuator1 = 0;
  initializeMenu(pt1.getElementsByTagName('li')[actuator1]);
  //to find the second actuator, we need to know the number of items in the first submenu
  var subitems1 = pt1.getElementsByTagName('li')[actuator1].getElementsByTagName('li').length;
  //the actuator is after the submenu
  var actuator2 = actuator1 + subitems1 + 1;
  initializeMenu(pt1.getElementsByTagName('li')[actuator2]);
  //to find the third actuator, we need to know the number of items in the second submenu
  var subitems2 = pt1.getElementsByTagName('li')[actuator2].getElementsByTagName('li').length;
  //the actuator is after the submenu
  var actuator3 = actuator1 + subitems1 + 1 + subitems2 + 1;
  initializeMenu(pt1.getElementsByTagName('li')[actuator3]);
}
