//// MechE popup menus for interior pages//// The first part of the code below reads the menu data from an xml file// and generates the menus. It relies on the function in importxml.js to read// the XML file. The XML file is the same one used by the Flash movie on the// home page.//// The second part of the code below performs the popups.////////////////////////////////////////////////////////////////////////// read the menus from this file...var menufile = "/xml/nav.xml";//////////////////////////////////////////////////////////////////////// object containing XML documentvar xmlDoc = null;// flag to indicate whether menus are ready for usevar menusloaded = false;// write divs for menus and load menu XML data// (call this from HTML file)function init_menus() {  write_menu_containers();  importXML(menufile, 'write_menus');}// write divs to contain menusfunction write_menu_containers() {	document.writeln("<div id='divmenuabout' class='divpopupmenu'></div>");	document.writeln("<div id='divmenumembers' class='divpopupmenu'></div>");	document.writeln("<div id='divmenuresources' class='divpopupmenu'></div>");	document.writeln("<div id='divmenupublications' class='divpopupmenu'></div>");	document.writeln("<div id='divmenuevents' class='divpopupmenu'></div>");	document.writeln("<div id='divmenucenter' class='divpopupmenu'></div>");	document.writeln("<div id='divmenugroups' class='divpopupmenu'></div>");}// this array maps the menu groups in the XML file to the menu div idsvar xmltodiv = new Array();xmltodiv['About'] = 'divmenuabout';xmltodiv['Members'] = 'divmenumembers';xmltodiv['Resources'] = 'divmenuresources';xmltodiv['Publications'] = 'divmenupublications';xmltodiv['Events'] = 'divmenuevents';xmltodiv['Centers'] = 'divmenucenter';xmltodiv['Local Groups'] = 'divmenugroups';// when XML data is ready, write the menusfunction write_menus(doc) {	xmlDoc = doc;  // get list of menus	var mainnav = xmlDoc.getElementsByTagName('mainNav');	// iterate through list of menus	for (i = 0; i < mainnav.length; i++) {		// write individual menu		write_menu(mainnav[i]);	}}// write a single menufunction write_menu(mainnavitem) {	var mainnavtitle = mainnavitem.getAttribute('title');	var menudivid = xmltodiv[mainnavtitle];	var menudiv = document.getElementById(menudivid);  // get list of menu items	var subnav = mainnavitem.getElementsByTagName('item');  // create an unordered list containing the menu items	// NOTE: at present, items are in reverse order in the XML file	var ul = document.createElement('ul');	for (j = subnav.length-1; j >= 0; j--) {		var title = subnav[j].getAttribute('title');		var url = subnav[j].getAttribute('url');		var li = document.createElement('li');		var a = document.createElement('a');		var txt = document.createTextNode(title);		a.setAttribute('href', url);//		a.setAttribute('onmouseover', 'cancel_delayed_hide_menu()');//		a.setAttribute('onmouseout', 'start_delayed_hide_menu()');		if (a.addEventListener) {			a.addEventListener('mouseover', cancel_delayed_hide_menu, false);			a.addEventListener('mouseout', start_delayed_hide_menu, false);		}		else if (a.attachEvent) {			a.attachEvent('onmouseover', cancel_delayed_hide_menu);			a.attachEvent('onmouseout', start_delayed_hide_menu);		}		if (j == 0) {  		a.className = 'last';		}		else if (j == subnav.length - 1) {  		a.className = 'first';		}		a.appendChild(txt);		li.appendChild(a);		ul.appendChild(li);	}		menudiv.appendChild(ul);// set flag so popup routines know it's okay to proceed	menusloaded = true;}//// code for popping the 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.//////// globals// variable records which menu is currently openvar open_menu = "";// timer for delayed hidevar timerid = null;// delay before menu disappears, in ms (you can change this)var delayinterval = 250;//// functions// show main nav mouseover and corresponding pop-up menu (immediately hide previous, if any)//function show_menu_exclusive(menuname) {  if (!menusloaded)	  return;  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("n1"+open_menu);    // replace the original image    if (oldnavobj != null) {      if (oldnavobj.originalsrc) {        oldnavobj.src = oldnavobj.originalsrc;      }    }    // hide the old pop-up menu    var oldmenulayer = "divmenu" + 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("n1"+menuname);    if (navobj != null) {      // get image src      var src = navobj.src;      // stash it for later replacement      navobj.originalsrc = src;      // replace ".gif" or "_on.gif" with "_ro.gif"      // (but make sure we're not already showing _ro.gif)      var i = src.lastIndexOf("_ro.gif");      if (i < 0) {        i = src.lastIndexOf("_on.gif");        if (i >= 0) {          src = src.substring(0,i)+"_ro.gif";        }				else {          i = src.lastIndexOf(".gif");          if (i >= 0) {            src = src.substring(0,i)+"_ro.gif";          }				}      }      // swap in highlighted image      navobj.src = src;    }    // show the new pop-up menu    var menulayer = "divmenu" + 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() {  if (!menusloaded)	  return;  timerid = setTimeout("do_delayed_hide_menu()", delayinterval); // last arg is delay in milliseconds}// cancel delayed main nav image restoration and pop-up menu hiding//function cancel_delayed_hide_menu() {  if (!menusloaded)	  return;  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("");}