/* Menu JS */

//
// Add hooks to menu items
//
var hoverCounter = 0;
var menuTimers = [];
var MENU_DELAY = 600;

//
// Clears any timeouts for this menu index
//
function ClearTimeout(menuIndex) {
  if (menuTimers[menuIndex]) {
    clearTimeout(menuTimers[menuIndex]);
  }
}

$(document).ready(function() {
  //
  // Handle menu level 1 hover...
  //
  $("#menu ul.menuLevel1 > li").hover(
    // Mouse over
    function() {
      ClearTimeout(this.id);
      menuTimers[this.id] = setTimeout('$("#' + this.id + '").addClass("menuHover");', MENU_DELAY);
    },
    // Mouse out
    function() {
      ClearTimeout(this.id);
      menuTimers[this.id] = setTimeout('$("#' + this.id + '").removeClass("menuHover");', MENU_DELAY);
    }
  );

  //
  // Handle menu level 2 hover...
  //
  $("#menu ul.menuLevel2 > li").hover(
    // Mouse over
    function() {
      ClearTimeout(this.id);
      menuTimers[this.id] = setTimeout('$("#' + this.id + '").addClass("menuHover");', MENU_DELAY);
    },
    // Mouse out
    function() {
      ClearTimeout(this.id);
      menuTimers[this.id] = setTimeout('$("#' + this.id + '").removeClass("menuHover");', MENU_DELAY);
    }
  );

  //
  // Handle tabbing into menu level 1 items...
  //
  $("#menu ul.menuLevel1 > li a.l1a").focus(function() {
    if (!$(this).parent().hasClass("menuHover")) {
      $(this).parent().addClass("menuHover");
    }
  });

  //
  // Handle tabbing out of menu level 1 items...
  //
  $("#menu ul.menuLevel1 > li a.l1a").blur(function() {
    if ($(this).parent().hasClass("menuHover")) {
      $(this).parent().removeClass("menuHover");
    }
  });

});