function menuItem(id, name)
{
	this.id			= id;
	this.name		= name;
	this.timer		= null;
	this.active		= false;
	
	this.anchor		= null;
	
	this.children 	= new Array();
}

	menuItem.prototype.addChild = function (menuitem)
	{
		this.children[this.children.length] = menuitem;
	}

	menuItem.prototype.addBehaviour = function (id)
	{
		// reference naar zichzelf
		var li_elm	= document.getElementById(this.id);
		// reference naar de ul die hij moet gaan triggeren
		var ul_elm 	= document.getElementById(id);
		
		var an_elm	= this.anchor;
		
		li_elm.onmouseover = function ()
		{
			ul_elm.style.display = 'block';
			an_elm.className = 'active';
		}
		
		li_elm.onmouseout = function ()
		{
			ul_elm.style.display = 'none';
			an_elm.className = '';
		}
	}

function menu()
{
	this.menu		= null;
	this.timer		= null;
	
	this.activeids 	= new Array();
}

	menu.prototype.init = function (id, counter)
	{
		// clear TimeOud
		
		clearTimeout (this.timer);
		
		// init counter
		
		var counter 	= (counter) ? counter + 1 : 1;
		var target 		= document.getElementById(id);
		
		if (target)
		{
			// De UL selecteren van de hoofditems van het menu
			
			if (target.childNodes[0].nodeName == "UL")
			{
				this.menu = menu.parseUL(new menuItem(null, null), target.childNodes[0]);
			}
		}
		else
		{
			if (counter == 10)
			{
				throw new Error("Timeout... No element found for id: " + id);
			}
			else
			{
				this.timer = setTimeout (function(){menu.init(id, counter)}, 100);
			}
		}
	}
	
	menu.prototype.parseUL = function (menuitem, ul)
	{
		for (var i = 0; i < ul.childNodes.length; i++)
		{
			var item 	= new menuItem(ul.childNodes[i].id);
			
			if (ul.childNodes[i].className.indexOf("active") != -1)
			{
				// we stoppen alle actieve id's in een collection, dat is namelijk makkelijk doorzoeken 
				
				this.activeids[this.activeids.length] = ul.childNodes[i].id;
				
				// we zetten dit item op true
				
				item.active = true;
			}
			
			// we gaan de naam van het menuitem opzoeken en we gaan kijken of er nog een submenu id aanwezig is
			
			for (var j = 0; j < ul.childNodes[i].childNodes.length; j++)
			{
				// id en naam er uit halen, die slaan we op in het menuitem
				
				if (ul.childNodes[i].childNodes[j].nodeName == "A")
				{
					item.id 	= ul.childNodes[i].id;
					item.name 	= ul.childNodes[i].childNodes[j].innerHTML;
					
					item.anchor	= ul.childNodes[i].childNodes[j];
				}
				
				// we hebben nog een submenu, we gaan recursie toepassen
				
				if (ul.childNodes[i].childNodes[j].nodeName == "UL")
				{
					// gedrag aan de knop hangen
					item.addBehaviour(ul.childNodes[i].childNodes[j].id)
					
					// recursie
					item = menu.parseUL(item, ul.childNodes[i].childNodes[j]);
				}
			}
			
			menuitem.addChild(item);
		}
		
		return menuitem;
	}


menu = new menu();
menu.init('navmenu');