var to = null;
var ytems = new Array("adverteren", "info");
if (document.getElementById) {
	var cando = true;
} else {
	var cando = false;
}

function menu_init() {
	if (cando) {
		for (key in ytems) {
			id = "a_menu_" + ytems[key];
			e  = document.getElementById(id);
			e.onmouseover = menu_e;
			if (e.captureEvents) e.captureEvents(Event.MOUSEOVER);
			
			id = "menupopup_" + ytems[key];
			e = document.getElementById(id);
			e.onmouseover = menu_clear_to;
			e.onmouseout  = menu_hide_to;
		}
	}
}

function menu_e(e) {
	if (cando) {
		menu_clear_to();
		
		if (!e) e = window.event;
		if (!e.target) e.target = e.srcElement;
		
		et = e.target; // et is nu <a>
		
		/*
		mp = document.getElementById("menupopup");
		for (k in et) {
			mp.innerHTML += k + " = " + et[k] + "<h" + "r>";
		}
		mp.style.display = "block";
		*/
		
		// et.id ~= a_menu_teksten | a_menu_redactie
		// alert("et.id = `" + et.id + "`");
		ytem = et.id.substr(7);
		menu_view(ytem, e);
	}
}

function cmbVisibility(visibility) {
	// bepaalde <select> boxen weghalen (of tonen), ivm IE, die laat <select> altijd `bovenaan` zien, dus valt het popup menu er onder
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		cmb = document.getElementById("cmbSport");
		if (cmb) {
			cmb.style.visibility = visibility;
		}
	}
}

function menu_view(ytem, e) {
	if (cando) {
		if (!e && window.event) e = window.event;
		
		if (e) {
			mp = document.getElementById("menupopup_" + ytem);
			
			if (!mp) alert("function menu_view() : ytem = `" + ytem + "`");
			
			if (mp.style.display == "block") {
				// wordt al getoond
			} else {
				for (key in ytems) {
					document.getElementById("menupopup_" + ytems[key]).style.display = "none";
				}
				
				if ( (ytem == "Login") && (ingelogd == "true") && (type == "admin") )
				{
					cmbVisibility("hidden");
				}
				
				y = e.clientY;
				y = 0;
				
				if (!e.target) e.target = e.srcElement;
				e = e.target;
				
				while (e.offsetParent.tagName != "BODY") {
					y = y + e.offsetTop;
					e = e.offsetParent;
				}
				
				mp.style.display = "block";
				mp.style.top = y;
				mp.style.marginTop = "18px";
				
				ua = navigator.userAgent.toLowerCase();
				if ( (document.all) && (ua.indexOf("opera") == -1) ) {
					// IE
					if (ytem == "adverteren") {
						mp.style.marginLeft = -178;
						mp.style.marginTop = -14;
					} else if (ytem == "info") {
						mp.style.marginLeft = -188;
						mp.style.marginTop = -30;
					}
				}
				else {
					if (ytem == "adverteren") {
						mp.style.marginLeft  = "126px";
						mp.style.marginTop   = "-14px";
					}
					else if (ytem == "info") {
						mp.style.marginLeft  = "126px";
						mp.style.marginTop   = "-30px";
					}
				}
				
				// mp = document.getElementById("mp_" + ytem);
				
				if (ytem == "adverteren") {
					mp.innerHTML  = '<a href="' + menupath + 'adverteren/waarom-adverteren/" TARGET="welkom.htm">waarom adverteren</a><br>';
					mp.innerHTML += '<a href="' + menupath + 'adverteren/kosten/" TARGET="welkom.htm">kosten</a><br>';
					mp.innerHTML += '<a href="' + menupath + 'adverteren/verblijf-aanmelden/" TARGET="welkom.htm">aanmelden</a><br>';
					mp.innerHTML += '<a href="' + menupath + 'adverteren/hotel-pension-aanmelden" TARGET="welkom.htm">hotel/pension aanmelden</a><br>';
					mp.innerHTML += '<a href="http://www.holland-vakantiehuis.nl/adverteren/banners/" TARGET="_blank">adverteren d.m.v. banners</a><br>';
				} else if (ytem == "info") {
					mp.innerHTML  = '<a href="' + menupath + 'informatie/contact/" TARGET="welkom.htm">contact</a><br>';
					mp.innerHTML += '<a href="' + menupath + 'informatie/voorwaarden/" TARGET="welkom.htm">voorwaarden</a><br>';
					mp.innerHTML += '<a href="' + menupath + 'informatie/schoolvakanties/" TARGET="welkom.htm">schoolvakanties</a><br>';
					mp.innerHTML += '<a href="' + menupath + 'informatie/tip-een-vriend/" TARGET="welkom.htm">tip een vriend</a><br>';
					mp.innerHTML += '<a href="' + menupath + 'informatie/wie-zijn-wij/" TARGET="welkom.htm">wie zijn wij</a><br>';
				}
			}
		}
	}
}

function menu_hide() {
	if (cando) {
		for (key in ytems) {
			e = document.getElementById("menupopup_" + ytems[key]);
			e.style.display = "none";
		}
		cmbVisibility("visible");
	}
}

function menu_hide_to() {
	to = setTimeout("menu_hide()", 500);
}

function menu_clear_to() {
	clearTimeout(to);
}