﻿// JScript File
function initiateMenuBar() {
   if (document.getElementById) {
      var mapIds = initiateMenuBar.arguments;    // pass string IDs of containing map elements
      var i, j, area, areas;
      for (i = 0; i < mapIds.length; i++) {
        if (document.getElementById(mapIds[i]))
        {
          areas = document.getElementById(mapIds[i]).getElementsByTagName("area");

          for (j = 0; j < areas.length; j++) {  // loop thru area elements
             area = areas[j];
             area.onmouseout = imgSwap;   // set event handlers
             area.onmouseover = imgSwap;  // set event handlers
          }
        }
      }
   }
}

// image swapping event handling
function imgSwap(evt) {
   evt = (evt) ? evt : event;                   // equalize event models
   var elem = (evt.target) ? evt.target : evt.srcElement;
   var imgClass = elem.parentNode.name;         // get map element name
   var coords = elem.coords.split(",");         // convert coords to clip
   var clipVal = "rect(" + coords[1] + "px " +
                           coords[2] + "px " +
                           coords[3] + "px " +
                           coords[0] + "px)";
   var imgStyle;
   
   switch (evt.type) {
      case "mouseout" :
         document.getElementById(imgClass + "_over").style.visibility = "hidden";
         break;
      case "mouseover" :
         imgStyle = document.getElementById(imgClass + "_over").style;
         imgStyle.clip = clipVal;
         imgStyle.visibility = "visible";
         break
   }
   evt.cancelBubble = true;
   return false;
}

function setSelectedMenuItem(menuBar, selectedId)
{
  var area = document.getElementById(selectedId);
  if (area)
  {
    var coords = area.coords.split(",");         // convert coords to clip
    var clipVal = "rect(" + coords[1] + "px " +
                            coords[2] + "px " +
                            coords[3] + "px " +
                            coords[0] + "px)";
    if (document.getElementById(menuBar))
    {
      var imgStyle = document.getElementById(menuBar).style;
      imgStyle.clip = clipVal;
      document.getElementById(menuBar).style.visibility = 'visible';
    }
  }
}