      var mainMenu = {
        idCounter: 1,
        divId: 'hauptnavileiste',
        miActive:null,
        miSelected:null,
        mi2Active:null,
        sbSelected:null,
        colors:{ active: '#666699', inactive: '#807b19',  hilite: '#666699'  },
        timer:null,
        timeout:400,


        stopTimer: function() {
          if (this.timer) {
            window.clearTimeout(this.timer);
            this.timer = null;
          }
        },

        startTimer: function() {
          this.stopTimer();
          this.timer = window.setTimeout('mainMenu.hide();',this.timeout);
        },

        hide: function() {
          this.stopTimer();
          if (this.sbSelected) {
            this.sbSelected.style.display = 'none';
            this.sbSelected = null;
          }
          if (this.miSelected) {
            if (this.miSelected != this.miActive) {
              this.miSelected.bgColor = this.colors.inactive;
            }
            this.miSelected = null;
          }
        },

        changeSelection: function(target) {
          this.stopTimer();
          if (target != this.miSelected) {
            this.hide();
          }
          this.miSelected = target;
          if (this.miSelected != this.miActive) {
            this.miSelected.bgColor = this.colors.hilite;
          }
          var sbId = this.miSelected.id.replace(/mi_/,'menu_');
          this.sbSelected = $(sbId);
          if (this.sbSelected) {
            this.sbSelected.style.display='block';
          }
        },


        init: function(activeMiId,activePos) {        
		  var newDiv = document.createElement("div");
		  newDiv.innerHTML=parent.gMenuTemplate;
		  newDiv.style.position='absolute';
		  newDiv.style.left='0px';
		  newDiv.style.top='0px';		  
		  newDiv.style.zIndex=1000;
		  document.body.insertBefore(newDiv,document.body.firstChild);	
          var mi = $(activeMiId);
          this.miActive = this.miSelected = mi;
          var cells = $(this.divId).getElementsByTagName('table')[0].rows[0].cells;
          for (var i=0; i<cells.length; ++i) {
            var cellId = cells[i].id;
            cells[i].bgColor = (cellId != activeMiId) ? this.colors.inactive : this.colors.active;

            var sbId = cellId.replace(/mi_/,'menu_'); /*submenu*/
            var sb = $(sbId);


            if (sb) {
              sb.style.display='none';
              sb.onmouseout = new Function("mainMenu.startTimer();");
              sb.onmouseover = new Function("mainMenu.stopTimer();");

              var sbCells = sb.getElementsByTagName('table')[0].rows[0].cells;
              for (var j=0; j<sbCells.length; j+=2) {
                sbCells[j].bgColor = this.colors.inactive;
                var a = sbCells[j].getElementsByTagName("a")[0];
                if (a == null) continue;
                var id = a.id || ('mi_a_' + (this.idCounter++));
                a.id = id;
                a.onmouseover = new Function("var e=$('" + id + "');  if (e.parentNode != mainMenu.mi2Active) e.parentNode.bgColor = mainMenu.colors.hilite;");
                a.onmouseout = new Function("var e=$('" + id + "');  if (e.parentNode != mainMenu.mi2Active) e.parentNode.bgColor = mainMenu.colors.inactive;");
              }

              if (cellId == activeMiId && activePos >= 0) {
                var c = sbCells[activePos*2];
                if (c) {
                  this.sbSelected = sb;
                  this.mi2Active = c;
                  sb.style.display='block';
                  c.bgColor = this.colors.active;
                }
              }
            }

            var a = cells[i].getElementsByTagName("a")[0];
            if (a) {
                a.onmouseover = function(e) {
                  e = e || window.event;
                  var target = e.target || e.srcElement;
                  mainMenu.changeSelection(target.parentNode);
                };
               a.onmouseout = function(e) {
                  mainMenu.startTimer();
                };
            }
          }

          $(mainMenu.divId).style.display = 'block';

        }

     };

      function $(id) {
        return document.getElementById(id);
      }
