//// code for pop-up menus

// how it works:
//  When the mouse passes over one of the main navigation 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.
//
//  In addition, the current section's menu is opened when no other menu is active.
//

//// 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) {

  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 image object
    var oldnavobj = MM_findObj(open_menu);
    if (oldnavobj != null) {
      // get image src
      var src = oldnavobj.src;
      // replace "_on.gif" with "_off.gif"
      var i = src.lastIndexOf("_on.gif");
      if (i >= 0) {
        src = src.substring(0,i)+"_off.gif";
      }
      // swap back unhighlighted image
      oldnavobj.src = src;
    }
    // hide the old pop-up menu
    var oldmenulayer = "menu" + open_menu;
    MM_showHideLayers(oldmenulayer,'','hide')
  }

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

  if (menuname != "") {
    // find image object
    var navobj = MM_findObj(menuname);
    if (navobj != null) {
      // get image src
      var src = navobj.src;
      // replace "_off.gif" with "_on.gif"
      var i = src.lastIndexOf("_off.gif");
      if (i >= 0) {
        src = src.substring(0,i)+"_on.gif";
      }
      // swap back unhighlighted image
      navobj.src = src;
    }
    // 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() {
  timerid = setTimeout("do_delayed_hide_menu()", 200); // 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("");
}


//
// WRITE THE MENUS
//  Note: this uses site-relative links
//
function write_menu() {
  document.write("<div id=\"menuservices\">");
  document.write("<a href=\"/public-speaking-training.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('public','','/img/servmenu/public_on.gif',1)\"><img src=\"/img/servmenu/public_off.gif\" alt=\"\" name=\"public\" width=\"188\" height=\"45\" border=\"0\" id=\"public\"></a><br>");
  document.write("<a href=\"/fear-public-speaking.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('conquer','','/img/servmenu/conquer_on.gif',1)\"><img src=\"/img/servmenu/conquer_off.gif\" alt=\"\" name=\"conquer\" width=\"188\" height=\"45\" border=\"0\" id=\"conquer\"></a><br>");
  document.write("<a href=\"/executive-speech-coach.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('executive','','/img/servmenu/executive_on.gif',1)\"><img src=\"/img/servmenu/executive_off.gif\" alt=\"\" name=\"executive\" width=\"188\" height=\"29\" border=\"0\" id=\"executive\"></a><br>");
  document.write("<a href=\"/leadership-training-communications.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('presence','','/img/servmenu/presence_on.gif',1)\"><img src=\"/img/servmenu/presence_off.gif\" alt=\"\" name=\"presence\" width=\"188\" height=\"45\" border=\"0\" id=\"presence\"></a><br>");
  document.write("<a href=\"/sales-presentation-training.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('salestalk','','/img/servmenu/salestalk_on.gif',1)\"><img src=\"/img/servmenu/salestalk_off.gif\" alt=\"\" name=\"salestalk\" width=\"188\" height=\"29\" border=\"0\" id=\"salestalk\"></a><br>");
  document.write("<a href=\"/public-speaking-women.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('women','','/img/servmenu/women_on.gif',1)\"><img src=\"/img/servmenu/women_off.gif\" alt=\"\" name=\"women\" width=\"188\" height=\"45\" border=\"0\" id=\"women\"></a><br>");
  document.write("<a href=\"/public-speech-improvement.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('speech','','/img/servmenu/speech_on.gif',1)\"><img src=\"/img/servmenu/speech_off.gif\" alt=\"\" name=\"speech\" width=\"188\" height=\"29\" border=\"0\" id=\"speech\"></a><br>");
  document.write("<a href=\"/media-training-coach.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('media','','/img/servmenu/media_on.gif',1)\"><img src=\"/img/servmenu/media_off.gif\" alt=\"\" name=\"media\" width=\"188\" height=\"29\" border=\"0\" id=\"media\"></a><br>");
  document.write("<a href=\"/diplomatic-speeches-communications.html\" onmouseout=\"MM_swapImgRestore();start_delayed_hide_menu()\" onmouseover=\"cancel_delayed_hide_menu();MM_swapImage('political','','/img/servmenu/political_on.gif',1)\"><img src=\"/img/servmenu/political_off.gif\" alt=\"\" name=\"political\" width=\"188\" height=\"45\" border=\"0\" id=\"political\"></a></div>");
}

function preload_menu_mouseovers() {
  MM_preloadImages('/PSI/img/servmenu/public_on.gif','/PSI/img/servmenu/conquer_on.gif','/img/servmenu/executive_on.gif','/img/servmenu/sales_on.gif','/img/servmenu/film_on.gif','/img/servmenu/women_on.gif','/img/servmenu/speech_on.gif','/img/servmenu/media_on.gif','/img/servmenu/political_on.gif');
}

