function Menu(menu)
{
	this.menu = menu;
	this.menubar = menubar;
	this.menuItems = new Array();
	this.currentSubMenu = null;

	this.setMenu = function()
	{
		for (var i = 0; i <= this.menu.childNodes.length - 1; i++)
		{
			if (this.menu.childNodes[i].tagName == 'LI')
				this.addMenuItem(this.menu.childNodes[i]);
		}
	}

	this.addMenuItem = function(element)
	{
		var menuItem = new MenuItem(element, this);
		this.menuItems.push(menuItem);
	}

	this.setMenu();
}

function MenuItem(element, menu)
{
	this.menu = menu;
	this.element = element;
	this.subMenu = null;
	this.timer = null;
	this.className = element.className;

	var self = this;

	this.element.onmouseover = function()
	{
		self.cancelHide();

		if (self.menu.currentSubMenu != null)
			self.menu.currentSubMenu.hideNow();

		self.element.className = 'hover';
		self.menu.currentSubMenu = self;

		if (self.subMenu)
			self.subMenu.style.display = 'block';
	}

	this.element.onmouseout = function()
	{
		self.hide();
	}

	this.hide = function()
	{
		this.timer = setTimeout(this.hideNow, 500);
	}

	this.hideNow = function()
	{
		self.element.className = self.className;

		if (self.subMenu)
			self.subMenu.style.display = 'none';
	}

	this.cancelHide = function()
	{
		if (this.timer != null)
		{
			clearTimeout(this.timer);
			this.timer = null;
		}
	}

	this.detectSubMenu = function()
	{
		return this.element.getElementsByTagName('UL')[0];
	}

	this.subMenu = this.detectSubMenu();
}

