// menu getest in IE 5, IE 6, IE 7, FF 1.0, FF 1.5, FF 2, O 7.11, O 8.01, 0 9.1

var to = null;
var sto = null;
var submenusaanwezig = false;
var submenu = false; // submenu in beeld ja of nee

var is_opera = (navigator.userAgent.indexOf("Opera/") != -1);
var is_ie = ( (navigator.userAgent.indexOf("MSIE ") != -1) && (!is_opera) );
var is_ie8 = ( (navigator.userAgent.indexOf("MSIE 8.") != -1) && (!is_opera) );
var is_gecko = (navigator.userAgent.indexOf("Gecko/") != -1);

if (document.getElementById) {
	var cando = true;
} else {
	var cando = false;
}

function getE(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	else if (document.all) {
		return document.all[id];
	}
	else {
		return null;
	}
}

function menu_init() {
	if (cando) {
		for (key in ytems) {
			id = "a_menu_" + ytems[key]; // A
			e  = document.getElementById(id);
			if (e) {
				e.onmouseover = menu_e;
				if (e.captureEvents) e.captureEvents(Event.MOUSEOVER);
				e.onmouseout  = menu_hide_to;
				if (e.captureEvents) e.captureEvents(Event.MOUSEOUT);
			}
			
			id = "menupopup_" + ytems[key]; // DIV
			e = document.getElementById(id);
			if (e) {
				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 <img>
		
		ytem = et.id.substr(7);
		
		/*
		et.className = 'actief';
		*/
		
		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 (is_ie) {
		/*
		cmb = document.getElementById("cmbMaand");
		if (cmb) {
			cmb.style.visibility = visibility;
		}
		cmb = document.getElementById("cmbJaar");
		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) {
				// HOOFDMENU's
				
				if (mp.style.display == "block") {
					// wordt al getoond
				} else {
					for (key in ytems) {
						var e2 = document.getElementById("menupopup_" + ytems[key]);
						if (e2) {
							e2.style.display = "none";
						}
						
						/*
						var e3 = document.getElementById("a_menu_" + ytems[key]);
						if (e3) {
							if (ytems[key] == ytem) {
								e3.className = "actief";
							}
							else {
								e3.className = "inactief";
							}
						}
						*/
					}
					
					if (ytem == "...") {
						cmbVisibility("hidden");
					}
					
				//	x = e.clientX;
					x = 0;
				//	y = e.clientY;
					y = 0;
					
					if (!e.target) e.target = e.srcElement;
					e = e.target;
					
				/*
					while (e.offsetParent.tagName != "BODY") {
					//	alert(e.offsetParent.tagName);
					//	alert(e.offsetLeft);
					//	if (e.offsetParent.tagName != "TABLE")
						
						x = x + e.offsetLeft;
						y = y + e.offsetTop;
						e = e.offsetParent;
					}
				*/
				
					/*
					if (is_ie || is_opera) {
						x = Math.floor((document.body.scrollWidth - 1000) / 2) + x;
					}
					*/
					
					// margin-left instellingen voor IE staan in HTML code
					// margin-top instellingen voor IE staan in CSS code
					
					if (is_gecko || is_ie8 || is_opera) {
						mp.style.marginTop  = "15px";
						
						if (ytem == "dezorggroep") {
							mp.style.marginLeft = "190px";
						}
						else if (ytem == "dienstenenproducten") {
							mp.style.marginLeft = "296px";
						}
						else if (ytem == "wonenbij") {
							mp.style.marginLeft = "450px";
						}
						else if (ytem == "werkenbij") {
							mp.style.marginLeft = "550px";
						}
						else if (ytem == "nieuws") {
							mp.style.marginLeft = "625px";
						}
						else if (ytem == "contact") {
							mp.style.marginLeft = "679px";
						}
					}
					
					mp.style.display = "block";
					
				//	mp.style.left = x;
				//	mp.style.top = y;
					
				/*
					if (!is_ie) {
						mp.style.left = x;
						
						mp.style.marginLeft = "132px";
						mp.style.marginTop = "-6px";
					}
					else {
						mp.style.marginLeft = "-90px";
						mp.style.marginTop = "30px";
					}
				*/
					
					for (key in ytems) {
						if (ytems[key] == ytem) {
							var menu_content = getE('menupopup_' + ytem).innerHTML;
							var ih = '<div class="menupopupcontainer" id="menupopupcontainer">' + menu_content + '</div>';
							mp.innerHTML = ih;
						}
					}
				}
			}
		}
	}
}

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

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

function menu_clear_to() {
	clearTimeout(to);
}
