// Single level menu:
function initSimpleListMenu(listId) {
 if (document.all && document.getElementById) {
  var root = document.getElementById(listId);
  if(!root) return;
  var i = root.childNodes.length;
  while(i--){
   n = root.childNodes[i];
   if (n.nodeName=="LI"||n.nodeName=="li") {
    n.onmouseover = function() { this.className += " over"; }
    n.onmouseout = function() { this.className = this.className.replace(" over", ""); }
   }
  }
 }
}

// Multilevel menu:
var timeoutInterval;
var activeElement;
var DELAY = 1000;

function initList(id){
 var root = document.getElementById(id);
 if(root) attachEvents(root, 0);
 activeElement = Array();
}

function attachEvents(obj, level){
 var n;
 var i = obj.childNodes.length;
 while(i--){
  n = obj.childNodes[i];
  switch(n.nodeName){
   case 'UL':
    n.style.display = 'none';
    n.onmouseover = function(){ clearTimeout(timeoutInterval); } 
    n.onmouseout = mnuOut;
    attachEvents(n, level+1);
    break;
   case 'LI':
	 	if(i == 0 && level > 0) n.className = 'topli';
    attachEvents(n, level);
    break;
   case 'A':
    if(getInnerUL(obj)) n.className = 'parent';
    n.onmouseover = function(){ mnuOver(this, level) } 
    n.onmouseout = mnuOut;
    break;
  }
 }
}

function mnuOut(){
  clearTimeout(timeoutInterval);
 timeoutInterval = setTimeout('hideSubmenu(0)', DELAY);
}

function getInnerUL(o){
 var i = o.childNodes.length;
 while(i--) if(o.childNodes[i].nodeName == 'UL') return o.childNodes[i];
 return null;
}

function mnuOver(o, level){
 clearTimeout(timeoutInterval);
 hideSubmenu(level);
 var obj = getInnerUL(o.parentNode);
 if(obj){
  activeElement[level] = obj;
  obj.style.display = 'block';
 }
}

function hideSubmenu(index){
 var i = activeElement.length - 1;
 while(i >= index){
  if(activeElement[i]){
   activeElement[i].style.display = 'none';
   activeElement.splice(i--, 1);
  }
 }
}

// IE5 Fix, it has no support fpr splice:
if (typeof Array.prototype.splice == "undefined") {
  Array.prototype.splice = function(offset, length) {
    var temp = [];
  for(var i=this.length - 1; i >= 0; i--){
      if (i < offset || i > (offset + length - 1)) {
        temp[temp.length] = this[i];
      }
   this.length--;
    }
  for(var i=this.length - 1; i >= 0; i--){
      this[this.length] = temp[i];
    }
  }
}

