// My Menu JavaScript File - COPYRIGHT INFORMATION
// This entire file is copyright to Envision Information Technologies, Copyright 2007
// Any use of this code is forbidden without direct authorization from Envision Information Technologies
// Code may not be copied, modified, or used without direct authorization from Envision Information Technologies
// Envision Information Technologies, Madison, WI
// info@nvsn-it.com   http://www.nvsn-it.com   608-256-5680

// Things to do
// - Ability to leave a certain menuObject open, *or* leave the menuObject of the active menuObject open (see http://www.deltanoid.com/board.html)
// - Have a menuObject expanded class - change the menuObject item class when it's menuObject is expanded
var agt=navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

var allMenus = new Array();       // this is an array which contains all of the MyMenu classes
var hideMenuTimeout = 200;        // the timeout, in ms, to wait before hiding the menuObject on onmouseout
var fadeInterval = 20;            // the timeout, in ms, to wait between each fade increment
var fadeDelta = 25;               // percentage of alpha value to change each step

// MyObject is the parentMenu object that all objects will inherit from
// Provides the "parseProperties" method which parses the properties passed to the constructor of the object
function MyObject()
{
  this.objectType = "MyObject";
  this.parseProperties = function()
  {
    for (var property in this.properties)
    {
      if (typeof(this.properties[property]) == "string")
        eval ("this." + property + " = '" + this.properties[property].replace(/'/g,"&#39;") + "';");
      else
        eval ("this." + property + " = " + this.properties[property] + ";");
    };
  };
};

// Supported properties to pass to this constructor:
// - 'orient': "horizontal" or "vertical", the orientation to display the menuObject items
// - 'placementid': The ID of an object where the menus will be placed
// - 'usealpha': Indicates if fading should be used for showing/hiding menus, defaults to true
function MenuContainer(vars)
{
  this.menus = new Array();     // this is an array which contains all of the menuObject items
  this.properties = vars;       // this contains all of the properties passed in the constructor - these are all assigned to this class by myObject
  this.placement = undefined;   // This is the placement element
  
  this.parseProperties();

  this.objectType = 'MenuContainer';    // This is the type of the object, for reference purposes
  
  if (this.usealpha == undefined || (this.usealpha != true && this.usealpha != false))
  {
    this.usealpha = false;
  };
  
  // can not execute if no placementid
  if (this.placementid == undefined || document.getElementById(this.placementid) == undefined)
  {
    alert("Either no placement-item or an invalid placement-item was defined");
    return;
  };
  
  // make sure a valid value is set for orient
  if (this.orient == undefined)
  {
    this.orient = "horizontal";
  };
  
  this.orient = this.orient.toLowerCase();
  
  if (this.orient != "vertical" && this.orient != "horizontal")
  {
    this.orient = "horizontal";
  };
  
  // set the placement element
  this.placement = document.getElementById(this.placementid);
  
  this.addMenu = function(myMenu)
  {
    myMenu.menuContainerObject = this;
    this.menus.push(myMenu);
  };
  
  this.draw = function()
  {
    var place = document.getElementById(this.placementid);
      
    var drawX = getLeft(place);
    var drawY = getTop(place);
    
    var drawHeight = 0;
    var drawWidth = 0;

    place.menuContainerObject = document.createElement("div");
    place.menuContainerObject.className = "menuContainer";
    place.menuContainerObject.style.position = "relative";

    place.menuContainerObject.placement = this.placement;
    
    place.appendChild(place.menuContainerObject);
    
    for (var cIndex=0;cIndex<this.menus.length;cIndex++)
    {
      this.menus[cIndex].draw((this.orient == "horizontal"), place.menuContainerObject);
      
      if (this.orient == "horizontal")
      {
        drawWidth += this.menus[cIndex].menuElement.offsetWidth;
        drawHeight = this.menus[cIndex].menuElement.offsetHeight;
      }
      else
      {
        drawHeight += this.menus[cIndex].menuElement.offsetHeight;
        drawWidth = this.menus[cIndex].menuElement.offsetWidth;
      };
    };
    
    place.menuContainerObject.style.width = drawWidth + "px";
    place.menuContainerObject.style.height = drawHeight + "px";
    
  };
};

// Set MenuContainer to inherit from MyObject
MenuContainer.prototype = new MyObject();

// MySubMenu - A container object to hold all of the submenu's for a parentMenu menuObject
//
// 'shadow': true for a shadow on the container, false for no shadow
// 'width': the width of the submenu
// 'alpha': the alpha level for the submenu container.  0 to 100, 0 = transparent and 100 = opaque (default)
function MySubMenu(vars,parentMenu)
{
  this.parentMenu = parentMenu;       // This is the MyMenu object which is the parent for this submenu container
  this.properties = vars;             // this contains all of the properties passed in the constructor - these are all assigned to this class by myObject
  this.shadowContainer = undefined;   // this is the actual DIV which contains the shadows
  this.subMenuContainerObject = undefined;  // this is the actual DIV that contains all of the submenu objects
  this.subMenus = new Array();        // this contains an array of all the sub-menus for this object
  
  this.parseProperties();
  
  this.objectType = 'MySubMenu';      // This is the type of the object, for reference purposes
  
  this.addMenu = function(subMenuObject)
  {
    subMenuObject.menuContainerObject = this.parentMenu.menuContainerObject;
    subMenuObject.subMenuIndex = this.subMenus.length;
    this.subMenus.push(subMenuObject);
    this.parentMenu.subMenus.push(subMenuObject);
    subMenuObject.parentMenu = this.parentMenu;
    subMenuObject.subMenuContainerObject = this;
  };
  
  this.drawSubMenu = function()
  {
    // Do not run if there are no subMenus in the menuObject
    if (this.subMenus.length == 0)
      return;
      
    if (this.subMenuContainerObject != undefined)
      return;
  
    this.subMenuContainerObject = document.createElement("div");

    this.subMenuContainerObject.className = "subMenuContainer";
    this.subMenuContainerObject.style.zIndex = 100;
    
    this.subMenuContainerObject.subMenuObject = this;        // This sets a property called subMenuObject on the div which points to this submenu class
    
    // fist, go through user-defined properties
    if (this.width != undefined)
    {
      this.subMenuContainerObject.style.width = this.width;
    };
    
    this.subMenuContainerObject.style.visibility = "hidden";
    this.subMenuContainerObject.style.position = "absolute";

    switch (this.parentMenu.submenudisplay)     // determine the position of the submenu container
    {
      case "top":
        this.subMenuContainerObject.style.top = "0px";
        this.subMenuContainerObject.style.left = "0px";

        break;
      case "left":
        this.subMenuContainerObject.style.top = "0px";
        this.subMenuContainerObject.style.left = "0px";

        break;
      case "right":
        var left = getLeft(this.parentMenu.menuElement) + this.parentMenu.menuElement.offsetWidth;
        
        if (this.parentMenu.parentMenu != undefined)
          left += 2;
          
        this.subMenuContainerObject.style.top = "0px";
        this.subMenuContainerObject.style.left = "0px";
        
        break;
      default: // bottom
        var top = (getTop(this.parentMenu.menuElement) + this.parentMenu.menuElement.offsetHeight);
        
        if (this.parentMenu.parentMenu != undefined)
          top += 2;
          
        this.subMenuContainerObject.style.top = "0px";
        this.subMenuContainerObject.style.left = "0px";
                
        break;
    }; // end setting submenu container position

    if (this.parentMenu.menuContainerObject.usealpha == true)
    { 
    /*   
      if (is_ie)
      {
        this.subMenuContainerObject.style.filter = 'alpha(opacity=0)';
      }
      else // for mozilla
      {
        this.subMenuContainerObject.style.opacity = 0;
      };
      */
    }
    else
    {
      this.subMenuContainerObject.visibility = 'hidden';
    };
    
    this.subMenuContainerObject.onmouseout = function()
    {
      // hide the menuElement if needed
      var parentMenu = this.subMenuObject.parentMenu;
      while (parentMenu != undefined)
      {
        if (parentMenu.isSubMenuVisible == true && parentMenu.timerSubMenuID == undefined)
        {
          parentMenu.timerSubMenuID = setTimeout('hideSubMenu(' + parentMenu.allMenusIndex + ')', hideMenuTimeout);
        };
        
        parentMenu = parentMenu.parentMenu;
      };
      
    }; // end on mouse out
    
    this.subMenuContainerObject.onmouseover = function()
    {
      var parentMenu = this.subMenuObject.parentMenu;
      while (parentMenu != undefined)
      {
        if (parentMenu.timerSubMenuID != undefined)
        {
          window.clearTimeout(parentMenu.timerSubMenuID);
          parentMenu.timerSubMenuID = undefined;
        };
        
        parentMenu = parentMenu.parentMenu;
      };
      
    }; // end on mouse over
    
    document.body.appendChild(this.subMenuContainerObject);
    
    
    // next, go through all of the children and draw them
    for (var a=0; a<this.subMenus.length; a++)
    {
      this.subMenus[a].draw();
    };
    
    // next, now that we have a set width and height for this item, adjust the position if display to the left or to the top
    // first, left
    if (this.parentMenu.submenudisplay == "left")
    {
      this.subMenuContainerObject.style.left = getLeft(this.parentMenu.menuElement) - this.subMenuContainerObject.offsetWidth + "px";
    };
    // last, top
    if (this.parentMenu.submenudisplay == "top")
    {
      this.subMenuContainerObject.style.top = getTop(this.parentMenu.menuElement) - this.subMenuContainerObject.offsetHeight + "px";
    };
    
    // draw the shadow
    if (this.shadow == true)
    {
      this.shadowContainer = createShadow(this.subMenuContainerObject);
    };

  }; // end draw method
};

MySubMenu.prototype = new MyObject();

// Supported Properties to pass to the constructor:
// - 'alpha': The alpha level of the menuElement, 0 to 100, 0 = transparent and 100 = opaque, 100 is default
// - 'width': The width of the menuElement - this propogates to the submenu if 'submenuwidth' is not defined
// - 'text': The text of the menuObject item
// - 'id': The id assigned to the item for future reference - if not defined, item will not have an ID assigned
// - 'classnormal': The class assigned to the item - the item will not get menuElement or subMenu class if this is defined
// - 'classover': The class assigned to the item when the mouse is over the item
// - 'classactive': The class assigned to the item when the item is the current page defined by the link.  Class assigned in addition to classnormal!
// - 'classoveractive': The class assigned to the item when the mouse is over the item and the link of the item is the active page, assigned in addition to classover!
// - 'submenuwidth': The width to assign to the submenu items for the item
// - 'link': The link that the menuElement option redirects to the page.  Prefix with "javascript:" to run code
// - 'submenualpha': The alpha value (0-100, 0=transparent) of the submenu - 100 is default
// - 'submenudisplay': Can be top, bottom, left, right.  Defaults to bottom.  This is the direction to show the submenu for this object, if it has a submenu
// - 'submenushadow': true for a shadow on it's submenu, false or blank for no shadow
// - 'submenushowjs': Javascript that is executed when the submenu is shown.  Pass it complete javascript like "showMenu();"
// - 'submenuhidejs': Javascript that is executed when the submenu is hidden.  Pass it complete javascript like "hideMenu();"

function MyMenu(vars)
{
  this.allMenusIndex = allMenus.length; // this is the index of this menuElement in the global allMenus variable, for reference globally
  allMenus.push(this);                  // add this menuElement to the allMenus array
  
  this.isSubMenuVisible = false;  // this is for parents only, whether the submenus are visible
  this.menuElement = undefined;          // this is the actual menuElement div - only assigned after it has been drawn
  this.parentMenu = undefined;    // this is the parent menuObject of this menuObject - if this is the root, it remains undefined
  this.properties = vars;         // this contains all of the properties passed in the constructor - these are all assigned to this class by myObject
  this.subMenuObject = undefined;       // this will be the mySubMenu class if the item has subitems
  this.subMenus = new Array();    // this will be an array of the submenus this item has
  this.subMenuIndex = -1;         // if the item is a subitem to a parent, this is it's index in the submenu array - if not a subitem, it will be -1
  this.timerFadeID = undefined;   // The timer (interval) id for fading in and out
  this.timerSubMenuID = undefined;// The timer id for hiding the menuObject
  this.menuContainerObject = undefined; // This is the MenuContainer containing this MyMenu
  this.subMenuContainerObject = undefined; // This is the MySubMenu containing this MyMenu

  this.parseProperties(); 

  this.objectType = 'MyMenu';     // This is the object type, for reference purposes
  
  // make sure there is a valid submenudisplay value        
  if (this.submenudisplay == undefined)
  {
    this.submenudisplay = "bottom";
  }
  else
  {
    this.submenudisplay = this.submenudisplay.toLowerCase();
  };
  
  if (this.submenudisplay != "top" && this.submenudisplay != "bottom" && this.submenudisplay != "left" && this.submenudisplay != "right")
  {
    this.submenudisplay = "bottom";
  };
  
  // make sure there is a valid submenushadow value
  if (this.submenushadow == undefined || this.submenushadow != true)
  {
    this.submenushadow = false;
  };
  
  // make sure the values for submenualpha are valid
  if (this.submenualpha == undefined || this.submenualpha != undefined && (typeof(this.submenualpha) != "number" || this.submenualpha < 0 || this.submenualpha > 100))
  {
    this.submenualpha = 100;
  };
  
  // make sure the values for alpha are valid
  if (this.alpha == undefined || this.alpha != undefined && (typeof(this.alpha) != "number" || this.alpha < 0 || this.alpha > 100))
  {
    this.alpha = 100;
  };
  
  this.addMenu = function(subMenuObject)
  {
    if (this.subMenuObject == undefined)
    {
      // set the width - set to submenuwidth property if defined, else width of the parent
      var sWidth = this.width;
      
      if (this.submenuwidth != undefined)
        sWidth = this.submenuwidth;
      
      this.subMenuObject = new MySubMenu({width:sWidth,shadow:this.submenushadow,alpha:this.submenualpha},this);
    };
    
    this.subMenuObject.addMenu(subMenuObject);
  };
  
  // isFloat is whether to apply float:left to the item (if the container is horizontal)
  // menuContainer is the menuContainer to add the menuElement to
  this.draw = function(isFloat, menuContainerObject)
  {
    if (this.menuElement != undefined)
      return;

    if (isFloat == undefined || isFloat != true)
      isFloat = false;

    this.menuElement = document.createElement("div");

    // set the class to the peroperty classnormal if set for this object, otherwise use default class names
    if (this.classnormal == undefined)
    {
      // test if it is the active page
      if (this.link != undefined && this.link.substr(0,11) != "javascript:" && location.href.indexOf(this.link) != -1)
      {
        if (this.parentMenu == undefined)
          this.menuElement.className = "menu menuActive";
        else
          this.menuElement.className = "subMenu subMenuActive";
      }
      else
      {
        if (this.parentMenu == undefined)
          this.menuElement.className = "menu";
        else
          this.menuElement.className = "subMenu";
      };
    }
    else
    {
      // test if it is the active page
      if (this.link != undefined && this.link.substr(0,11) != "javascript:" && location.href.indexOf(this.link) != -1 && this.classactive != undefined)
        this.menuElement.className = this.classnormal + " " + this.classactive;

      this.menuElement.className = this.classnormal;
    };
      
    this.menuElement.menuObject = this;        // This sets a property called menuObject on the div which points to this menuElement class - so the div can reflect on values in the parentMenu div
    
    // fist, go through user-defined properties          
    if (this.width != undefined)
    {
      this.menuElement.style.width = this.width;
    }
    else
    {
      if (this.parentMenu != undefined && this.parentMenu.subMenuObject != undefined && this.parentMenu.subMenuObject.width != undefined)
        this.menuElement.style.width = this.parentMenu.subMenuObject.width;
    };
    
    if (this.text != undefined)
    {
      this.menuElement.innerHTML = this.text;
    };
    
    if (this.id != undefined)
    {
      this.menuElement.id = this.id;
    };
    
    if (this.link != undefined)
    {
      this.menuElement.style.cursor = "pointer";
    }
    else
    {
      this.menuElement.style.cursor = "default";
    };
    
    // set the transparency
    if (this.alpha != undefined)
    {
    /*
      if (is_ie)
      {
        this.menuElement.style.filter = 'alpha(opacity=' + this.alpha + ')';
      }
      else // for mozilla
      {
        this.menuElement.style.opacity = this.alpha/100;
      };
      */
    };
    
    // set events for the item         
    this.menuElement.onclick = function()
    {
      if (this.menuObject.link != undefined)
      {
        if (this.menuObject.link.substr(0,11) == "javascript:")
          eval(this.menuObject.link.substr(11));
        else
          location.href = this.menuObject.link;
      };
    }; // end onclick
    
    this.menuElement.onmouseout = function()
    {
      // only change the class if the submenu is not visible
      if (this.menuObject.isSubMenuVisible != true)
      {
        // first, change the class as needed
        if (this.menuObject.classnormal == undefined)
        {
          // test if it is the active page
          if (this.menuObject.link != undefined && this.menuObject.link.substr(0,11) != "javascript:" && location.href.indexOf(this.menuObject.link) != -1)
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = "menu menuActive";
            else
              this.className = "subMenu subMenuActive";
          }
          else
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = "menu";
            else
              this.className = "subMenu";
          };
        }
        else
        {
          // test if it is the active page
          if (this.menuObject.link != undefined && this.menuObject.link.substr(0,11) != "javascript:" && location.href.indexOf(this.menuObject.link) != -1)
            this.className = this.menuObject.classnormal + " " + ((this.menuObject.classactive != undefined)?(this.menuObject.classactive):((this.menuObject.parentMenu == undefined)?("menuActive"):("subMenuActive")));
          else
            this.className = this.menuObject.classnormal;
        };
      }; // end submenuvisible check
      
      // next, hide the menuElement if needed
      if (this.menuObject.subMenuObject != undefined && this.menuObject.isSubMenuVisible == true && this.menuObject.timerSubMenuID == undefined)
      {
        this.menuObject.timerSubMenuID = setTimeout('hideSubMenu(' + this.menuObject.allMenusIndex + ')', hideMenuTimeout);
      };
      
    }; // end on mouse out
    
    this.menuElement.onmouseover = function()
    {
      // first, change the class as needed for the menuElement item
      if (this.menuObject.classnormal == undefined)
      {
        if (this.menuObject.classover == undefined)
        {
          // test if it is the active page
          if (this.menuObject.link != undefined && this.menuObject.link.substr(0,11) != "javascript:" && location.href.indexOf(this.menuObject.link) != -1)
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = "menu menuOver menuOverActive";
            else
              this.className = "subMenu subMenuOver subMenuOverActive";
          }
          else
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = "menu menuOver";
            else
              this.className = "subMenu subMenuOver";
          };
        }
        else
        {
          // test if it is the active page
          if (this.menuObject.link != undefined && this.menuObject.link.substr(0,11) != "javascript:" && location.href.indexOf(this.menuObject.link) != -1)
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = "menu " + this.menuObject.classover + " " + (this.menuObject.classoveractive != undefined)?(this.menuObject.classoveractive):("menuOverActive");
            else
              this.className = "subMenu " + this.menuObject.classover + " " + (this.menuObject.classoveractive != undefined)?(this.menuObject.classoveractive):("subMenuOverActive");
          }
          else
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = "menu " + this.menuObject.classover;
            else
              this.className = "subMenu " + this.menuObject.classover;
          };
        };
      }
      else
      {
        if (this.menuObject.classover == undefined)
        {
          // test if it is the active page
          if (this.menuObject.link != undefined && this.menuObject.link.substr(0,11) != "javascript:" && location.href.indexOf(this.menuObject.link) != -1)
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = this.menuObject.classnormal + " menuOver " + (this.menuObject.classoveractive != undefined)?(this.menuObject.classoveractive):("menuOverActive");
            else
              this.className = this.menuObject.classnormal + " subMenuOver " + (this.menuObject.classoveractive != undefined)?(this.menuObject.classoveractive):("subMenuOverActive");
          }
          else
          {
            if (this.menuObject.parentMenu == undefined)
              this.className = this.menuObject.classnormal + " menuOver";
            else
              this.className = this.menuObject.classnormal + " subMenuOver";
          };
        }
        else
        {
          // test if it is the active page
          if (this.menuObject.link != undefined && this.menuObject.link.substr(0,11) != "javascript:" && location.href.indexOf(this.menuObject.link) != -1)
          {
            this.className = this.menuObject.classnormal + " " + this.menuObject.classover + " " + ((this.menuObject.classoveractive != undefined)?(this.menuObject.classoveractive):((this.menuObject.parentMenu == undefined)?("menuOverActive"):("subMenuOverActive")));
          }
          else
          {
            this.className = this.menuObject.classnormal + " " + this.menuObject.classover;
          };
        };
      };
      
      // next, show the menuElement if needed
      if (this.menuObject.subMenuObject != undefined && this.menuObject.isSubMenuVisible == false)
      {
        this.menuObject.subMenuObject.subMenuContainerObject.style.visibility = "visible";

        // Change the position of the item, if needed
        switch (this.menuObject.submenudisplay)     // determine the position of the submenu container
        {
          case "top":
            this.menuObject.subMenuObject.subMenuContainerObject.style.left = getLeft(this) + "px";
            this.menuObject.subMenuObject.subMenuContainerObject.style.top = getTop(this) - this.menuObject.subMenuObject.subMenuContainerObject.offsetHeight + "px";

            break;
          case "left":
            this.menuObject.subMenuObject.subMenuContainerObject.style.top = getTop(this) + "px";
            this.menuObject.subMenuObject.subMenuContainerObject.style.left = getLeft(this) - this.menuObject.subMenuObject.subMenuContainerObject.offsetWidth + "px";

            break;
          case "right":
            var left = getLeft(this) + this.offsetWidth;
            
            this.menuObject.subMenuObject.subMenuContainerObject.style.top = getTop(this) + "px";
            this.menuObject.subMenuObject.subMenuContainerObject.style.left = left + "px";
            
            break;
          default: // bottom
            var top = (getTop(this) + this.offsetHeight);
            
            this.menuObject.subMenuObject.subMenuContainerObject.style.top = top + "px";
            
            //Modification to right align the menu - specific to APT

            //width of parent element
            //this.menuObject.menuElement.offsetWidth
          
            //width of submenu
            //this.menuObject.subMenuObject.subMenuContainerObject.offsetWidth;
            
            this.menuObject.subMenuObject.subMenuContainerObject.style.left = getLeft(this) + "px";
            
            break;
        }; // end setting submenu container position
        
        // show the shadow
        if (this.menuObject.subMenuObject.shadowContainer != undefined)
        {
          this.menuObject.subMenuObject.shadowContainer.style.visibility = "visible";

          this.menuObject.subMenuObject.shadowContainer.style.top = getTop(this.menuObject.subMenuObject.subMenuContainerObject) + 6 + "px";
          this.menuObject.subMenuObject.shadowContainer.style.left = getLeft(this.menuObject.subMenuObject.subMenuContainerObject) + 6 + "px";
        };
        
        this.menuObject.isSubMenuVisible = true;
        
        if (this.menuObject.timerFadeID != undefined)
        {
          window.clearInterval(this.menuObject.timerFadeID);
        };
        
        

        showSubMenu(this.menuObject);
      };
      
      // cancel the hide menuElement timer if set
      if (this.menuObject.timerSubMenuID != undefined)
      {
        window.clearTimeout(this.menuObject.timerSubMenuID);
        this.menuObject.timerSubMenuID = undefined;
      };
    }; // end on mouse over
    
    if (this.parentMenu == undefined)
    {
      if (isFloat == true)
      {
        if (is_ie)
        {
          this.menuElement.style.styleFloat = "left";
        }
        else
        {
          this.menuElement.style.cssFloat = "left";
        };
      };
      
      menuContainerObject.appendChild(this.menuElement);
    }
    else
    {
      this.parentMenu.subMenuObject.subMenuContainerObject.appendChild(this.menuElement);
    };
    
    if (this.subMenuObject != undefined)
    {
      this.subMenuObject.drawSubMenu();
    };
    
    if (this.menuElement.style.width == "" && this.parentMenu != undefined && this.parentMenu.subMenuObject != undefined)
    {
      this.menuElement.style.width = this.parentMenu.subMenuObject.subMenuContainerObject.clientWidth + "px";
    };
  }; // end draw method
}; // end MyMenu class

// Set MyMenu to inherit from MyObject
MyMenu.prototype = new MyObject();

// This function is called to hide a subMenuObject container
function hideSubMenu(menuIndex)
{
  var myMenu = allMenus[menuIndex];
  
  myMenu.timerSubMenuID = undefined;
  myMenu.isSubMenuVisible = false;
  
  // first, change the class as needed
  if (myMenu.classnormal == undefined)
  {
    // test if it is the active page
    if (myMenu.link != undefined && myMenu.link.substr(0,11) != "javascript:" && location.href.indexOf(myMenu.link) != -1)
    {
      if (myMenu.parentMenu == undefined)
        myMenu.menuElement.className = "menu menuActive";
      else
        myMenu.menuElement.className = "subMenu subMenuActive";
    }
    else
    {
      if (myMenu.parentMenu == undefined)
        myMenu.menuElement.className = "menu";
      else
        myMenu.menuElement.className = "subMenu";
    };
  }
  else
  {
    // test if it is the active page
    if (myMenu.link != undefined && myMenu.link.substr(0,11) != "javascript:" && location.href.indexOf(myMenu.link) != -1)
      myMenu.menuElement.className = myMenu.classnormal + " " + ((myMenu.classactive != undefined)?(myMenu.classactive):((myMenu.parentMenu == undefined)?("menuActive"):("subMenuActive")));
    else
      myMenu.menuElement.className = myMenu.classnormal;
  };
  
  if (myMenu.menuContainerObject.usealpha == true)
  {
    if (myMenu.timerFadeID != undefined)
    {
      window.clearInterval(myMenu.timerFadeID);
    };
  
    //myMenu.timerFadeID = setInterval('fadeSubMenuOut(' + menuIndex + ')',fadeInterval);
    
    if (is_ie)
    {
      myMenu.subMenuObject.subMenuContainerObject.style.visibility = "hidden";
        
      // hide the shadow
      if (myMenu.subMenuObject.shadowContainer != undefined)
        myMenu.subMenuObject.shadowContainer.style.visibility = "hidden";
       
      myMenu.subMenuObject.subMenuContainerObject.style.filter = 'alpha(opacity=0)';
      
      // hide the shadow
      if (myMenu.subMenuObject.shadowContainer != undefined)
        myMenu.subMenuObject.shadowContainer.style.filter = 'alpha(opacity=0)';
    }
    else // for mozilla
    {
      myMenu.subMenuObject.subMenuContainerObject.style.visibility = "hidden";
  
      // hide the shadow
      if (myMenu.subMenuObject.shadowContainer != undefined)
        myMenu.subMenuObject.shadowContainer.style.visibility = "hidden";
      
      myMenu.subMenuObject.subMenuContainerObject.style.opacity = 0;
      
      // hide the shadow
      if (myMenu.subMenuObject.shadowContainer != undefined)
        myMenu.subMenuObject.shadowContainer.style.opacity = 0;
    };
  }
  else
  {
    allMenus[menuIndex].subMenuObject.subMenuContainerObject.style.visibility = 'hidden';
  };
  
  if (myMenu.submenuhidejs != undefined)
  {
    eval(myMenu.submenuhidejs);
  };
}; // end hideSubMenu

// This function is called to show a subMenuObject container
function showSubMenu(menuObject)
{
  if (allMenus[menuObject.allMenusIndex].menuContainerObject.usealpha == true)
  {
    alert('shit');
    menuObject.timerFadeID = setInterval('fadeSubMenuIn(' + menuObject.allMenusIndex + ')',fadeInterval);
  }
  else
  {
    // do nothing
  };
  
  if (allMenus[menuObject.allMenusIndex].submenushowjs != undefined)
  {
    eval(allMenus[menuObject.allMenusIndex].submenushowjs);
  };
}; // end showSubMenu

function fadeSubMenuIn(menuIndex)
{
  var myMenu = allMenus[menuIndex];
  
  if (is_ie)
  {
    if (myMenu.subMenuObject.subMenuContainerObject.filters["alpha"] == undefined || myMenu.subMenuObject.subMenuContainerObject.filters["alpha"].opacity >= myMenu.subMenuObject.alpha)
    {
      clearInterval(myMenu.timerFadeID);
      return;
    };
    
    // The adjusted amount to actually fade each step
    var fadeAmount = fadeDelta * (myMenu.subMenuObject.alpha / 100);
    
    var alpha = ((myMenu.subMenuObject.subMenuContainerObject.filters["alpha"].opacity + fadeAmount) > myMenu.subMenuObject.alpha)?(myMenu.subMenuObject.alpha):(myMenu.subMenuObject.subMenuContainerObject.filters["alpha"].opacity + fadeAmount);
    
    myMenu.subMenuObject.subMenuContainerObject.style.filter = 'alpha(opacity=' + alpha + ')';
    
    // show the shadow
    if (myMenu.subMenuObject.shadowContainer != undefined)
      myMenu.subMenuObject.shadowContainer.style.filter = 'alpha(opacity=' + alpha + ')';
  }
  else // for mozilla
  {
    if (myMenu.subMenuObject.subMenuContainerObject.style.opacity == "" || parseFloat(myMenu.subMenuObject.subMenuContainerObject.style.opacity) >= 1)
    {
      clearInterval(myMenu.timerFadeID);
      return;
    };
    
    // The adjusted amount to fade each step
    var fadeAmount = (fadeDelta/100) * (myMenu.subMenuObject.alpha / 100);
    
    var alpha = ((parseFloat(myMenu.subMenuObject.subMenuContainerObject.style.opacity) + fadeAmount) > (myMenu.subMenuObject.alpha/100))?((myMenu.subMenuObject.alpha/100)):(parseFloat(myMenu.subMenuObject.subMenuContainerObject.style.opacity) + fadeAmount);

    myMenu.subMenuObject.subMenuContainerObject.style.opacity = alpha;
    
    // show the shadow
    if (myMenu.subMenuObject.shadowContainer != undefined)
      myMenu.subMenuObject.shadowContainer.style.opacity = alpha;
  };
}; // end fadeSubMenuIn

function fadeSubMenuOut(menuIndex)
{
  var myMenu = allMenus[menuIndex];
  
  if (is_ie)
  {
    if (myMenu.subMenuObject.subMenuContainerObject.filters["alpha"] != undefined && myMenu.subMenuObject.subMenuContainerObject.filters["alpha"].opacity <= 0)
    {
      clearInterval(myMenu.timerFadeID);
      //myMenu.subMenuObject.subMenuContainerObject.style.display = "none";
      myMenu.subMenuObject.subMenuContainerObject.style.visibility = "hidden";
      
      // hide the shadow
      if (myMenu.subMenuObject.shadowContainer != undefined)
        myMenu.subMenuObject.shadowContainer.style.visibility = "hidden";
        
      return;
    };
    
    //var alpha = ((myMenu.subMenuObject.subMenuContainerObject.filters["alpha"] != undefined)?(myMenu.subMenuObject.subMenuContainerObject.filters["alpha"].opacity):(100)) - fadeDelta;
    var alpha = 0;

    if (alpha < 0)
      alpha = 0;
      
    myMenu.subMenuObject.subMenuContainerObject.style.filter = 'alpha(opacity=' + alpha + ')';
    
    // hide the shadow
    if (myMenu.subMenuObject.shadowContainer != undefined)
      myMenu.subMenuObject.shadowContainer.style.filter = 'alpha(opacity=' + alpha + ')';
  }
  else // for mozilla
  {
    if (myMenu.subMenuObject.subMenuContainerObject.style.opacity != "" && parseFloat(myMenu.subMenuObject.subMenuContainerObject.style.opacity) <= 0)
    {
      clearInterval(myMenu.timerFadeID);
      //myMenu.subMenuObject.subMenuContainerObject.style.display = "none";
      myMenu.subMenuObject.subMenuContainerObject.style.visibility = "hidden";

      // hide the shadow
      if (myMenu.subMenuObject.shadowContainer != undefined)
        myMenu.subMenuObject.shadowContainer.style.visibility = "hidden";
      
      return;
    };
    
    //var alpha = ((myMenu.subMenuObject.subMenuContainerObject.style.opacity != "")?(parseFloat(myMenu.subMenuObject.subMenuContainerObject.style.opacity)):(1)) - (fadeDelta / 100);
    alpha = 0;
    
    if (alpha < 0)
      alpha = 0;
      
    myMenu.subMenuObject.subMenuContainerObject.style.opacity = alpha;
    
    // hide the shadow
    if (myMenu.subMenuObject.shadowContainer != undefined)
      myMenu.subMenuObject.shadowContainer.style.opacity = alpha;
  };
}; // end fadeSubMenuOut

function getTop(object)
{
  var top = object.offsetTop;
  var obj = object;
  
  while (obj = obj.offsetParent)
  {
    top += obj.offsetTop;
  };
  
  return top;
}; // end getTop

function getLeft(object)
{
  var left = object.offsetLeft;
  var obj = object;
  
  while (obj = obj.offsetParent)
  {
    left += obj.offsetLeft;
  };
  
  return left;
}; // end getLeft

// 'obj': The object to create a shadow on
function createShadow(obj)
{
  var container = document.createElement("div");
  container.style.position = "absolute";
  container.style.width = obj.offsetWidth + "px";
  container.style.height = obj.offsetHeight + "px";
  container.style.left = getLeft(obj) + 6 + "px";
  container.style.top = getTop(obj) + 6 + "px";
  container.style.zIndex = 0;
  document.body.appendChild(container);
  
  createShadowLayer(container, 0, 10);
  createShadowLayer(container, 1, 20);
  createShadowLayer(container, 2, 30);
  createShadowLayer(container, 3, 40);
  createShadowLayer(container, 4, 50);
  createShadowLayer(container, 5, 60);
  
  container.style.visibility = "hidden";
  if (is_ie)
  {
    container.style.filter = 'alpha(opacity=0)';
  }
  else // for mozilla
  {
    container.style.opacity = 0;
  };
  
  return container;
};

// This is only used by createShadow
function createShadowLayer(obj,offset,alpha)
{
  var shadowLayer = document.createElement("div");
  shadowLayer.style.position = "absolute";
  shadowLayer.style.top = (offset - 2) + "px";
  shadowLayer.style.left = (offset - 2) + "px";
  shadowLayer.style.width = obj.offsetWidth - (offset*2) + "px";
  shadowLayer.style.height = obj.offsetHeight - (offset*2) + "px";
  //shadowLayer.style.backgroundColor = "gray";
  shadowLayer.style.borderRight = "1px solid gray";
  shadowLayer.style.borderBottom = "1px solid gray";
  // do not have a left and top borders - important because if an item is partially transparent and has a shadow
  //   we do not want to see the border of the shadow (creates a line)
  shadowLayer.style.borderTop = "0px solid gray";
  shadowLayer.style.borderLeft = "0px solid gray";
  
  if (is_ie)
  {
    shadowLayer.style.filter = 'alpha(opacity=' + alpha + ')';
  }
  else // for mozilla
  {
    shadowLayer.style.opacity = alpha/100;
  };
  
  obj.appendChild(shadowLayer);
};
