
function init(){
	initializeLayerPositions();
}


var timerID = null; 
var timerOn = false; 
var timecount = 400; 

function menuOver(layerName){hideAll(); showLayer(layerName); stopTime();}
function menuOut(){ startTime(); }


function showLayer(layerName) { 
	if (document.getElementById) {
		document.getElementById(layerName).style.left = ((getAnchorPosition(layerName+'Link').x)-1) + 'px';
		document.getElementById(layerName).style.visibility="visible"; 
	}
	} 
function hideLayer(layerName) { 	if (document.getElementById) {document.getElementById(layerName).style.visibility="hidden";} } 

function hideAll() {
	if (document.getElementById) {
	hideLayer("menuaanmelden"); hideLayer("menukriq"); hideLayer("menumail"); hideLayer("menupartners");
	}
} 

function startTime() {  if (timerOn == false) {  timerID=setTimeout("hideAll()" , timecount);  timerOn = true;  }  } 
function stopTime() {  if (timerOn) {  clearTimeout(timerID);  timerID = null;  timerOn = false;  }  } 
function onLoad() {  init();  } 

function getAnchorPosition(anchorname) {
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}




var dmenus = ["menuaanmelden","menukriq","menumail","menupartners"];

function initializeLayerPositions()

	{
		
		for (var i = 0; i < dmenus.length; i++) 
			{
				var layerName = dmenus[i];
				if (document.getElementById(layerName))
					{ document.getElementById(layerName).style.left = ((getAnchorPosition(layerName+'Link').x)-1) + 'px'; }
			}
	}

var dmenuaanmelden = 
				[
					["aanmelden", "/aan.php"],
					["afmelden", "/af.php"],
					["wijzigen", "/wijzig.php"],
					["abonneer een vriend(in)", "/vriend.php"]
					
				];
				
var dmenukriq = 
				[
					["Lenthe KriQs van de voorbije week", "/week.php"],
					["veelgestelde vragen", "/faq.php"]
					
				];
				
				
var dmenumail = 
				[
				
					["suggestie aan redactie", "/suggestie.php"],
					["Lenthe KriQ in de fout!", "/fout.php"]
					
				];
	
var dmenupartners = 
				[
					["links of koppelingen", "/links.php"],
          ["Sponsors", "/sponsors.php"]					
				];			
				
				
	
				
function writemenu(location){

	
	if(document.getElementById)
		{
		for (var i = 0; i < dmenus.length; i++) 
			{
				var layerName = 'd'+dmenus[i];		
				document.write("<div id=\"" + dmenus[i] +"\" class=\"dropdownmenu\"  onMouseOver=\"stopTime()\" onMouseOut=\"startTime();\"><ul>");		
				for (var f = 0; f < eval(layerName + '.length'); f++) 
					{
						var str = location;
						var lnk = eval(layerName + "[f][1]");
						var pos=str.indexOf(lnk);
						//alert(pos);
						if (pos>=0)	
							{ var cls = " class=\"active\" ";}
						else
							{ var cls = ""; }
						document.write("<li><a href=\"" + eval(layerName + "[f][1]") + "\"" + cls + ">" + eval(layerName + "[f][0]") + "</a></li>");
					}
					document.write("</ul></div>");
			}
		}
}
