/***********************
  SCK Hierarchical Pop-up Menus
  Copyright 2002  SCK Design

  2003-06-18 - 2003-06-19 nbs: modified to allow relative
    positioning of menus, and to fix menu position on resize.
  2003-09-24 - 2003-10-01 nbs: fixed reposition to eliminate
    NS6 flicker.

  Menu code

  Default parameters and the menu definitions are in other files.

***********************/

  function timestamp ()
  {
    this.toString = toString;
    this.valueOf = toString;

    function toString ()
    {
      var dat = new Date ();

      return dat.getHours () + ':' + dat.getMinutes () + ':' + dat.getSeconds () + '.' + dat.getMilliseconds ();
    }
  }

  function isString (o)
  {
    return ((typeof (o) == 'string')
        || ((typeof (o) == 'object') && o.constructor
          && (o.constructor.toString ().substr (0, 20) == '\nfunction String() {')))
  }

  function getPosition (element)
  {
    //given an element on the page, finds its position relative to the top left
    //  corner of the page.
    var aryCoords = [element.x || 0, element.y || 0];
    var el = element;

    if (el.offsetParent && !element.x)
    {
      while (el != null)
      {
        aryCoords [0] += parseInt (el.offsetLeft, 10);
        aryCoords [1] += parseInt (el.offsetTop, 10);

        el = el.offsetParent;
      }
    }

    return aryCoords;
  }


  /*******************
    Browser-specific code
  *******************/
  function Menu_BrowserSpecific ()
  {
    this.newLayer = newLayer;
    this.iCounter = 0;

    function newLayer (width, parent, isItem)
    {
      var layer;

      if (document.layers)
      {
        parent = parent || window;
        layer = new Layer (width, parent);
        layer.visibility = 'inherit';
        layer._width = width;
        if (isItem)
          layer.captureEvents (Event.MOUSEUP);
        
        layer._makeMenu = _makeMenu_NS;
        layer._resize = _resize_NS;
        layer._moveTo = _moveTo_NS;
        layer._setBgColor = _setBgColor_NS;
        layer._setFontColor = new Function ();
        layer._setVisibility = _setVisibility_NS;
        layer._setZIndex = _setZIndex_NS;
        layer._write = _write_NS;
        layer._getHeight = _getHeight_NS;
        layer._setCursor = _setCursor_NS;
        layer._fixWidth = _fixWidth_NS;
        layer._getChildren = _getChildren_NS;
      }
      else
      {
        parent = parent || document.body;
        if (document.createElement)
        {
          layer = document.createElement ('div');
          parent.appendChild (layer);
        }
        else
        {
          if (parent.insertAdjacentHTML && document.all)
          {
            parent.insertAdjacentHTML ('beforeEnd', '<div id="Menu_Layer_' + this.iCounter + '"></div>');
            layer = document.all ['Menu_Layer_' + this.iCounter];
            this.iCounter ++;
          }
        }

        if (layer)
        {
          layer.style.position = 'absolute';
          layer.style.visibility = 'inherit';
          layer.style.left = '0px';
          layer.style.top = '0px';
          layer.style.width = width + 'px';
          layer._width = width;

          layer._makeMenu = _makeMenu_DOM;
          layer._resize = _resize_DOM;
          layer._moveTo = _moveTo_DOM;
          layer._setBgColor = _setBgColor_DOM;
          layer._setFontColor = _setFontColor_DOM;
          layer._setVisibility = _setVisibility_DOM;
          layer._setZIndex = _setZIndex_DOM;
          layer._write = _write_DOM;
          layer._getHeight = _getHeight_DOM;
          layer._setCursor = _setCursor_DOM;
          layer._fixWidth = _fixWidth_DOM;
          layer._getChildren = _getChildren_DOM;
        }
      }

      return layer;
    }

    function increaseFont (strFontSize)
    {
      var match;

      if (match = strFontSize.match (/(\d+)(em|ex|px|%|in|cm|mm|pt|pc)/i))
      {
        return '' + Math.round (parseInt (match [1], 10) * 1.1) + match [2];
      }
      else
        switch (strFontSize)
        {
          case 'xx-small':
            return 'x-small'; break;
          case 'x-small':
            return 'small'; break;
          case 'small':
            return 'medium'; break;
          case 'medium':
            return 'large'; break;
          case 'large':
            return 'x-large'; break;
          case 'x-large':
            return 'xx-large'; break;
          default:
            return strFontSize;
        }
    }

    function _makeMenu_NS (menu, i)
    {
      var str;

      str  = '<div style="margin: 0px; ';
      str += 'padding: ' + (menu.padding - 2) + 'px; ';
      str += 'padding-left: ' + (menu.paddingLeft - 2) + 'px; ';
      str += 'width: ' + menu.width + 'px; ';
      str += 'border-color: ' + menu.borderColor + '; ';
      str += 'border-width: ' + menu.borderWidth + 'px; ';
      str += 'border-style: solid; ';
      str += '">';
      str += '<span style="font-family: ' + menu.fontFamily + '; ';
      str += 'color: ' + menu.fontColor + '; ';
      str += 'font-size: ' + increaseFont (menu.fontSize) + '; ';
      str += '">' + menu.items [i].text + '</span></div>\n';

      this._write (str);
    }

    function _makeMenu_DOM (menu, i)
    {
      this.style.padding = menu.padding + 'px';
      this.style.paddingLeft = menu.paddingLeft + 'px';
      this.style.borderColor = menu.borderColor;
      this.style.borderWidth = menu.borderWidth + 'px';
      this.style.borderStyle = 'solid';
      this.style.fontFamily = menu.fontFamily;
      this.style.color = menu.fontColor;
      this.style.fontSize = menu.fontSize;

      this._write (menu.items [i].text);
    }

    function _resize_NS (width, height)
    {
      if (width != null)
      {
        this.clip.width = width;
        this._width = width;
      }
      if (height != null)
      {
        this.clip.height = height;
        this._height = height;
      }
    }

    function _resize_DOM (width, height)
    {
      if (width != null)
      {
        this.style.width = width + 'px';
        this._width = width;
      }
      if (height != null)
      {
        this.style.height = height + 'px';
        this._height = height;
      }
    }

    function _moveTo_NS (left, top)
    {
      this.moveTo (left, top);
      this._left = left;
      this._top = top;
    }

    function _moveTo_DOM (left, top)
    {
      this.style.left = left + 'px';
      this.style.top = top + 'px';
      this._left = left;
      this._top = top;
    }

    function _setBgColor_NS (bgColor)
    {
      this.bgColor = bgColor;
    }

    function _setBgColor_DOM (bgColor)
    {
      this.style.backgroundColor = bgColor;
    }

    function _setFontColor_DOM (fontColor)
    {
      this.style.color = fontColor;
    }

    function _setVisibility_NS (boolVisible)
    {
      if (boolVisible == null)
        this.visibility = 'inherit';
      else
        if (boolVisible)
          this.visibility = 'show';
        else
          this.visibility = 'hide';
    }

    function _setVisibility_DOM (boolVisible)
    {
      if (boolVisible == null)
        this.style.visibility = 'inherit';
      else
        if (boolVisible)
          this.style.visibility = 'visible';
        else
          this.style.visibility = 'hidden';
    }

    function _setZIndex_NS (zIndex)
    {
      this.zIndex = zIndex;
    }

    function _setZIndex_DOM (zIndex)
    {
      this.style.zIndex = zIndex;
    }

    function _write_NS (str)
    {
      this.document.open ();
      this.document.write (str);
      this.document.close ();
    }

    function _write_DOM (str)
    {
      this.innerHTML = str;
    }

    function _getHeight_NS ()
    {
      return this.document.height;
    }

    function _getHeight_DOM ()
    {
      var scrollHeight = 0, offsetHeight = 0;

      if (this.scrollHeight > 0) scrollHeight = this.scrollHeight;
      if (this.offsetHeight > 0) offsetHeight = this.offsetHeight;

      return ((offsetHeight > scrollHeight) ? offsetHeight : scrollHeight);
    }
    
    //Sets the cursor when over a menu
    function _setCursor_NS ()
    {
      var lsub;

      //cover the text layer with an empty one, 
      //  so that the cursor will be an arrow
      //  and not an I-bar.
      lsub = menuUtils.browserSpecific.newLayer (this._width, this);
      lsub._resize (this._width, this._height);
      lsub._setZIndex (50);
    }

    //Sets the cursor when over a menu
    function _setCursor_DOM ()
    {
      if (this._link)
      {
        //display a hand (IE5 and NS6 define it differently)
        if (document.all)
          this.style.cursor = 'hand';
        else
          this.style.cursor = 'pointer';
      }
      else
        this.style.cursor = 'default';
    }


    function _fixWidth_NS () {}

    //IE5 incorrectly includes the padding and border when
    //  setting or calculating an element's width; having
    //  set the width according to the IE way, this function
    //  corrects it for NS6.
    function _fixWidth_DOM ()
    {
      var intWidth;

      if (navigator.userAgent.indexOf ('Gecko') > 0)
      {
        intWidth = parseInt (this.style.width);
        intWidth -= (parseInt (this.style.borderLeftWidth) || parseInt (this.style.borderWidth));
        intWidth -= (parseInt (this.style.paddingLeft) || parseInt (this.style.padding));
        intWidth -= (parseInt (this.style.paddingRight) || parseInt (this.style.padding));
        intWidth -= (parseInt (this.style.borderRightWidth) || parseInt (this.style.borderWidth));

        this.style.width = intWidth + 'px';
      }
    }

    //array of all layers contained within the given layer
    function _getChildren_NS ()
    {
      return this.document.layers ? this.document.layers : new Array ();
    }

    //array of all layers contained within the given layer
    function _getChildren_DOM ()
    {
      return this.children || this.childNodes;
    }
  }
  

  /*******************
    Utility functions
    --provides a single entry point for
      all external functions related to the menu
      system and for collecting any global variables.
  *******************/
  function MenuUtils ()
  {
    this.currentMenu = null;
    this.isOverTrigger = false;
    this.isSetUp = false;

    this.browserSpecific = new Menu_BrowserSpecific ();

    this.rollOver = rollOver;
    this.moveOver = moveOver;
    this.doLink = doLink;

    this.show = show;
    this.hide = hide;
    this.doHide = doHide;
    this.setup = setup;
    this.setupMenu = setupMenu;
    this.preloadMenus = preloadMenus;
    this.repositionMenus = repositionMenus;
    this.cleanUp = cleanUp;
    this._zIndex = 100;
    this.showSelects = showSelects;
    this.hideSelects = hideSelects;

    //on mouseover or mouseout of a menu
    function moveOver (layer, boolOver)
    {
      var menuParent;

      layer._menu.isOver = boolOver;

      if (boolOver)
      {
         if (layer._menu.itemLayer)
           layer._menu.itemLayer._parentMenu.setHighlight (layer._menu.itemLayer);
      }
      else
        layer._menu.hide ();
    }

    //on mouseover or mouseout of a menu item
    function rollOver (layer, boolOver)
    {
      if (layer._menu && layer._parentMenu)
      {
        if (boolOver)
        {
          if (menuUtils.timeout)
            window.clearTimeout (menuUtils.timeout);

          if (layer._parentMenu.visibleChild && (layer._parentMenu.visibleChild != layer._menu))
            layer._parentMenu.visibleChild.hide (true);
          
          layer._parentMenu.visibleChild = layer._menu;
          layer._parentMenu.visibleChild.show ();
        }
        else
        {
          if (layer._parentMenu.visibleChild)
            layer._parentMenu.visibleChild.hide ();
        }
      }


      if (layer._link)
      {
        if (boolOver)
          window.status = layer._link;
        else
          window.status = '';
      }

      if (boolOver)
        layer._parentMenu.setHighlight (layer);
    }

    //on mouseup of a menu item
    function doLink (layer)
    {
      var win;

      if (layer._link)
      {
        if (layer._target)
        {
          win = window.open (layer._link, layer._target);
          win.focus ();
        }
        else
          top.location = layer._link;
      }
    }

    //on mouseover a trigger to start menu
    function show (str)
    {
      this.isOverTrigger = true;

      if (menuUtils.timeout)
        window.clearTimeout (menuUtils.timeout);

      if (this.currentMenu && (this.currentMenu != str))
        this.hide (true);

      if (Menus [str])
      {
        this.currentMenu = str;
        if (Menus [str].show)
        {
          Menus [str].show ();
          this.hideSelects ();
        }
      }
      else
        this.currentMenu = null;
    }

    //on mouseout of a trigger to start menu
    function hide (boolNow)
    {
      if (!boolNow)
        this.isOverTrigger = false;

      if (this.currentMenu 
          && Menus [this.currentMenu] 
          && Menus [this.currentMenu].hide)
        Menus [this.currentMenu].hide (boolNow);
    }

    function doHide (menuThis)
    {
      var menu = menuThis || Menus [this.currentMenu];
      var i;
      var boolHide = true;
      var boolAnyVisible = false;

      if (menu)
      {
        for (i = 0; i < menu.items.length; i ++)
        {
          if (menu.items [i].menu)
            boolHide = boolHide && this.doHide (menu.items [i].menu);
        }
        
        if (boolHide)
          boolHide = ! (menu.visible && menu.isOver);

        if (boolHide && (menu == Menus [this.currentMenu]))
        {
          boolHide = ! menuUtils.isOverTrigger;
          if (boolHide)
            this.currentMenu = null;
        }

        if (boolHide)
        {
          menu.setVisible (false);

          if (menu.onHide)
            eval (menu.onHide);
        }
      }

      for (i in Menus)
      {
        if (Menus [i].visible)
        {
          boolAnyVisible = true;
          break;
        }
      }
      if (! boolAnyVisible) this.showSelects ();

      return boolHide;
    }

    function setupMenu (menu, parent, depth)
    {
      var i;

      if (! menu.isSetup)
      {
        menu.isSetup = true;
        parent = parent || window.menu_params || new Object ();
      
        for (i in parent)
        {
          if ((menu [i] == null)
              && (i != 'left') && (i != 'top')
              && (i != 'onShow') && (i != 'onHide')
              && (i != 'left_delta') && (i != 'top_delta')
              && (i != 'relativeToElement'))
            menu [i] = parent [i];
        }
        if (! menu.left) menu.left = 0;
        if (! menu.top) menu.top = 0;

        if (! menu._proto)
        {
          menu._proto = MenuObject;
          menu._proto ();
        }

        menu.parent = parent;
        menu.depth = depth || 0;

        for (i = 0; i < menu.items.length; i ++)
        {
          if (menu.items [i].menu)
            this.setupMenu (menu.items [i].menu, menu, menu.depth + 1);
        }
      }
    }
 
    function setup ()
    {
      var strMenuName;

      for (strMenuName in Menus)
        this.setupMenu (Menus [strMenuName]);

      if (!this.isSetUp)
      {
        this.isSetUp = true;

        this._onunload_old = window.onunload || new Function ('return true');
        window.onunload = new Function ('menuUtils.cleanUp (); return menuUtils._onunload_old ();');

        this._onload_old = window.onload || new Function ('return true');
        window.onload = new Function ('menuUtils.preloadMenus (); return menuUtils._onload_old ();');

        this._onresize_old = window.onresize || new Function ('return true');
        window.onresize = new Function ('menuUtils.repositionMenus (); return menuUtils._onload_old ();');
        this._onscroll_old = window.onscroll || new Function ('return true');
        window.onscroll = new Function ('menuUtils.repositionMenus (); return menuUtils._onscroll_old ();');
      }
    }

    function preloadMenus ()
    {
      var strMenuName;

      for (strMenuName in Menus)
        Menus [strMenuName].preload ();
      for (strMenuName in Menus)
        Menus [strMenuName].reposition ();
    }

    function repositionMenus ()
    {
      var strMenuName;

      for (strMenuName in Menus)
        Menus [strMenuName].reposition ();
    }

    function cleanUp ()
    {
      var strMenuName;

      for (strMenuName in Menus)
        Menus [strMenuName].cleanUp ();
    }
    function hideSelects ()
    /***********
    *  Hides all <select> elements in document and temporarily
    *    replaces them with a <div> containing the same text.
    ***/
    {
      var iFrame, doc;
      var aryCbos;
      var iCbo, cbo, div;
      var text;

      if (document.getElementsByTagName && document.getElementById)
      {
        for (iFrame = -1; iFrame < window.frames.length; iFrame ++)
        {
          if (iFrame == -1)
            doc = document;
          else
            doc = window.frames [iFrame].window.document;
          aryCbos = doc.getElementsByTagName ("select");

          for (iCbo = 0; iCbo < aryCbos.length; iCbo ++)
          {
            // for each <select> on the page:
            cbo = aryCbos [iCbo];
            if (cbo.id)
            {
              // Get the text to display instead of the <select>
              if (cbo.type == 'select-multiple')
                text = '(list box)';
              else
                if (cbo.selectedIndex != -1)
                  text = cbo.options [cbo.selectedIndex].text;
                else
                  text = '&nbsp;';

              if (div = doc.getElementById (cbo.id + '__temp'))
              {
                // if we've already done this before, the <div> of
                //   text to replace the <select> is still there, it's
                //   just empty and hidden.  Fill it and show it.
                div.innerHTML = text;
                div.style.display = 'block';
              }
              else
                // add a <div> after the <select> which contains the
                //   text of the selected option
                cbo.insertAdjacentHTML ('afterEnd', '<div id="' + cbo.id + '__temp" class="' + cbo.className + '" style="width: ' + cbo.offsetWidth + 'px; height: ' + cbo.offsetHeight + 'px; border: 1px solid #404040;">' + text + '</div>');

              // hide the <select>
              cbo.style.display = "none";
            }
          }
        }
      }
    }

    
    function showSelects ()
    /************
    * Shows all <select> elements in document and hides
    *   the <div>s that temporarily replaced them.
    ***/
    {
      var iFrame, doc;
      var aryCbos;
      var iCbo, cbo, div;

      if (document.getElementsByTagName && document.getElementById)
      {
        for (iFrame = -1; iFrame < window.frames.length; iFrame ++)
        {
          if (iFrame == -1)
            doc = document;
          else
            doc = window.frames [iFrame].window.document;
          aryCbos = doc.getElementsByTagName ("select");
        
          for (iCbo = 0; iCbo < aryCbos.length; iCbo ++)
          {
            // for each <select> on the page:

            cbo = aryCbos [iCbo]
            // show the <select>
            cbo.style.display = 'inline';
            // if there's a <div> replacing it (there should always be,
            //   but error checking just in case), hide it.
            if (cbo.id && (div = doc.getElementById (cbo.id + '__temp')))
              div.style.display = 'none';
          }
        }
      }
    }
  }


  function MenuObject ()
  {
    this.depth = 0;
    this.isOver = false;
    this.layer = null;
    this.sizeFixed = false;
    this.positionFixed = false;
    this.visible = false;
    this.visibleChild = null;

    this.show = show;
    this.hide = hide;

    this.createLayer = createLayer;
    this.makeMenu = makeMenu;
    this.setVisible = setVisible;
    this.setHighlight = setHighlight;
    this.fixSize = fixSize;
    this.fixPosition = fixPosition;

    this.reposition = reposition;
    this.preload = preload;
    this.cleanUp = cleanUp;

    function show ()
    {
      if (this.onShow)
        eval (this.onShow);

      if (this.layer)
      {
        if (! this.sizeFixed)
          this.fixSize ();
        if (! this.positionFixed)
          this.fixPosition ();

        this.setHighlight (false);
        if (this.items.length > 0)
          this.setVisible (true);
      }
    }

    function hide (boolNow)
    {
      var i;

      if (boolNow)
      {
        for (i = 0; i < this.items.length; i ++)
        {
          if (this.items [i].menu)
            this.items [i].menu.hide (boolNow);
        }

        if (this.layer)
          this.setVisible (false);

        if (this.onHide)
          eval (this.onHide);
      }
      else
      {
        if (menuUtils.timeout)
          window.clearTimeout (menuUtils.timeout);
        menuUtils.timeout = window.setTimeout ('menuUtils.doHide ()', this.timeout, 'JavaScript');
      }
    }

    function createLayer ()
    {
      var layer = menuUtils.browserSpecific.newLayer (this.width);
      layer._menu = this;
      layer._moveTo (this.left, this.top);
      layer._setVisibility (false);
      layer._setZIndex (10 + this.depth);
      layer._setBgColor (this.bgColor);
      layer.onmouseover = new Function ('menuUtils.moveOver (this, true); return true;');
      layer.onmouseout = new Function ('menuUtils.moveOver (this, false); return true;');

      return layer;
    }

    function makeMenu ()
    {
      var i;
      var l, lsub;
      var str;

      this.layer = this.createLayer ();

      for (i = 0; i < this.items.length; i ++)
      {
        l = menuUtils.browserSpecific.newLayer (this.width, this.layer, true);
        l.zIndex = menuUtils._zIndex;
        menuUtils._zIndex ++;
        l._bgColor = this.bgColor;
        l._bgColorOver = this.bgColorOver;
        l._fontColor = this.fontColor;
        l._fontColorOver = this.fontColorOver;
        l._setBgColor (l._bgColor);
        l._link = this.items [i].link;
        l._target = this.items [i].target;
        l._menu = this.items [i].menu;
        l._parentMenu = this;
        l.onmouseover = new Function ('menuUtils.rollOver (this, true); return true;');
        l.onmouseout = new Function ('menuUtils.rollOver (this, false); return true;');
        l.onmouseup = new Function ('menuUtils.doLink (this); return true;');
        l._makeMenu (this, i);

        if (l._menu)
        {
          str  = '<img src="' + this.moreImg + '" ';
          str += 'width="' + this.moreImgWidth + '" ';
          str += 'height="' + this.moreImgHeight + '" ';
          str += 'border="0">';

          lsub = menuUtils.browserSpecific.newLayer (this.moreImgWidth, l);
          lsub._write (str);
          lsub._setZIndex (20);
          lsub._resize (this.moreImgWidth, this.moreImgHeight);
          l._imgLayer = lsub;

          str  = '<img src="' + this.moreImgOver + '" ';
          str += 'width="' + this.moreImgWidth + '" ';
          str += 'height="' + this.moreImgHeight + '" ';
          str += 'border="0">';

          lsub = menuUtils.browserSpecific.newLayer (this.moreImgWidth, l);
          lsub._write (str);
          lsub._setVisibility (false);
          lsub._setZIndex (20);
          lsub._resize (this.moreImgWidth, this.moreImgHeight);
          l._imgLayerOver = lsub;

          if (! l._menu.left)
            l._menu.left = this.layer._left + this.width - this.subMenuOffsetLeft;
          l._menu.itemLayer = l;
        }
      }
    }

    function fixSize ()
    {
      var intTop = 0;
      var i;
      var aryChildren;
      var l;

      if (this.layer)
      {
        this.sizeFixed = true;

        aryChildren = this.layer._getChildren ();

        for (i = 0; i < aryChildren.length; i ++)
        {
          l = aryChildren [i];
          l._moveTo (0, intTop);
          l._height = l._getHeight ();
          this.sizeFixed = this.sizeFixed && (l._height > 0) && (l._height < 300);
          if (this.sizeFixed)
          {
            l._fixWidth ();
            l._setCursor ();
          }

          if (this.sizeFixed && l._menu)
          {
            l._imgLayer._moveTo (l._width - this.borderWidth - this.moreImgOffset - this.moreImgWidth - 1, parseInt ((l._height - this.moreImgHeight) / 2) || 0);
            l._imgLayerOver._moveTo (l._imgLayer._left, l._imgLayer._top);

            if (!l._menu.top)
              l._menu.top = this.layer._top + intTop + this.subMenuOffsetTop;
            l._menu.layer._moveTo (l._menu.left, l._menu.top);
          }

          intTop += (l._height || 1) - 1;
        }

        if (this.sizeFixed)
          this.layer._resize (this._width, intTop + 1);
      }
    }

    function fixPosition ()
    {
      var aryChildren, i, l;
      var intWindowLeft, intWindowTop, intWindowWidth, intWindowHeight
      var intLayerLeft = 0, intLayerTop = 0;
      var el = null, aryCoords;

      if (this.relativeToElement && isString (this.relativeToElement))
      {
        if (document.getElementById)
          el = document.getElementById (this.relativeToElement);
        
        this.relativeToElement = el || document.images [this.relativeToElement] || document.links [this.relativeToElement] || document.anchors [this.relativeToElement] || null;
      }

      if (this.relativeToElement) aryCoords = getPosition (this.relativeToElement);

      if (this.left_delta != null)
      {
        if (this._left_base == null) this._left_base = this.left;
        intLayerLeft = this.layer._left = this.left = this.left_delta + (aryCoords ? aryCoords [0] : this._left_base);
      }
      if (this.top_delta != null)
      {
        if (this._top_base == null) this._top_base = this.top;
        intLayerTop = this.layer._top = this.top = this.top_delta + (aryCoords ? aryCoords [1] : this._top_base);
      }

      intWindowLeft = window.pageXOffset;
      if (document.body)
        intWindowLeft = intWindowLeft || document.body.scrollLeft || 0;
      intWindowTop = window.pageYOffset;
      if (document.body)
        intWindowTop = intWindowTop || document.body.scrollTop || 0;
      intWindowWidth = window.innerWidth || document.body.offsetWidth || 0;
      intWindowHeight = window.innerHeight || document.body.offsetHeight || 0;
      if ((this.layer._left + this.layer._width) > (intWindowLeft + intWindowWidth))
        intLayerLeft = intWindowLeft + intWindowWidth - this.layer._width;
      if (this.layer._left < intWindowLeft)
        intLayerLeft = intWindowLeft;
      if ((this.layer._top + this.layer._height) > (intWindowTop + intWindowHeight))
        intLayerTop = intWindowTop + intWindowHeight - this.layer._height;
      if (this.layer._top < intWindowTop)
        intLayerTop = intWindowTop;
      if (intLayerLeft || intLayerTop)
      {
        intLayerLeft = intLayerLeft || this.layer._left;
        intLayerTop = intLayerTop || this.layer._top;
        this.layer._moveTo (intLayerLeft, intLayerTop);

        aryChildren = this.layer._getChildren ();
        for (i = 0; i < aryChildren.length; i ++)
        {
          l = aryChildren [i];
          if (l._menu)
          {
            l._menu.left_delta = (intLayerLeft - (this._left_base || 0));
            l._menu.top_delta = (intLayerTop - (this._top_base || 0));
          }
        }
      }
      if (! document.layers)
        this.positionFixed = true;
    }

    function setVisible (boolVisible)
    {
      if (this.layer)
      {
        if (boolVisible)
        {
          this.visible = true;
        }
        else
        {
          this.visible = false;
          this.isOver = false;

          this.setHighlight (false)

          if (this.parent.visibleChild == this)
            this.parent.visibleChild = null;
        }
        this.layer._setVisibility (boolVisible);
      }
    }

    function setHighlight (val)
    {
      if (val)
      {
        if (this.highlightedLayer && (this.highlightedLayer != val))
          this.setHighlight (false);

        val._setBgColor (val._bgColorOver);
        val._setFontColor (val._fontColorOver);
        if (val._imgLayer)
        {
          val._imgLayerOver._setVisibility (null);
          val._imgLayer._setVisibility (false);
        }
        this.highlightedLayer = val;
      }
      else
      {
        if (this.highlightedLayer)
        {
          this.highlightedLayer._setBgColor (this.highlightedLayer._bgColor);
          this.highlightedLayer._setFontColor (this.highlightedLayer._fontColor);
          if (this.highlightedLayer._imgLayer)
          {
            this.highlightedLayer._imgLayer._setVisibility (null);
            this.highlightedLayer._imgLayerOver._setVisibility (false);  
          }
          this.highlightedLayer = null;
        }
      }
    }

    function preload ()
    {
      var i;
    
      if (! this.layer)
        this.makeMenu ();

      for (i = 0; i < this.items.length; i ++)
      {
        if (this.items [i].menu)
          this.items [i].menu.preload ();
      }
    }

    function reposition ()
    {
      var i;

      if (! this.sizeFixed)
          this.fixSize ();
      this.fixPosition ();
      this.setHighlight (false);

      for (i = 0; i < this.items.length; i ++)
      {
        if (this.items [i].menu)
          this.items [i].menu.reposition ();
      }
    }

    function cleanUp ()
    {
      var i;
      var aryChildren;

      this.highlightedLayer = null;
      this.visibleChild = null;
      this.itemLayer = null;
      this.parent = null;

      if (this.layer)
      {
        this.layer._menu = null;
        this.layer._parentMenu = null;

        aryChildren = this.layer._getChildren ();
        for (i = 0; i < aryChildren.length; i ++)
        {
          aryChildren [i]._menu = null;
          aryChildren [i]._parentMenu = null;
          aryChildren [i]._imgLayer = null;
          aryChildren [i]._imgLayerOver = null;
        }
        this.layer = null;
      }

      for (i = 0; i < this.items.length; i ++)
      {
        if (this.items [i].menu)
          this.items [i].menu.cleanUp ();
      }
    }
  }

/******
  Restores an image on mouseout of the menu
*/
function SCK_MM_swapImgsRestore ()
{
   var i, x;
   var args = SCK_MM_swapImgsRestore.arguments;

   for (i = 0; i < args.length; i ++)
   {
     if ((x = MM_findObj (args [i])) != null)
     {
       if (x.oSrc)
         x.src = x.oSrc;
     }
   }   
}


var menuUtils = new MenuUtils ();
var Menus = new Object ();

