

function Menu(ulElt) {
	this.element = ulElt;
	this.init();
};
Menu.prototype = {
	init : function() {
		this.items = [];
		var kids = this.element.childNodes;
		for(var i=0; i<kids.length; i++) {
			if(kids[i].nodeType == 1 && kids[i].tagName.toLowerCase() == "li") {
				this.items[this.items.length] = new MenuItem(kids[i], this);
			}
		}
		this.reset();
	},
	
	reset : function() {
		for(var i=0; i<this.items.length; i++) {
			var it = this.items[i];
			if(it.isCurrentSection) {
				it.on();
			} else {
				it.off();
			}
		}
	},
	
	clear : function() {
		for(var i=0; i<this.items.length; i++) {
			this.items[i].off();
		}
	}
};


function MenuItem(liElt, menu) {
	this.element = liElt;
	this.menu = menu;
	this.init();
};
MenuItem.prototype = {
	init : function() {
		this.isCurrentSection = this.element.className.match("current-section") ? true : false;
	
		var subUl = this.element.getElementsByTagName("ul")[0];
		if(subUl) {
			this.submenu = new SubMenu(subUl);
		}
		
		var self = this;
		this.element.onmouseover = function() {
			if(self.menu.timer) clearTimeout(self.menu.timer);
			self.menu.clear();
			self.on();
		};
		this.element.onmouseout = function() {
			self.menu.timer = setTimeout(function(){self.menu.reset();}, 500);
		};
	},
	
	on : function() {
		if(this.submenu) {
			this.submenu.show();
		}
	},
	
	off : function() {
		if(this.submenu) {
			this.submenu.hide();
		}
	}
};

function SubMenu(ulElt) {
	this.element = ulElt;
	this.init();
};
SubMenu.prototype = {
	init : function() {
	},
	
	show : function() {
		this.element.style.display = "block";
	},
	
	hide : function() {
		this.element.style.display = "none";
	}
};






