  /*
    mxNavBar
    --------
      XP-Like navigation bar .
      Works in opera,ie,netscape 7,mozilla firefox,mozilla ?

    NOTE : you must set the selfRef variable after calling the constructor and before
           calling the createNavBar() function .

    HOW IT WORKS :
    ==============
      See examples for full details of how to define the html .
      Basically the a container table is defined with one cell(td).
      The menu goes in the td . Each menu button is  a table and the items
      for each button are inside a div. The menu buttons are linked to
      the divs by the id of the button table and the items div .
      If the buttons id is "navbarbtnMain1" , then the items div id
      must be "navbarbtnMain1items" (Case sensitive). The createNavBar
      function links all of these named elements together to make it work .

      You can put whatever you want into the items div .

      Class names are :
        mxNavBar        - The table container of the navBar .
        mxNavBarBtn     - The buttons of the bar . These must be tables .
        mxNavBarItems   - Div elements containing the items for each button .
        mxNavBarBtnItem - Some cells inside the buttons . Required only for mouse effects .
        mxNavBarBtnIcon - A cell inside a button containing the up down image . Required only for mouse effects .
  */
  function mxNavBar()
  {
    // set defaults
    this.mxall        = new Array();
    this.container    = null;
    this.buttons      = new Array();
    this.itemsboxes   = new Array();
    this.selfRef      = null;
    this.mxActive     = false;
    this.itemsDownImg = new Image();
    this.itemsUpImg   = new Image();

    // declare standard css class names for navBar . Override these for your own look and feel ,
    // or redefine the standard css etc ...
    this.css_mxNavBarBtn        =  "mxNavBarBtn";
    this.css_mxNavBarItems      =  "mxNavBarItems";
    this.css_mxNavBar           =  "mxNavBar";
    this.css_mxNavBarBtnButton  =  "mxNavBarBtnButton";
    this.css_mxNavBarBtnIcon    =  "mxNavBarBtnIcon";

    this.css_mxNavBarBtnOver        =  "mxNavBarBtnOver";
    this.css_mxNavBarItemsOver      =  "mxNavBarItemsOver";
    this.css_mxNavBarOver           =  "mxNavBarOver";
    this.css_mxNavBarBtnButtonOver  =  "mxNavBarBtnButtonOver";
    this.css_mxNavBarBtnIconOver    =  "mxNavBarBtnIconOver";

    this.css_mxNavBarBtnDown        =  "mxNavBarBtnDown";
    this.css_mxNavBarItemsDown      =  "mxNavBarItemsDown";
    this.css_mxNavBarDown           =  "mxNavBarDown";
    this.css_mxNavBarBtnButtonDown  =  "mxNavBarBtnButtonDown";
    this.css_mxNavBarBtnIconDown    =  "mxNavBarBtnIconDown";


  }

  mxNavBar.prototype.deactivateAll = function()
  {
    return;
    if (!this.mxActive)
    {
      return;
    }
    this.mxActive = false;
    if (this.mxall)
    {
      var i,e;
      for (i=0;i<this.mxall.length;++i)
      {
        e = this.mxall[i];
        if (e)
        {
          this.applyCSS(e);
        }
      }
    }
  }

  mxNavBar.prototype.activate = function()
  {
    return;
    if (this.mxActive)
    {
      return;
    }
    this.mxActive=true;
    if (this.container)
    {
      this.applyCSSOver(this.container);
    }
  }


  mxNavBar.prototype.applyCSSDown = function(e)
  {
    return;
    if (e.ismxNavBarBtn)
    {
      e.className=this.css_mxNavBarBtnDown;
      if (e.mxNavBarBtnButton)
      {
        e.mxNavBarBtnButton.className=this.css_mxNavBarBtnButtonDown;
      }
      if (e.mxNavBarBtnIcon)
      {
        e.mxNavBarBtnIcon.className=this.css_mxNavBarBtnIconDown;
      }
    }
  }

  mxNavBar.prototype.applyCSSOver = function(e)
  {
    return;
    //alert('Apply');
    if (e.ismxNavBarBtn)
    {
      //if (e.className==this.css_mxNavBarBtnOver)
      //{
      //  return;
      //}
      e.className=this.css_mxNavBarBtnOver;
      if (e.mxNavBarBtnButton)
      {
        //alert('ApplyCSSOver: button');
        e.mxNavBarBtnButton.className=this.css_mxNavBarBtnButtonOver;
      }
      if (e.mxNavBarBtnIcon)
      {
        e.mxNavBarBtnIcon.className=this.css_mxNavBarBtnIconOver;
      }
    }
    else if (e.ismxNavBarItems)
    {
      //if (e.className==this.css_mxNavBarItemsOver)
      //{
      //  return;
      //}
      e.className=this.css_mxNavBarItemsOver;
    }
    else if (e.ismxNavBar)
    {
      if (e.className==this.css_mxNavBarOver)
      {
        return;
      }
      e.className=this.css_mxNavBarOver;
    }
  }

  mxNavBar.prototype.applyCSS = function(e)
  {
    if (e.ismxNavBarBtn)
    {
      //if (e.className==this.css_mxNavBarBtn)
      //{
      //  return;
      //}
      e.className=this.css_mxNavBarBtn;
      if (e.mxNavBarBtnButton)
      {
        //alert('ApplyCSS: button');
      //  e.mxNavBarBtnButton.className=this.css_mxNavBarBtnButton;
      }
      if (e.mxNavBarBtnIcon)
      {
        e.mxNavBarBtnIcon.className=this.css_mxNavBarBtnIcon;
      }
    }
    else if (e.ismxNavBarItems)
    {
      //if (e.className==this.css_mxNavBarItems)
      //{
      //  return;
      //}
      e.className=this.css_mxNavBarItems;
    }
    else if (e.ismxNavBar)
    {
      //if (e.className==this.css_mxNavBar)
      //{
      //  return;
      //}
      e.className=this.css_mxNavBar;
    }
  }

  mxNavBar.prototype.createNavBar = function(AContainerId)
  {
    this.container = documentX.getElementById(AContainerId);
    if (!this.container)
    {
      alert('ERROR: mxNavBar- Invalid container in function createNavBar()');
      return;
    }
    // Preload updown images

    this.itemsDownImg.src = this.imgItemsDown;
    this.itemsUpImg.src = this.imgItemsUp;

    mxNavBarManager.addNavBar(this.selfRef);

    this.linkMenu();
  }

  mxNavBar.prototype.linkMenu = function()
  {
    var i,btn,s,aitems,sitems,e,tempall;

    tempall = documentX.getElementsByTagName('',this.container);
    if (!tempall)
    {
      alert('ERROR: mxNavBar - You have not defined any elements in your navBar container .');
      return;
    }

    for (i=0;i<tempall.length;++i)
    {
      e = tempall[i];
      if (e)
      {
        this.mxall[this.mxall.length] = e;
        e.mxNavBar = this.selfRef;
        if (utilsX.isString(e.className) && (e.className=='mxNavBarBtn'))
        {
          //alert('Got button');
          this.buttons[this.buttons.length]=e;
          e.ismxNavBarBtn=true;
        }
      }
    }
    this.mxall[this.mxall.length] = this.container;
    this.container.ismxNavBar = true;
    var incont;
    incont = documentX.getElementsByClassName('mxNavBarContent',this.container);
    if (incont)
    {
      this.container.mxNavBarContent = incont;
    }


    if (!this.buttons)
    {
      alert('ERROR: mxNavBar - You have not defined any button headers in the navBar container.');
      return;
    }

    var col,x,cole,cols,itemchilds;
    for (i=0;i<this.buttons.length;++i)
    {
      btn=this.buttons[i];
      if (btn)
      {
        //alert('button');
        //btn.mxNavBarItems = null;
        col = documentX.getElementsByTagName('',btn);
        if (col)
        {
          //alert('button children');
          for (x=0;x<col.length;++x)
          {
            cole = col[x];
            cole.mxNavBarBtn=btn;
            cole.mxNavBarBtnChild=true;
            if (utilsX.isString(cole.className) && (cole.className.length > 0))
            {
              cols = cole.className.toLowerCase();
              if (cols == "mxnavbarbtnbutton")
              {
                //alert("got btnButton");
                btn.mxNavBarBtnButton = cole;
              }
              else if (cols == "mxnavbarbtnicon")
              {
                btn.mxNavBarBtnIcon = cole;
                var udimg = documentX.getElementsByTagName('',cole);
                if (udimg && (udimg.length > 0) )
                {
                  btn.mxUpDownImg = udimg[0];
                }
              }
            }
            //alert('child' + x);
          }
        }
        s=btn.id;
        if (utilsX.isString(s) && (s.length>0))
        {
          //alert(btn);
          sitems = s + 'items';
          aitems = documentX.getElementById(sitems);
          if (aitems)
          {
            //alert('found items');
            this.itemsboxes[this.itemsboxes.length] = aitems;
            btn.mxNavBarItems=aitems;
            aitems.mxNavBarBtn=btn;
            aitems.mxNavBarBtnChild=false;
            aitems.mxOrigHeight=documentX.elementHeight(aitems);
            aitems.ismxNavBarItems=true;
            itemchilds = documentX.getElementsByTagName('',aitems);
            aitems.mxall=itemchilds;
            if (itemchilds)
            {
              for (x=0;x<itemchilds.length;++x)
              {
                cole=itemchilds[x];
                if (cole)
                {
                  cole.mxNavBarItemsChild=true;
                  cole.mxNavBarItems=aitems;
                }
              }
            }
          }
        }
      }
    }
  }

  mxNavBar.prototype.hoverButtons = function(e)
  {
    return;
    var i,btn;
    for (i=0;i<this.buttons.length;++i)
    {
      btn = this.buttons[i];
      if (btn == e)
      {
        this.applyCSSOver(btn)
      }
      else
      {
        this.applyCSS(btn)
      }
    }
  }

  mxNavBar.prototype.hoverItems = function(e)
  {
    return;
    var i,aitems;
    for (i=0;i<this.itemsboxes.length;++i)
    {
      aitems = this.itemsboxes[i];
      if (aitems == e)
      {
        this.applyCSSOver(aitems)
      }
      else
      {
        this.applyCSS(aitems)
      }
    }
  }


  mxNavBar.prototype.doMouseMove = function(evt)
  {
    //alert('mouseMove');
    return;
    if (!evt)
    {
      alert('ERROR: bad event passed for mouse move !')
      return;
    }
    if (this.mxAnimating)
    {
      return;
    }
    //alert('click');
    this.mxActive = true;
    var e = evt.target;
    if (e.ismxNavBarBtn || e.mxNavBarBtnChild)
    {
      // Over a nav btn
      //this.hoverButtons(e.mxNavBarBtn);
      //this.hoverItems();
    }
    else if (e.ismxNavBarItems || e.mxNavBarItemsChild)
    {
      // Over an items box
      //this.hoverButtons();
      //this.hoverItems(e.mxNavBarItems);
    }
    else
    {
      // over the control , but not over items box or button
      //this.hoverButtons();
      //this.hoverItems();
    }
  }

  mxNavBar.prototype.doMouseDown = function(evt)
  {
    return;
    //alert('mouseDown');
    if (!evt)
    {
      alert('ERROR: bad event passed for mouse move !')
      return;
    }
    //alert('click');
    var e = evt.target;

  }

  mxNavBar.prototype.doClick = function(evt)
  {
    if (!evt)
    {
      alert('ERROR: bad event passed for mouse move !')
      return;
    }
    //alert('click');
    var e = evt.target;

    if (e && e.mxNavBarBtn && e.mxNavBarBtnChild)
    {
      var aitems=e.mxNavBarBtn.mxNavBarItems;
      //alert(aitems);
      if (!aitems.mxAnimating)
      {
        aitems.mxHeightCount=1;
        hideNavBarBtn(aitems.id);
      }
    }
  }

  function hideNavBarBtn(aItemsId)
  {
    var aitems = documentX.getElementById(aItemsId);
    if (!aitems)
    {
      return;
    }
    if (aitems.mxHeightCount==1)
    {
      aitems.mxNavBar.mxAnimating=true;
      aitems.mxAnimating=true;
      if (aitems.style.display=='none')
      {
        aitems.mxHiding=false;
        aitems.style.height=1;
        aitems.style.display='block';
        //xSlideTo(aitems,0,0,1000);
        aitems.mxNavBarBtn.mxUpDownImg.src=aitems.mxNavBar.itemsDownImg.src;
      }
      else
      {
        //alert('hiding');
        //xSlideTo(aitems,-100,0,1000);
        aitems.mxHiding = true;
        aitems.mxNavBarBtn.mxUpDownImg.src=aitems.mxNavBar.itemsUpImg.src;
      }
    }
    var temp;
    var speed;
    speed=6;
    if (aitems.mxHiding)
    {
      temp = (aitems.mxOrigHeight / speed) * (speed - aitems.mxHeightCount);
    }
    else
    {
      temp = (aitems.mxOrigHeight / speed) * (aitems.mxHeightCount);
    }
    documentX.elementHeight(aitems,temp);

    aitems.mxHeightCount = aitems.mxHeightCount + 1;
    if (aitems.mxHeightCount < speed)
    {
      var s='javaScript: hideNavBarBtn("' + aitems.id + '")';
      //alert(s);
      setTimeout(s,10);
    }
    else
    {
      aitems.mxNavBar.mxAnimating=false;
      aitems.mxAnimating=false;
      if (aitems.mxHiding)
      {
        aitems.style.display='none';
      }
      else
      {
        documentX.elementHeight(aitems,aitems.mxOrigHeight);
      }
    }
  }


  function mxNavBarClick(oEvent)
  {
    //return;
    var evt = new xEvent(oEvent);
    var ele = evt.target;
    // if mouse clicked over a navBar .
    if (ele.mxNavBar)
    {
      // process the mouse click for the navBar
      ele.mxNavBar.doClick(evt);
    }
    else
    {
      // mouse clicked on element not in a menu .
      //
    }
  }

  function mxNavBarMouseMove(oEvent)
  {
    return;
    var evt = new xEvent(oEvent);
    var ele = evt.target;
    // if mouse clicked over a navBar .
    if (ele.mxNavBar)
    {
      // process the mouse click for the navBar
      ele.mxNavBar.activate;
      ele.mxNavBar.doMouseMove(evt);
    }
    else
    {
      // mouse clicked on element not in a menu .
      //
      mxNavBarManager.deactivateAll();
    }
  }

  function mxNavBarMouseDown(oEvent)
  {
    return;
    var evt = new xEvent(oEvent);
    var ele = evt.target;
    // if mouse clicked over a navBar .
    if (ele.mxNavBar)
    {
      // process the mouse click for the navBar
      ele.mxNavBar.doMouseDown(evt);
    }
    else
    {
      // mouse clicked on element not in a menu .
      //
    }
  }




  // create menu manager object .
  function TmxNavBarManager()
  {
    // array to hold list of menus in a page
    this.trappedMouse = false;
    this.navBars=new Array();
  }

  var mxNavBarManager = new TmxNavBarManager();

  TmxNavBarManager.prototype.deactivateAll = function()
  {
    return;
    //alert('dall');
    if (this.navBars)
    {
      var i;
      for (i=0;i<this.navBars.length;++i)
      {
        if (this.navBars[i])
        {
          this.navBars[i].deactivateAll();
        }
      }
    }
  }

  // Add mxmenu object to menu
  TmxNavBarManager.prototype.addNavBar = function(aNavBar)
  {
    if (aNavBar)
    {
      this.navBars[this.navBars.length]=aNavBar;
      if (!this.trappedMouse)
      {
        xAddEventListener(document, 'click', mxNavBarClick, false);
        //xAddEventListener(document, 'mousemove', mxNavBarMouseMove, false);
        //xAddEventListener(document, 'mousedown', mxNavBarMouseDown, false);
        this.trappedMouse = true;
      }
    }
  }


  /*
    Nav button functions , these are the functions to handle highlighting
    for the default item buttons. You can define your own or change the css for
    different effects.
  */
    function navBarBitBtnMouseOver(se)
    {
      //alert('Move');
      var btn,btntext,btnicon;
      btn     = documentX.getElementById(se);
      btntext = documentX.getElementById(se + 'text');
      btnicon = documentX.getElementById(se + 'icon');
      if (btn && (btn.className != "xxnavBarBitBtnOver") ) btn.className = "navBarBitBtnOver";
      if (btntext && (btntext.className != "xxnavBarBitBtnTextOver") ) btntext.className = "navBarBitBtnTextOver";
      if (btnicon && (btnicon.className != "xxnavBarBitBtnIconOver") ) btnicon.className = "navBarBitBtnIconOver";

    }
    function navBarBitBtnMouseDown(se)
    {
      var btn,btntext,btnicon;
      btn     = documentX.getElementById(se);
      btntext = documentX.getElementById(se + 'text');
      btnicon = documentX.getElementById(se + 'icon');
      if (btn && (btn.className != "xxnavBarBitBtnDown") ) btn.className = "navBarBitBtnDown";
      if (btntext && (btntext.className != "xxnavBarBitBtnTextDown") ) btntext.className = "navBarBitBtnTextDown";
      if (btnicon && (btnicon.className != "xxnavBarBitBtnIconDown") ) btnicon.className = "navBarBitBtnIconDown";
    }
    function navBarBitBtnMouseOut(se)
    {
      var btn,btntext,btnicon;
      btn     = documentX.getElementById(se);
      btntext = documentX.getElementById(se + 'text');
      btnicon = documentX.getElementById(se + 'icon');
      if (btn && (btn.className != "xxnavBarBitBtn") ) btn.className = "navBarBitBtn";
        //alert('1');
      if (btntext && (btntext.className != "xxnavBarBitBtnText") )
      {
        //alert('1');
        btntext.className = "navBarBitBtnText";
      }
      if (btnicon && (btnicon.className != "xxnavBarBitBtnIcon") ) btnicon.className = "navBarBitBtnIcon";
    }



