//// code for pop-up menus on projects page
// altered for Truant, 3/06

// how it works:
//  When the mouse passes over one of the menu launch buttons, it calls
//   show_menu_exclusive() to swap the button image, open that button's pop-up menu,
//   and close any others that might be open.
//  When the mouse leaves the nav button, it starts a delayed restore of the button image
//   and 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

// variables record which menu is currently open
var open_menu_divid = "";   // id of menu div
var open_menu_imgid = "";   // id of image button that opened menu

// timer for delayed hide
var timerid = null;

// browser identification
var NS4 = document.layers;

//// functions

// show main nav mouseover and corresponding pop-up menu (immediately hide previous, if any)
//
function show_menu_exclusive(menuid, buttonid) {
  if (NS4)
    return;

  if (timerid != null) {        // cancel any delayed hides
    clearTimeout (timerid);
    timerid = null;
  }

  if (open_menu_divid == menuid)  // return if this menu already open
    return;

  if (open_menu_divid != "") {      // restore main navigation button
    // find image object
    var oldnavobj = MM_findObj(open_menu_imgid);
    if (oldnavobj != null) {
      // get image src
      var src = oldnavobj.src;
      // replace "_mo.gif" with ".gif"
      var i = src.lastIndexOf("_mo.gif");
      if (i >= 0) {
        src = src.substring(0,i)+".gif";
      }
      // swap back unhighlighted image
      oldnavobj.src = src;
    }
    // hide the old pop-up menu
    MM_showHideLayers(open_menu_divid,'','hide')
  }

  // swap in new menu button rollover and show pop-up menu

  if (buttonid != "") {
    // find image object
    var navobj = MM_findObj(buttonid);
    if (navobj != null) {
      // get image src
      var src = navobj.src;
      // replace ".gif" with "_mo.gif"
      // (but make sure we're not already showing _mo.gif)
      var i = src.lastIndexOf("_mo.gif");
      if (i < 0) {
        i = src.lastIndexOf(".gif");
        if (i >= 0) {
          src = src.substring(0,i)+"_mo.gif";
        }
      }
      // swap back unhighlighted image
      navobj.src = src;
    }
    // show the new pop-up menu
    MM_showHideLayers(menuid,'','show')
  }

  // record the open menu
  open_menu_divid = menuid;
  open_menu_imgid = buttonid;
}

// start delayed main nav image restoration and pop-up menu hiding
//
function start_delayed_hide_menu() {
  if (NS4)
    return;

  timerid = setTimeout("do_delayed_hide_menu()", 250); // last arg is delay in milliseconds
}

// cancel delayed main nav image restoration and pop-up menu hiding
//
function cancel_delayed_hide_menu() {
  if (NS4)
    return;

  if (timerid != null) {
    clearTimeout (timerid);
    timerid = null;
  }
}

// perform delayed main nav image restoration and pop-up menu hiding
//
function do_delayed_hide_menu() {
  if (NS4)
    return;

  show_menu_exclusive("", "");
}
