//
// javascript for MIT Course Catalogue home page
//



//// code for pop-up menus
// NOTE: function names have been abbreviated for this site - sme(), sdhm(), cdhm()

// how it works:
//  When the mouse passes over one of the main navigation buttons, it calls
//   show_menu_exclusive() to open that buttons's pop-up menu,
//   and close any others that might be open.
//  When the mouse leaves the nav button, it starts a delayed closing of that
//   pop-up menu by calling start_delayed_hide_menu(). The closing
//   is delayed because the mouse might be entering the pop-up menu. If not, then the menu
//   will either be closed by the delayed call to do_delayed_hide_menu(), or by entering
//   a different navigation button.
//  When the mouse enters a pop-up menu button, it cancels the delayed close of that
//   pop-up menu with cancel_delayed_hide_menu().
//  When the mouse leaves a pop-up menu button, it starts the delayed close.
//

//// globals

// variable records which menu is currently open
var open_menu = "";

// timer for delayed hide
var timerid = null;

//// functions

// show main nav mouseover and corresponding pop-up menu (immediately hide previous, if any)
//
//function show_menu_exclusive(menuname) {
function sme(menuname) {

  if (timerid != null) {        // cancel any delayed hides
    clearTimeout (timerid);
    timerid = null;
  }

  if (open_menu == menuname)  // return if this menu already open
    return;

  if (open_menu != "") {      // restore main navigation button
    // find button object
    var oldnavobj = MM_findObj(open_menu);
    // set original background color
    if (oldnavobj != null) {
      oldnavobj.className = "off";
    }
    // hide the old pop-up menu
    var oldmenu = "menu" + open_menu;
    MM_showHideLayers(oldmenu,'','hide')
  }

  // set new button rollover and show pop-up menu

  if (menuname != "") {
    // find image object
    var navobj = MM_findObj(menuname);
    if (navobj != null) {
      navobj.className = "on";
    }
    // show the new pop-up menu
    var menulayer = "menu" + menuname;
    MM_showHideLayers(menulayer,'','show')
  }

  // record the open menu
  open_menu = menuname;
}

// start delayed main nav image restoration and pop-up menu hiding
//
//function start_delayed_hide_menu() {
function sdhm() {
  timerid = setTimeout("do_delayed_hide_menu()", 50); // last arg is delay in milliseconds
}

// cancel delayed main nav image restoration and pop-up menu hiding
//
//function cancel_delayed_hide_menu() {
function cdhm() {
  if (timerid != null) {
    clearTimeout (timerid);
    timerid = null;
  }
}

// perform delayed main nav image restoration and pop-up menu hiding
//
function do_delayed_hide_menu() {
//  show_menu_exclusive("");
  sme("");
}
