var Menu = function(el) { if (document.all && el.currentStyle) { this.initList(el, 0) } } Menu.prototype = { initList: function(node, level) { do { switch (node.tagName) { case 'LI': this.initNode(node, level) break case 'UL': level++ break } if (node.firstChild) { this.initList(node.firstChild, level) } } while (node = node.nextSibling) level-- }, initNode: function(node, level) { this.whiteSpace(node) var el = node; do { if (el.className && el.className.search('on') != -1) { return; } //document.getElementById('debug1').innerHTML += el.tagName + '
'; } while ((el = el.parentNode)); //document.getElementById('debug1').innerHTML += el.tagName + '
'; node.onmouseover = function() { if (this.lastChild && this.lastChild.tagName == 'UL') { this.lastChild.style.display = 'block' } } node.onmouseout = function() { if (this.lastChild && this.lastChild.tagName == 'UL') { this.lastChild.style.display = '' } } }, whiteSpace: function(el) { var i = 0 do { if (el.childNodes[i].nodeType == 3 && !/\S/.test(el.childNodes[i].nodeValue)) { el.removeChild(el.childNodes[i]) } } while (el.childNodes[++i]) return el } } /* window.onload = function() { new Menu(document.getElementById('mainNav')); } */