/*
  Created:   2000-10-21
  Issued:    2001-01-11
  Modified:  2005-02-23

  Copyright (c) 2001-2005 by Philip Shaw <phil@codestyle.org>

  This work is licensed under the Creative Commons
  Attribution-NonCommercial-ShareAlike License.
  To view a copy of this license, visit
  http://creativecommons.org/licenses/by-nc-sa/2.0/
  or send a letter to Creative Commons, 559 Nathan
  Abbott Way, Stanford, California 94305, USA.
*/

/*
  Successfully debugged for:
   Mozilla M15
   Netscape 3, 4.5, 6.0
   Internet Explorer 4.0 5.0, 5.5
   Opera 3.62, 4.0, 5.0, 5.11, 6.0
*/

// Declare the number of menus
// N.B. Add menu IDs and adjust
// widths of divs in stylesheet:
// visibility-HorizontalMenus.css
///////////////////////////////////////

// Global number for total menus:
///////////////////////////////////////
var totalmenus = 9;

// Global number for counting the tab
// sequence
///////////////////////////////////////
var tabcount = 0;

// Global string for menu output:
///////////////////////////////////////
var menutxt = '';

// Global array for menu data:
///////////////////////////////////////
var menu = new makeArray(totalmenus);

// Custom array constructor,
// indexed from 1:
///////////////////////////////////////
function makeArray(n){
  this.size = n;
  for(i=1; i<=n; i++){
    this[i] = 0;
  }
  return(this);
}

// Menu group constructor:
///////////////////////////////////////
function menuObject(n,MenuTitle,MenuURL){
  this.size =       n;
  this.MenuTitle =  MenuTitle;
  this.MenuURL =    MenuURL;
  this.Bullet =     new makeArray(n);
}

// Menu item constructor:
///////////////////////////////////////
function bulletObject(BulletTitle,BulletURL){
  this.BulletTitle =  BulletTitle;
  this.BulletURL =    BulletURL;
}

// Define menus. Add new items by
// increasing menu bullets argument
// and adding a new indexed bullet
// object to the end of the list.
//
// Menu arguments:
// 1 = No. of bullets
// 2 = Menu title
// 3 = Menu URL

// Bullet arguments:
// 1 = Bullet title
// 2 = Bullet URL
///////////////////////////////////////


// Base directory
///////////////////////////////////////
var base_dir = "/projects/sanger/";


// First menu
///////////////////////////////////////
menu[1] = new menuObject(4,'About Margaret Sanger*',base_dir + 'secure/aboutms/index.html');
menu[1].Bullet[1] = new bulletObject('Biographical sketch',base_dir + 'secure/aboutms/index.html');
menu[1].Bullet[2] = new bulletObject('Birth Control Organizations',base_dir + 'secure/aboutms/bc_organizations.html');
menu[1].Bullet[3] = new bulletObject('The Sanger Archive',base_dir + 'secure/aboutms/sanger_archive.html');
menu[1].Bullet[4] = new bulletObject('Sanger\'s Writings',base_dir + 'secure/aboutms/ms_writings.html');


// Second menu
///////////////////////////////////////
menu[2] = new menuObject(7,'About the Project',base_dir + 'aboutmspp/index.html');
menu[2].Bullet[1] = new bulletObject('About',base_dir + 'aboutmspp/index.html');
menu[2].Bullet[2] = new bulletObject('Staff',base_dir + 'aboutmspp/staff.html');
menu[2].Bullet[3] = new bulletObject('Internships',base_dir + 'aboutmspp/internships.html');
menu[2].Bullet[4] = new bulletObject('Support',base_dir + 'aboutmspp/support.html');
menu[2].Bullet[5] = new bulletObject('Funders',base_dir + 'aboutmspp/funders.html');
menu[2].Bullet[6] = new bulletObject('Reviews',base_dir + 'aboutmspp/reviews.html');
menu[2].Bullet[7] = new bulletObject('Editing at the MSPP',base_dir + 'aboutmspp/editing_at_mspp.html');

// Third menu
///////////////////////////////////////
menu[3] = new menuObject(3,'Publications',base_dir + 'publications/index.html');
menu[3].Bullet[1] = new bulletObject('About',base_dir + 'publications/index.html');
menu[3].Bullet[2] = new bulletObject('The Selected Papers of Margaret Sanger',base_dir + 'publications/book.html');
menu[3].Bullet[3] = new bulletObject('The Microfilm Edition',base_dir + 'publications/microfilm.html');
/* menu[3].Bullet[4] = new bulletObject('The Electronic Edition',base_dir + 'publications/electronic_ed/on_the_web.html'); */

// Fourth menu
///////////////////////////////////////
menu[4] = new menuObject(3,'Newsletter*',base_dir + 'secure/newsletter/about.html');
menu[4].Bullet[1] = new bulletObject('About',base_dir + 'secure/newsletter/about.html');
menu[4].Bullet[2] = new bulletObject('Article List',base_dir + 'secure/newsletter/article_list.html');
menu[4].Bullet[3] = new bulletObject('Subscribe',base_dir + 'secure/newsletter/subscribe.html');

// Fifth menu
///////////////////////////////////////
menu[5] = new menuObject(5,'Documents Online*',base_dir + 'publications/electronic_ed/on_the_web.html');
menu[5].Bullet[1] = new bulletObject('About',base_dir + 'publications/electronic_ed/on_the_web.html');
menu[5].Bullet[2] = new bulletObject('Selected Writings',base_dir + 'secure/documents/documents_mspp.html');
menu[5].Bullet[3] = new bulletObject('Electronic Edition (in production)',base_dir + 'publications/electronic_ed/speeches_and_articles.html');
menu[5].Bullet[4] = new bulletObject('Margaret Sanger and the Woman Rebel',base_dir + 'publications/electronic_ed/ms_and_the_woman_rebel.html');
menu[5].Bullet[5] = new bulletObject('Documents on other sites',base_dir + 'secure/documents/documents_by_others.html');



// Sixth menu
///////////////////////////////////////
menu[6] = new menuObject(5,'Resources',base_dir + 'research/index.html');
menu[6].Bullet[1] = new bulletObject('Research Requests',base_dir + 'research/index.html');
menu[6].Bullet[2] = new bulletObject('National History Day',base_dir + 'research/history_day.html');
menu[6].Bullet[3] = new bulletObject('Sanger Bibliography',base_dir + 'research/ms_bibliography.html');
menu[6].Bullet[4] = new bulletObject('Sanger Images',base_dir + 'research/sanger_images.html');
menu[6].Bullet[5] = new bulletObject('Links',base_dir + 'research/links.html');

// Seventh menu
///////////////////////////////////////
menu[7] = new menuObject(0,'News-Sanger Sightings',base_dir + 'sightings/index.html');



// Eighth menu
///////////////////////////////////////
menu[8] = new menuObject(0,'Contact Us',base_dir + 'contact/index.html');

// Ninth menu
///////////////////////////////////////
menu[9] = new menuObject(0,'Donate Now',base_dir + 'aboutmspp/onlinedonate.html');


// Compile the static menu headings:
///////////////////////////////////////
menutxt += '<div id="LinkBar">\n';
for(i=1;i<=totalmenus;i++){
    // Increment the tabindex counter for every link
    tabcount++;

    menutxt += '\t<div id="Link' + i + '">';
    menutxt += '<a href="' + menu[i].MenuURL + '"';

    // Add an explicit tab sequence
    menutxt += ' tabindex="' + tabcount + '"';

    // Only compile the event handlers if able to handle them
    if(document.getElementById){// DOM1 compliant
      menutxt += ' onmouseover="menuOver(\'Menu' + i + '\'); return true;"';
      // To activate via tab navigation
      menutxt += ' onfocus="menuOver(\'Menu' + i + '\'); return true;"';
      menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;"';
      // To de-activate when tab focus is lost
      menutxt += ' onblur="menuOut(\'Menu' + i + '\'); return true;"';

      // Increment the tabindex to allow for the bullets
      tabcount += menu[i].Bullet.size;
    }
    menutxt += '>' + menu[i].MenuTitle + '</a>';
    menutxt += '<\/div>\n';
  }
menutxt += '<\/div>\n';

// If DOM1 compliant, add the
// drop-down menus:
///////////////////////////////////////
if(document.getElementById){// DOM1 compliant
  // Reset the tab counter
  tabcount = 0;
  menutxt += '<div id="MenuBar">\n';
  for(i=1;i<=totalmenus;i++){
    // Increment the tab counter
    tabcount++;
    menutxt += '<div id="Menu' + i + '">';
    // Build the bullet list
    menutxt += '<ul>\n\t';
    for(j=1;j<=menu[i].size;j++){
      // Increment the tab couter
      tabcount++
      menutxt += '<li><a href="' + menu[i].Bullet[j].BulletURL + '"';
      menutxt += ' onmouseover="stayOpen(\'Menu' + i + '\'); return true;"';
      menutxt += ' onfocus="stayOpen(\'Menu' + i + '\'); return true;"';
      menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;"';
      menutxt += ' onblur="menuOut(\'Menu' + i + '\'); return true;"';
      // Add an explicit tab sequence
      menutxt += ' tabindex="' + tabcount + '"';
      menutxt += '>' + menu[i].Bullet[j].BulletTitle;
      menutxt += '<\/a><\/li>';
    }
    menutxt += '<\/ul>\n<\/div>\n';
  }
  menutxt += '<\/div>\n';
}

// Global menu element handle:
///////////////////////////////////////
var LiveMenu = null;

// Global menu timeout handle:
///////////////////////////////////////
var Timeout_ID = null;

// Opens or keeps open a given menu
// and shuts any previous menu:
///////////////////////////////////////
function menuOver(MenuID){
  // If DOM1 supported and element exists ...
  if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
    // If this menu is already open ...
    if(LiveMenu==document.getElementById(MenuID)){
      // Do not close it
      clearTimeout(Timeout_ID);
    }
    // Another might still be open ...
    else{
      // If another menu is open ...
      if(LiveMenu!=null){
        // Do not wait, shut it now
        clearTimeout(Timeout_ID);
        hideNow();
      }
    }
    // This is the new 'live' menu, make it visible
    LiveMenu = document.getElementById(MenuID);
    // LiveMenu.style.visibility is
    // initially empty in IE5 until
    // it is assigned by these
    // functions, so must check that
    // it's not null before proceeding...
    if((LiveMenu.style)&&(LiveMenu.style.visibility!=null)){
      LiveMenu.style.visibility = 'visible';
    }
  }
}

// Stops menu links from opening menu
// onmouseover when shut to
// workaround mouse events which are
// not hidden by z-index in Opera 4!
///////////////////////////////////////
function stayOpen(MenuID){
  // If menuOver has not been called or the menu is hidden, do nothing
  if((LiveMenu==null)||((LiveMenu.style)&&(LiveMenu.style.visibility)&&(LiveMenu.style.visibility=='hidden')))return;
  else menuOver(MenuID);
}

// Shuts a given menu in 250
// milliseconds, unless timeout is
// cleared by menuOver()
///////////////////////////////////////
function menuOut(MenuID){
  // If DOM1 supported and a menu is open ...
  if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
    // Get the current live menu
    LiveMenu = document.getElementById(MenuID);
    // Prepare to shut it in 250 milliseconds
    Timeout_ID = window.setTimeout('hideNow();',400);
  }
}

// Called by menu handlers to shut
// previous menu immediately
///////////////////////////////////////
function hideNow(){
  if((LiveMenu.style)&&(LiveMenu.style.visibility)){
    LiveMenu.style.visibility = 'hidden';
  }
}
