/*
    Script: menu_swap.js

    Copyright: Fishnet NewMedia (c) 2003

    Create: 01.02.04

    Version: 1.0

    Compatibility: JavaScript 1.2

    Scripts: none

    Changes: none

    Description: 

        This script initializes and executes two different
        document event handlers: onmouseover & onmouseout.
        Each event is assigned a function (method) to show
        or hide a subnavigation when the event is triggered
        by a supported DOM element.

*/

// Parse the navigator object for browser type and platform for compatibility
// Supported browsers include MSIE version 5+ and Netscape with Gecko version 1+

var useragent = navigator.userAgent;   // user agent string for the current browser.
var browser = navigator.appName;       // official name of the current browser
var platform = navigator.platform;     // platform on which the current browser is running
var product = navigator.product;       // product name of the current browser - for Netscape
var productsub = navigator.productSub; // build number of the current browser - for Netscape

var N = 0;   // Netscape
var M = 0;   // MSIE

if (product == "Gecko" && Number(productsub) > 20020605){
   // Netscape with Gecko >= 1.0
   // supported browser
   N = 1;
}
else if (browser == "Microsoft Internet Explorer" && document.getElementById) {
   // MSIE version 5+
   // check platform
   if (platform.substring(0,3) == "MacPPC"){
       // Macintosh
       // check version
       if(/MSIE ([0-9\.]+)/.test(useragent) && Number(RegExp.$1) >= 5.1){
           // Mac MSIE version >= 5.1
           // supported browser
           M = 1;
       }
       else{
           // Mac MSIE version < 5.1
           // unsupported browser
           M = 0;
       }
   }
   else{
       // Win MSIE version 5+
       // supported browser
       M = 1;
   }
}
else {
   // Not MSIE 5+ or Netscape with Gecko 1+
   // unsupported browser
   M = 0;
   N = 0;
}

function ShowNav(evnt) {
   // the argument "evnt" is the event object for the event
   // the event object contains properties that describe a 
   // javascript event, and is passed as an argument to an 
   // event handler when the event occurs
   if (M) {
      // create reference to the event actuator object
      actuator = window.event.srcElement;
   }
   else if (N) { 
      // create reference to the event actuator object
      actuator = evnt.target;
   }

   // bubble up through each DOM element starting from 
   // actuator element through each ancestors elements
   loop:
   while (actuator){
      // ignore all events from non-menu DOM elements
      var id;
      for (id in menu_ids){
         // ignore all non-menu elements
         if (actuator.className && actuator.className.indexOf(menu_ids[id]) != -1){
            if (document.getElementById(menu_ids[id])){
               document.getElementById(menu_ids[id]).style.visibility = "visible";
               break loop; // exit the "bubble" loop
            }
         }
      }
      actuator = actuator.parentNode;
   }
}

function HideNav() {
   var id;
   for (id in menu_ids){
      if (document.getElementById(menu_ids[id])){
         document.getElementById(menu_ids[id]).style.visibility = "hidden";
      }
   }
}

function InitNav() {
   if (N){
      // capture all of the following events
      if (document.captureEvents) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
   }
   // initialize event handlers
   document.onmouseover = ShowNav;    // show the navigation
   document.onmouseout = HideNav;     // hide the navigation
}