﻿function DropDownMenu(e){
  this.i=null;
  this.j=[];
  this.d=500;  
  this.$l(document.getElementById(e),0);  
};

DropDownMenu.prototype.$z=function(n, l) {
  var o;
  var t=this;
  for (var i = 0; i < n.childNodes.length; i++)
  {
    o = n.childNodes[i];
    switch(o.nodeName) { 
      case 'UL': 
        var p = o.parentNode; 
        this.$m(o,'mouseover',function(){clearTimeout(t.i);});
        this.$m(o,'mouseout',function(){t.$n();});
        this.$z(o,l+1);
        break;
      case 'LI':
        this.$z(o,l);
        break;
      case 'A':
      case 'SPAN':      
        this.$m(o,'mouseover',function(){t.$p(o,l)});
        this.$m(o,'mouseout',function(){t.$n();});
        break;            
    }
  }
};

DropDownMenu.prototype.$l=function(e, l){
  var n,i,o;
  o=this;
  i=e.childNodes.length;
  while(i--){
    n=e.childNodes[i];
    switch(n.nodeName){
      case 'UL':
        if (l > 0) {
          var p = n.parentNode;
        }
        n.style.display='none';
        this.$m(n,'mouseover',function(){clearTimeout(o.i);});
        this.$m(n,'mouseout',function(){o.$n();});
        this.$l(n,l+1);
        break;
      case 'LI':
        this.$l(n,l);
        break;
      case 'A':
      case 'SPAN':      
        this.$m(n,'mouseover',function(){o.$p(n,l)});
        this.$m(n,'mouseout',function(){o.$n();});
        break;
    }
  }
};

DropDownMenu.prototype.$m=function(n,e,f){
  (document.all)?n.attachEvent("on"+e,f):n.addEventListener(e,f,false);
};

DropDownMenu.prototype.$n=function(){
  var o=this;
  clearTimeout(this.i);
  this.i=setTimeout(function(){o.$q(0);},this.d);
};

// returns first UL inside a node
DropDownMenu.prototype.$o=function(e){
  var i=e.childNodes.length;
  while(i--)
    if(e.childNodes[i].nodeName=='UL'){
      return e.childNodes[i];
    }
};

DropDownMenu.prototype.$p=function(o,$e){
  clearTimeout(this.i);
  this.$q($e);
  var $d=this.$o(o.parentNode);
  if($d){
    this.j[$e]=$d;
    $d.style.display='block';
  }
};

DropDownMenu.prototype.$q=function(n){
  var i=this.j.length-1;
  while(i>=n){
    if(this.j[i]){
      this.j[i].style.display='none';
      this.j.splice(i--,1);
     }
   }
};

