var dropdown = {

	elmmainmenu: null,

	init: function()
	{
		dropdown.events.register(window, 'load', dropdown.loaded);
	},

	loaded: function(e)
	{
		dropdown.elmmainmenu = document.getElementById("menu_tekst");
		if (dropdown.elmmainmenu != null)
		{
			// welke menuitems?
			var tmp = dropdown.elmmainmenu;
			var ul = null;
			while (ul == null)
				for (var n = 0; n < tmp.childNodes.length; n++)
					if (tmp.childNodes[n].nodeType == 1 && tmp.childNodes[n].tagName == "UL")
						ul = tmp.childNodes[n];

			if (ul != null) // ul gevonden
			{
				for (var n = 0; n < ul.childNodes.length; n++)
					if (ul.childNodes[n].nodeType == 1 && ul.childNodes[n].tagName == "LI")
					{
						var subul = ul.childNodes[n].getElementsByTagName("UL");
						if (subul != null && subul.length > 0)
						{
							ul.childNodes[n].__submenu = subul[0];
							ul.childNodes[n].__submenuvis = false;
							ul.childNodes[n].__submenutimer = null;
							if (ul.childNodes[n].id == "")
								ul.childNodes[n].id = "menu_" + n;
						}
					}
				dropdown.events.register(ul, 'mouseover', dropdown.menuover);
				dropdown.events.register(ul, 'mouseout', dropdown.menuover);
			}
		}

	},

	timeout: function(id)
	{
		var elm = document.getElementById(id);
		if (elm != null)
		{
			elm.__submenu.style.display = "none";
			elm.__submenuvis = false;
			elm.__submenutimer = null;
		}
	},

	menuover: function(e)
	{
		var targ;
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3)
			targ = targ.parentNode;
		// zoek naar de li
		var tmp = targ;
		while (tmp != null && tmp.nodeType == 1 && !tmp.__submenu)
			tmp = tmp.parentNode;
		if (tmp.nodeType != 1)
			return true;
		targ = tmp;
		if (targ.tagName != "LI")
			return true;
		if (!targ.__submenu)
			return true;
		dropdown.events.cancel(targ);
		switch (e.type)
		{
		case "mouseover":
			if (targ.__submenuvis != true)
			{
				targ.__submenu.style.display = "block";
				targ.__submenuvis = true;
			}
			if (targ.__submenutimer != null)
			{
				window.clearTimeout(targ.__submenutimer);
				targ.__submenutimer = null;
			}
			break;
		case "mouseout":
			if (targ.__submenuvis == true)
			{
				targ.__submenutimer = window.setTimeout("dropdown.timeout(\"" + targ.id + "\")", 250);
			}
			break;
		}
		return false;
	},

	events: {
		register: function( e , t , f )
		{		
			if( e.attachEvent )
			{
				e.attachEvent( 'on' + t , f ); //ie
			}else if ( e.addEventListener )
			{
				e.addEventListener( t , f , false ); //ff
			}
		},
	
		cancel: function( e )
		{
			if( e.stopPropagation ) e.stopPropagation();
			if( e.preventDefault ) e.preventDefault( );
			e.cancelBubble = true;
		}
	}
};

dropdown.init();
