// configuration constants
	// cosmetics
	var markEnable = 1; 		//1 activates the text and background marking (slower)
	var borderWidth = 0;
	var gridLines = 0;
	var borderCol = "#003366"
	var textLoCol = "#FFFFFF"
	var textHiCol = "#6699CC"
	var backLoCol = "#003366"
	var backHiCol = "#003366"
	var classLo   = "menu"
	var subImg    = "pijl"
	var nosubImg  = "pijl_leeg"

	var booHorizontal = false	// insanity
	var booBackImages = false	// doesn't work very well in mozilla yet
	if(booBackImages){
		var backLoImg = "back_p"
		var backHiImg = "back_a"
	}
	
	// dimensions
	var menuMinWidth = 72; 		// minimal menu width
	var menuMaxWidth = "100%"; 	// maximal menu width "100%" for free-sizing menus
	var menuHeight = 20;
	var iconWidth = 8;
	
	// position
	var menuAutoPos = true; 		// 'true' activates the menu position approximation (slower)
	var menuPosX = 0-menuMinWidth;
	var menuPosY = 15;
	var subMenuXShift = 0;
	var subMenuYShift = 0;
	var scrollLock = true;
	var edgeCompensation = true;
	
	// operation
	var noDelay = 0;			// 1 disables some wait-loops
	var menuCloseDelay = 1024;
	var menuShowDelay = 256;
	var menuPositionFrequency = 1; // Hz
	var imageFolder = "/images/"
	var imagePrefix = "m_"
	var imageSuffix = ".gif"
	var reportToFrameSet = true // set this to 'true' when foldout_frameset.js is available in the parent frame. This will greatly reduce loading times.
	var showRoot = false
	
		// location of the 'brain-file'
	if(typeof parent.DBarray != 'undefined'){
		DBarray = parent.DBarray
	}
	
	var inits = 0


// primary functions (functions that "do stuff")
	function cacheImages(){
		if(booBackImages){
			cacheBackgroundImage('imgback0',imageFolder+imagePrefix+backLoImg+imageSuffix)
			cacheBackgroundImage('imgback1',imageFolder+imagePrefix+backHiImg+imageSuffix)
		}
	}
	
	// item highlighting functions
	function mark(markobj){
		if(markEnable!=0 && markobj!=0){
			if(booBackImages){
				setBackgroundImage('tb'+markobj,'imgback1')
			}else{
				setBackgroundColour('tb'+markobj,backHiCol)
			}
			setColour('ti'+markobj,textHiCol)
		}
	}
	
	function unmark(unmarkobj){
		if(markEnable!=0 && unmarkobj!=0){
			if(booBackImages){
				setBackgroundImage('tb'+unmarkobj,'imgback0')
			}else{
				setBackgroundColour('tb'+unmarkobj,backLoCol)
			}
			setColour('ti'+unmarkobj,textLoCol)
		}
	}			
	
	// menu foldout/foldin functions
	// Shows a layer absolutely
	function show(obj) {	
		if (inits==1) {
			if(showRoot || obj>0){
				setVisibility('blockDiv'+obj,true)
			}
		}
	}
	
	// Hides a layer absolutely
	function hide(obj) {	
		if (inits==1) {
			setVisibility('blockDiv'+obj,false)
		}
	}


// secondary functions (functions that "control" the primary functions)
	// item highlighting functions
	function unmarkAll(){
		if(n!=1 && markEnable!=0){
			for(var tellerA=1 ; tellerA < DBarray[0] ; tellerA++){
				unmark(DBarray[tellerA][0])
			}
		}
	}
	
	// don't unmark an item if it was highlighted prior
	function unmarkExclusive(unmarkItem){
		if(unmarkItem!=openMenu && noDelay==0){unmark(unmarkItem)}
	}
	
	// don't unmark an item if it was highlighted prior
	function markExclusive(markItem){
		if(noDelay==0){
			if(DBarray[markItem][1]==DBarray[openMenu][1]){unmark(openMenu)}
			mark(markItem)
		}
	}
	
	// menu foldout/foldin functions
	closeBranch = new Array(0,1); openMenu = 0;
	function showExclusive(showobj){ 
			//trace the open menus back to the root
		openBranch = TraceBranch(showobj) 
		//check if the menu's have changed
		if(openBranch[closeBranch.length-1] != closeBranch[closeBranch.length-1]){
			//close (only the changes to) the menu-branch
			for(tellerA = 0; tellerA < closeBranch.length; tellerA++){ 
				if(hasChild(closeBranch[tellerA])>0 && closeBranch[tellerA] != openBranch[tellerA])	{hide(closeBranch[tellerA])}
				if(closeBranch[tellerA] != 0 && closeBranch[tellerA] != openBranch[tellerA])			{unmark(closeBranch[tellerA])}
			}
		}
		//re-open the menu-branch
		for(tellerA = 0; tellerA < openBranch.length; tellerA++){ 
			//openMenu remembers the last opened menu
			if(hasChild(openBranch[tellerA])>0){show(openBranch[tellerA]);openMenu=openBranch[tellerA]}
			if(openBranch[tellerA] != 0){mark(openBranch[tellerA])}
		}
		// store the list of open menus for the next time
		closeBranch = openBranch 
		// lock the function up
		delayPoke = 1
	}

	// Hides all a layer absolutely
	function hideall() {	
		for (var tellerA=1; tellerA<DBarray.length; tellerA++){
			var block = DBarray[tellerA][0]
			if(hasChild(block)>0){hide(block);}
		}
		hide(0);
		unmarkAll();
		closeBranch = Array(0,1)
	}
	
	function aproximateMenuPos(){
		// for every item
		for (var tellerA = 1 ; tellerA < DBarray.length ; tellerA++){
			intItemIndex = DBarray[tellerA][0]
			// if an item has sub-items
			if(hasChild(intItemIndex)>0){
			// X
				// trace item's path back to the root
				arrRootPath = TraceBranch(intItemIndex)
				// it's vertical position is the length of the path * the minimalwidth + default-offsets
				DBarray[intItemIndex][6] = (arrRootPath.length-1)*(menuMinWidth+subMenuXShift)+menuPosX
			
			// Y
				// determine the parent of the item
				intParentIndex = DBarray[intItemIndex][1]
				// filter it's parent's children
				arrPeerItems = FilterContent(1,intParentIndex,0)
				// order the array
				arrContentOrder = FilterContent(1,intParentIndex,8)
				arrPeerItems = OrderContent(arrPeerItems,arrContentOrder)
				// count the position of the current child in the list
				intListPosition = isElementOfArray(intItemIndex,arrPeerItems)
				// it's vertical position is this position*lineheight + it's parent's position + default offset
				if(intParentIndex>0){
					DBarray[intItemIndex][7] = intListPosition * menuHeight + DBarray[intParentIndex][7] + +subMenuYShift
				}else{
					DBarray[intItemIndex][7] = intListPosition * menuHeight + menuPosY +subMenuYShift
				}
			}
		}
	}
		
	// menu layers creation
	function storeMenus(strMenu){
		// where to dump 80KB of generated menus?
		if(reportToFrameSet) parent.strMenu = strMenu
	}
	
	function retrieveMenus(){
	strMenu = -1
		// where to retrieve 80KB of generated menus?
		if(reportToFrameSet) strMenu = parent.strMenu
	return strMenu
	}
	
	function writeMenus(){
		strMenus = retrieveMenus()
		if(strMenus==-1){
			strMenu = generateMenus()
			storeMenus(strMenu)
		}
	document.writeln(strMenu)
	}
	
	
	function generateMenus(){
	if(menuAutoPos){aproximateMenuPos()}
	writeString = "\n"

		// writing all menu blocks
		for (var i=0 ;i<DBarray.length;i++){
			if(hasChild(i)>0){
				// filtering the needed items from the content_ini.js
				menuOrder = FilterContent(1,i,8)
				menuIndex = OrderContent(FilterContent(1,i,0),menuOrder)

				if(i>0){
					intMenuPosX = DBarray[i][6]
					intMenuPosY = DBarray[i][7]
				}else{
					intMenuPosX = menuPosX
					intMenuPosY = menuPosY
				}
				
				// floating layer
				if 		(n==1)	{writeString = writeString+ "<layer name=\"blockDiv"+i+"\" pagex=\""+intMenuPosX+"\" pagey=\""+intMenuPosY+"\" z-index=\"20\" visibility=\"hide\">\n";}
				else if	(ie==1 || m==1){writeString = writeString+ "<DIV ID=\"blockDiv"+i+"\" STYLE=\"position:absolute; left:"+intMenuPosX+"px; top:"+intMenuPosY+"px; z-index:20; visibility:hidden;\" class=\"semitransparant\">\n";}
					
					// table in table for the border
					writeString = writeString+ "<table border=\"0\" cellspacing=\"0\" cellpadding=\""+borderWidth+"\"><tr><td bgcolor=\""+borderCol+"\"><table width=\""+menuMaxWidth+"\" border=\"0\" cellspacing=\""+gridLines+"\" cellpadding=\"2\">\n";
					if(booHorizontal){writeString = writeString + "<tr valign=\"middle\" height=\""+menuHeight+"\">\n"}
					
					//  writing all items in a block
					for(var tellerB=0; tellerB < menuIndex.length; tellerB++){ 
						// properties of the item to be written
						intItemID		= menuIndex[tellerB]
						strItemName		= DBarray[intItemID][10]
						strItemURL		= DBarray[intItemID][3]
						strItemTarget	= DBarray[intItemID][4]
						strItemIcon		= DBarray[intItemID][5]
						intSubMenus		= hasChild(intItemID)
						
						// (re)defining the building-blocks
							// general
							var lineMouseover 	= "onMouseOver=\"menuShouldNotclose();showExclusive("+intItemID+")\" onMouseOut=\"menuShouldClose()\""
							var lineIcon      	= "<img src=\""+imageFolder+imagePrefix+strItemIcon+".gif\" alt=\"\" align=\"left\" hspace=\"0\" vspace=\"0\" border=\"0\">\n"
							var lineItem      	= "<span id=\"ti"+intItemID+"\">"+strItemName+"</span>\n"
							var lineLinkend   	= "</a>"
							var lineCellEnd   	= "</nobr></td>\n"
							var strBackCol		= backLoCol
							var strClass		= classLo
							
							if(!booHorizontal){
								var lineStart 		= "<tr valign=\"middle\" height=\""+menuHeight+"\">\n"
								var lineEnd  		= "</tr>\n"
							}else{
								var lineStart 		= ""
								var lineEnd  		= ""
							}
							
							// in case of background images
							if(booBackImages){
								strBackImg  = "background=\""+imageFolder+imagePrefix+backHiImg+imageSuffix+"\""
							}else{
								strBackImg  = ""
							}


							// submenu indicators
							if(intSubMenus>0){
								lineArrow 	= "<img src=\""+imageFolder+imagePrefix+subImg+imageSuffix+"\" alt=\"\" border=\"0\" align=\"right\">\n"
							}else{
								lineArrow 	= "<img src=\""+imageFolder+imagePrefix+nosubImg+imageSuffix+"\" alt=\"\" border=\"0\" align=\"right\">\n"
							}
							
							// link specific
							if(strItemTarget=="_blank"){
								var lineCellStart 	= "<td nowrap onClick=\"w=window.open('"+strItemURL+"','pop"+tellerB+"','');w.focus()\" "+lineMouseover+" id=\"tb"+intItemID+"\" bgcolor=\""+strBackCol+"\" "+strBackImg+"><nobr>\n"
								var lineLinkstart 	= "<a href=\"javascript:w=window.open('"+strItemURL+"','pop"+tellerB+"','');w.focus()\" "+lineMouseover+" class=\"'+strClass+'\">\n"
							}else if(strItemURL=="javascript:{}"){
								var lineCellStart 	= "<td nowrap onclick=\"noclose=1\" "+lineMouseover+" id=\"tb"+intItemID+"\" bgcolor=\""+strBackCol+"\" "+strBackImg+"><nobr>\n"
								var lineLinkstart 	= "<a href=\""+strItemURL+"\" onclick=\"noclose=1\" "+lineMouseover+" class=\"menu\">\n"
							}else{
								var lineCellStart 	= "<td nowrap onClick=\"document.location.href='"+strItemURL+"'\" "+lineMouseover+" id=\"tb"+intItemID+"\" bgcolor=\""+strBackCol+"\" "+strBackImg+"><nobr>\n"
								var lineLinkstart 	= "<a href=\""+strItemURL+"\" target=\""+strItemTarget+"\" "+lineMouseover+" class=\"menu\">\n"
							}

						// piecing together the items with the building-blocks
							writeString = writeString + ''
							+ lineStart
							+ lineCellStart+lineLinkstart+lineArrow+lineIcon+lineItem+'&nbsp;&nbsp;&nbsp;'
							+ lineLinkend+lineCellEnd
							+ lineEnd

					}
					// end table
					if(booHorizontal){writeString = writeString + "</tr>\n"}
					writeString = writeString+ "</table></td></tr></table>\n"
				// end floating layer
				if (n==1){writeString = writeString+ "</LAYER>\n\n";}else if (ie==1 || m==1){writeString = writeString+ "</DIV>\n\n";}
			}
		}
	return writeString
	}
	

// Ternary functions (functions that "manage"the secondary functions)
	// locks layerblocks' vertical position
	function menuscrolllockinit() {
		// set "child-block"
		for (var tellerA=1; tellerA<DBarray.length; tellerA++){
			block = DBarray[tellerA][0]
			blockItems = hasChild(block)
			if (blockItems>0){
				// store the position in easylayer.js' cache
				intMenuWidth = menuMinWidth+(borderWidth*2)
				intMenuHeight = blockItems*menuHeight+(borderWidth*2)
				defineLayer("blockDiv"+block,true,DBarray[block][6],DBarray[block][7],20,intMenuWidth,intMenuHeight,1,'','',false,false,scrollLock,edgeCompensation)
				// update the position
				setPosition('blockDiv'+block,DBarray[block][6],DBarray[block][7],20,intMenuWidth,intMenuHeight,true,true)
			}
		}
		// set "home-block"
		blockItems = hasChild(0)
		// store the position in easylayer.js' cache
		intMenuWidth = menuMinWidth+(borderWidth*2)
		intMenuHeight = blockItems*menuHeight+(borderWidth*2)
		defineLayer("blockDiv0",true,menuPosX,menuPosY,20,intMenuWidth,intMenuHeight,1,'','',false,false,scrollLock,edgeCompensation)
		// update the position
		setPosition('blockDiv0',menuPosX,menuPosY,20,intMenuWidth,intMenuHeight,1,true,true)
		// report the menus functional
		inits=1;
		// activate easylayers.js' scroll-lock
		if(scrollLock){intRefreshrate=menuPositionFrequency;setScrollLock()}
	}

	var objTimeout0 = 0; var objTimeout1 = 0; var intPreviousRequest = -1
	function menuShouldOpen(setblock){
		if(inits==1){
			// disable the menu closing
			menuShouldNotclose();
			// open the new item after a delay
			if(noDelay==1){
				showExclusive(setblock)
			}else{
				//do not reset timeouts of the same request
				if(intPreviousRequest!=setblock){
					intPreviousRequest = setblock
					clearTimeout(objTimeout1)
					objTimeout1 = setTimeout('intPreviousRequest=-1;showExclusive('+setblock+')',menuShowDelay)
				}
			}
		}		
	}

	function menuShouldClose(){
		if(inits==1){
			// clear previous timeout
			clearTimeout(objTimeout0)
			// start new timeout
			objTimeout0 = setTimeout('menuWillClose()',menuCloseDelay)
		}
	}
	
	function menuShouldNotclose(){
		// clear current timeout
		clearTimeout(objTimeout0)
	}
	
	function menuWillClose(){
		// close all menus
		hideall()
		// reporting back if possible
		if(reportToFrameSet)parent.imenuHasClosed()
	}	



// executed inline
	if(typeof strMenu != 'undefined'){
		// pre-generate menus, if the foldout_document.js is included in the frameset
		strMenu = generateMenus()
	}else{
		//closes the menu if you click anywhere but on it
		if (ns){ 
			document.captureEvents(Event.CLICK); 
			document.onClick = menuWillClose; 
		}else{
			document.onClick = menuWillClose;
		}
		// write the menus to the page
		writeMenus()
		document.close()
		menuscrolllockinit()
		unmarkAll()
	}

