/* --------------------------------- */
/* Created:      2000-10-21          */
/* Issued:       2001-01-11          */
/* Modified:     2001-07-14          */
/* Copyright (c) 2001-2004 by        */
/* Philip Shaw, all rights reserved. */
/* --------------------------------- */

///////////////////////////////////////
// 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     //
///////////////////////////////////////

// See also:
// visibility-HorizontalMenuWriter.js
///////////////////////////////////////



// Compile the static menu headings:
///////////////////////////////////////
menutxt += '<div id="LinkBar" class="LinkBar">\n';
for(i=1;i<=totalmenus;i++){

    if (menu[i].MenuURL) {

        // this in case a HREF is given with the menutitle!

            // 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';

    } else {

        // this in case NO is given with the menutitle!


            menutxt += '\t<div id="Link' + i + '" ';
            // 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;"';
            }
            menutxt += '>' + menu[i].MenuTitle + '<\/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 += '<table class="menubar" width=100% border=0 CELLSPACING=0>\n\t';
    for(j=1;j<=menu[i].size;j++){
      // Increment the tab couter
      tabcount++
      // check if this is a separator and not a real URL!
      if (menu[i].Bullet[j].BulletURL == menu[i].Bullet[j].BulletTitle) {

          menutxt += '<tr><td class="separator"';
          menutxt += ' onMouseover="stayOpen(\'Menu' + i + '\'); return true;"';
          menutxt += ' onMouseout="menuOut(\'Menu' + i + '\'); return true;"';
          menutxt += ' onfocus="stayOpen(\'Menu' + i + '\'); return true;"';
          menutxt += ' onblur="menuOut(\'Menu' + i + '\'); return true;">&nbsp;</td></tr>';

      } else {

          menutxt += '<tr><td';
          menutxt += ' onMouseover="this.style.backgroundColor=\'FFFFFF\'; stayOpen(\'Menu' + i + '\'); return true;"';
          menutxt += ' onMouseout="this.style.backgroundColor=\'CCCCCC\'; menuOut(\'Menu' + i + '\'); return true;"';
          menutxt += ' onfocus="stayOpen(\'Menu' + i + '\'); return true;"';
          menutxt += ' onblur="menuOut(\'Menu' + i + '\'); return true;"';
          tmpURL = menu[i].Bullet[j].BulletFrame;
          if (tmpURL=="_blank") {
              menutxt += ' onClick="window.open=\'' + menu[i].Bullet[j].BulletURL + '\';">';
          } else {
              menutxt += ' onClick="window.' + menu[i].Bullet[j].BulletFrame + '.location.href=\'' + menu[i].Bullet[j].BulletURL + '\';">';
          }
          menutxt += '<a class="menubar" href="' + menu[i].Bullet[j].BulletURL + '" target="' + menu[i].Bullet[j].BulletFrame + '"';
    
          // Add an explicit tab sequence
          menutxt += ' tabindex="' + tabcount + '"';
    
          menutxt += '>' + menu[i].Bullet[j].BulletTitle;
          menutxt += '</td></tr>\n\t';

      }
    }
    menutxt += '</table>\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();',250);
  }
}

// Called by menu handlers to shut
// previous menu immediately
///////////////////////////////////////
function hideNow(){
  if((LiveMenu.style)&&(LiveMenu.style.visibility)){
    LiveMenu.style.visibility = 'hidden';
  }
}
