function DropDownMenu(element, options) {
  var el = (typeof element == 'string') ? document.getElementById(element) : element;
  if (el) this.setOptions(el, options || {});
};

DropDownMenu.prototype.setOptions = function(el, options) {
  this._timeoutInterval = null;
  this._activeElement = [];
  this._delay = options.delay || 1000;
  this.attachEvents(el, 0);
};

DropDownMenu.prototype.addEvent = function(object, name, handler) {
  (document.all) ? object.attachEvent("on" + name, handler) : object.addEventListener(name, handler, false);
};

DropDownMenu.prototype.attachEvents = function(obj, level) {
  var n, i, that;
  that = this;
  i = obj.childNodes.length;
  while (i--) {
    n = obj.childNodes[i];
    switch (n.nodeName) {
      case 'UL': n.style.display = 'none';
        this.addEvent(n, 'mouseover', function() { clearTimeout(that._timeoutInterval); });
        this.addEvent(n, 'mouseout', function() { that.menuOut(); });
        this.attachEvents(n, level + 1);
        break;
      case 'LI': if (i == 0 && level > 0) n.className = 'section';
        this.attachEvents(n, level);
        break;
      case 'A': if (this.getInnerUL(obj)) n.className = 'parent';
        this.addEvent(n, 'mouseover', function() { that.menuOver(n, level) });
        this.addEvent(n, 'mouseout', function() {
          that.menuOut();
        });
        break;
    }
  }
};

DropDownMenu.prototype.menuOut = function() {
  var that = this;
  clearTimeout(this._timeoutInterval);
  this._timeoutInterval = setTimeout(function() {
    that.hideSubmenu(0);
  }, this._delay);
};

DropDownMenu.prototype.getInnerUL = function(o) {
  var i = o.childNodes.length;
  while (i--) if (o.childNodes[i].nodeName == 'UL') {
    return o.childNodes[i];
  }
};

DropDownMenu.prototype.menuOver = function(o, level) {
  clearTimeout(this._timeoutInterval);
  this.hideSubmenu(level);
  var obj = this.getInnerUL(o.parentNode);
  if (obj) {
    this._activeElement[level] = obj;
    obj.style.display = 'block';
  }
};

DropDownMenu.prototype.hideSubmenu = function(index) {
  var i = this._activeElement.length - 1;
  while (i >= index) {
    if (this._activeElement[i]) {
      this._activeElement[i].style.display = 'none';
      this._activeElement.splice(i--, 1);
    }
  }
};
                                        

