//// code for pop-up menus

// how it works:
//  When the mouse passes over a menu-inducing navigation button, 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.

// Copyright (C) 2002 Robert J. Wilt

//// globals

// variable records which menu is currently open
var open_menu = "";

// timer for delayed hide
var timerid = null;

// browser
var NS = (navigator.appName == "Netscape");
IE4 = document.all; NS4 = document.layers; NS6a = document.getElementById;
if (NS6a && NS) {NS6=1;} else {NS6=0;}
if ((IE4) || (NS4) || (NS6)) {dhtml=1;}

//// functions

// show main nav mouseover and corresponding pop-up menu (immediately hide previous, if any)
//
function show_menu_exclusive(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
    
    if (open_menu != currentsection) {
      // find image object
      var oldnavobj = MM_findObj(open_menu);
      // create image sources
      var oldnavimgsrc = imagedirprefix + "nav/" + open_menu + ".gif";
      // swap the images
      if (oldnavobj != null) oldnavobj.src = oldnavimgsrc;
    }
    // hide the old pop-up menu
    var oldmenulayer = open_menu + "menu";
    MM_showHideLayers(oldmenulayer,'','hide')
  }

  // swap in new menu button rollover and show pop-up menu

  if (menuname != "") {
    if (menuname != currentsection) {
      // find image object
      var navobj = MM_findObj(menuname);
      // create image source
      var navimgsrc = imagedirprefix + "nav/" + menuname + "_hi.gif";
      // swap the image
      if (navobj != null) navobj.src = navimgsrc;
      
    }
    // show the new pop-up menu
    var menulayer = menuname + "menu";
    position_and_show(menulayer);
  }

  // record the open menu
  open_menu = menuname;
  
}




// start delayed main nav image restoration and pop-up menu hiding
//
function start_delayed_hide_menu() {
  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() {
  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("");
}

// utilities

function position_and_show(menulayer) {
  
  var obj;
  if ((obj=MM_findObj(menulayer))!=null) {
    
    if (obj.style) { obj=obj.style; }
    var minwidth =745;   // the minimum width
    var newwidth = minwidth;
    var newleft = 542; // the left position of the layer when the content is flush left is 542
    if (IE4) {
      newwidth = (document.body.clientWidth > minwidth ? document.body.clientWidth : minwidth);
      newleft = newleft + Math.floor(newwidth-minwidth);
    }
    else if (NS4 || NS6) {
      var innerWidth2 = innerWidth - 20; // subtract approx. width of scrollbar (varies from system to system)
      newwidth = (innerWidth2 > minwidth ? innerWidth2 : minwidth);
      newleft = newleft + Math.floor(newwidth-minwidth);
    }
    //else if (NS6) {
    //  newwidth = (innerWidth > minwidth ? innerWidth : minwidth);
    //  newleft = newleft + Math.floor(newwidth-minwidth);
    //}
    if (IE4 || NS6) {
      newleft = ""+newleft+"px";
    }
    obj.left = newleft;
    MM_showHideLayers(menulayer,'','show');
  }
}
