//Do you want images (if not set to 0 and remove the images from the body)
foldImg = true;

//Here are the images for the top links. (html-source)
//Here are the images for the sub links. (html-source)

pxbetweenmain = 0;          // space between the main menus (10)
pxbetweensub  = 0;          // space between the sub menus (5)

mainstayfolded = false;     // Should the main menus stay folded?
substayfolded  = false;     // Should the sub menus stay folded?


var myUrl      = window.location.href;      // complete url
var myPathName = window.location.pathname;  // path without parameter info
var myQuery    = window.location.search;    // query part

// get directory part, without servername (all url's need to link from root)
var myFileName = myPathName + myQuery;      // compare with complete root-dir

//alert(myFileName);

myBoldLevel    = new Object();              // collect info of selected menu item

// Checks if the url of the loaded page equals the reference url of an item
function getInitialExpanded(levelDepth, ref) {
    if (((levelDepth == 1) || (levelDepth == 2) || (levelDepth == 3)) && (ref != '' && myFileName.indexOf(ref) == 0)) {
        return true;
    }
    return false;
}


function check_current_level() {
    var expanded = 0;
    var p = -1;
    for (var i in items) {
        myReference = items[i].ref;

        if ( myReference != '' && myFileName.indexOf(myReference) == 0 ) {
            if ( p != -1 ) {
                if ( myLevelDepth > 1 ) {
                    changeFontToNormal( items[p].level );   // parent with same ref (url) is already expanded and in bold, reset it to normal
                    changeFontToBold(   items[i].level );   // set active level in bold
                    items[p].expanded = 0;
                    items[i].expanded = 1;
    
                    a = new Array;
                    a = items[i].level.split('_');
                    var myLevelDepth = items[i].levelDepth;
    
                    subfoldmenu(a[myLevelDepth-2],a[myLevelDepth-1]);     // foldout deeper level, parent is already foldet out
                }
                else {}     // ignore this item, already other level in bold
            }
            else { triggermenu( items[i].level ); } // foldout (sub-)menu

            expanded = 1;
            p = items[i].id;
        }
    }
    if (! expanded) {
        // foldout (standard) main menu
        if (myMainMenu != null) {
            triggermenu(myMainMenu);            // foldout standard (sub-)menu if no other menu is foldet out
        }
    }
}

// Create tree of item objects
function item(level, id, ref) {
    a = new Array;
    a = level.split('_');

    this.levelDepth = a.length;
    this.level      = level;
    this.id         = id;
    this.ref        = ref;
    this.parent     = getParent(this.level);
    this.expanded   = getInitialExpanded(this.levelDepth, this.ref);

    if (this.expanded) {
        // collect data of current menu item
        myBoldLevel.main = a[0];
        myBoldLevel.id   = id;
        if (this.levelDepth > 1) { myBoldLevel.sub = a[1]; }
    }
}

// Get the parent item of level 2 items, -1 for level 0 or level 1 items 
function getParent(level) {
        var par = 0;
        if ( level.indexOf('_') != -1 ) {
            var a = level.split('_');
            if (a[2]) { par = a[0]+'_'+a[1]; }
            else { par = -1; }
        }
        else { par = -1; }

        return par;
}

function triggermenu (level) {
    if (loaded_ok == 1) {

        if (level != '') changeFontToBold(level);        // print this text in bold (-> current menu item)
        var parent;

        // search parent
        if ( level.indexOf('_') == -1 ) { 
            // CHECKING FASE
            parent = level;             // foldout main level
        }
        else { 
            parent = level.substring(0,level.lastIndexOf('_')); 
        }

        // foldout level(s)
        if ( level != null && level.indexOf('_') != -1 ) {        // parent is sublevel
            var a           = level.split('_');
            var levelDepth  = a.length;
            foldmenu(a[0]);             // foldout main level
            if ( levelDepth > 2 ) {
                subfoldmenu(a[0],a[1]);     // foldout deeper level (ONLY IF SUBNAV !!)
            }
            else {
                for (var i in items) {
                    // search if there are sublevels to this item
                    if ( items[i].level == level+'_0' ) {
                        subfoldmenu(a[0],a[1]);     // foldout deeper level (ONLY IF SUBNAV !!)
                    }
                }
            }
        }
        else {                                                      // parent is main level
            if (parent != null && parent != '') {
                foldmenu(parent);           // foldout main level
            }
        }

/*        
        // foldout parent(s)
        if ( parent != null && parent.indexOf('_') != -1 ) {        // parent is sublevel
            var a = parent.split('_');
            foldmenu(a[0]);             // foldout main level
            subfoldmenu(a[0],a[1]);     // foldout deeper level
        }
        else {                                                      // parent is main level
            if (parent != null && parent != '') {
                foldmenu(parent);           // foldout main level
            }
        }
*/

    } else {
        setTimeout('triggermenu("'+level+'")', 50);
    }
}


/**********************************************************************************   
FoldoutMenu2 
*   Copyright (C) 2001 Thomas Brattli
*   This script was released at DHTMLCentral.com
*   This may be used and changed freely as long as this msg is intact!
*
*   Made by Thomas Brattli
*
*   Script date: 09/04/2001 (keep this date to check versions) 
*********************************************************************************/
function lib_bwcheck(){     //Browsercheck (needed)
	this.ver    = navigator.appVersion;
	this.agent  = navigator.userAgent;
	this.dom    = document.getElementById?1:0;
	this.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0;
	this.ie5    = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6    = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4    = (document.all && !this.dom && !this.opera5)?1:0;
	this.ie     = this.ie4||this.ie5||this.ie6;
	this.mac    = this.agent.indexOf("Mac")>-1;
	this.ns6    = (this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4    = (document.layers && !this.dom)?1:0;
	this.bw     = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this
}
var bw=lib_bwcheck();

if(document.layers){    //NS4 resize fix...
	scrX = innerWidth; scrY = innerHeight;
	onresize= function(){if(scrX!= innerWidth || scrY!= innerHeight){history.go(0)} }
}

if(navigator.userAgent.indexOf('Opera')>-1 && document.getElementById){ //Opera 5 resize fix.
	scrX= innerWidth; scrY= innerHeight;
	document.onmousemove= function(){
		if(scrX<innerWidth-10 || scrY<innerHeight-10 || scrX>innerWidth+10 || scrY>innerHeight+10){
			scrX = innerWidth;
			scrY = innerHeight;
			foldInit();
		}
	};
}


/************************************************************************************
Making cross-browser objects
************************************************************************************/
function makeMenu(obj,nest){
	nest=(!nest) ? "":'document.'+nest+'.';
   	this.css = bw.dom ? document.getElementById(obj).style
   	                  : bw.ie4 ? document.all[obj].style
   	                           : bw.ns4 ? eval(nest+"document.layers." +obj)
   	                                    : 0;
	this.elm = bw.dom ? document.getElementById(obj)
	                  : bw.ie4 ? document.all[obj]
	                           : bw.ns4 ? eval(nest+'document.'+obj)
	                                    :0;
	this.ref = bw.dom || bw.ie4 ? document
	                            : bw.ns4 ? eval(nest+"document.layers." +obj+".document")
	                            : 0;   // document.layers.divFold4
	this.x = bw.ns4 ? this.css.left
	                :bw.opera5 ? this.css.pixelLeft
	                           : this.elm.offsetLeft;
	this.y = bw.ns4 ? this.css.top
	                : bw.opera5 ? this.css.pixelTop
	                            : this.elm.offsetTop;
	this.height = bw.ns4 ? this.ref.height
	                     : bw.opera5 ? this.css.pixelHeight
	                                 : this.elm.offsetHeight;
	this.hideIt = b_hideIt;
	this.showIt = b_showIt;
	this.moveIt = b_moveIt;
	this.status = 0;
	return this;
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function b_showIt(){this.css.visibility="visible"; this.status=1}
function b_hideIt(){this.css.visibility="hidden"; this.status=0}
function b_moveIt(x,y){this.x=x; this.y=y; /*this.css.left=this.x+px;*/ this.css.top=this.y+px;}


/************************************************************************************
Initiating the page and making the menu
************************************************************************************/
function foldInit(){
	//Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
	bw.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (bw.opera5) bw.ns6 = 0

	//Creating the foldoutmenu
	oFold = new Array();
	y = 0;
	for (var i=0; i<mainmenus; i++){
		oFold[i] = new makeMenu('divFold'+i,'divFoldCont');
		oFold[i].moveIt(0,y);
		oFold[i].size = oFold[i].height;
		y += oFold[i].height+pxbetweenmain;
		if (bw.ns4) oFold[i].css.clip.bottom = 500;
		oFold[i].sub = new Array();
		oFold[i].subs = top_subs;
		suby = oFold[i].height+pxbetweensub;
		for (var j=0; j<submenus[i]; j++){
			oFold[i].sub[j] = new makeMenu('divFoldSub'+i+'_'+j,'divFoldCont.document.divFold'+i);
			oFold[i].sub[j].sub = new makeMenu('divFoldSub'+i+'_'+j+'_0','divFoldCont.document.divFold'+i+'.document.divFoldSub'+i+'_'+j);
			oFold[i].sub[j].hideIt();
			oFold[i].sub[j].sub.hideIt();
			oFold[i].sub[j].moveIt(10,suby);
			suby += oFold[i].sub[j].height+pxbetweensub;
		}
	}
  	oFoldCont = new makeMenu('divFoldCont');
	if (bw.ns4) oFoldCont.css.clip.bottom = 800;
  	oFoldCont.showIt();         // Show the menu when the menu has been "created"

    loaded_ok = 1;
    check_current_level();      // expand current selection
}

/************************************************************************************
Object function to the top of the menus.
************************************************************************************/
function top_subs(show, num){
	for (var j=0; j<this.sub.length; j++){
		if (show){
			this.sub[j].showIt();
			if (foldImg) { 
			    this.ref["imgFold"+num].src = foldoutImg.src;
			}
			if (substayfolded) {
			    if (this.sub[j].sub.status) {
			        this.sub[j].sub.showIt();
			    }
			}
			else{
				if (foldImg) this.sub[j].ref["imgFoldSub"+num+'_'+j].src = foldsubinImg.src;
				this.sub[j].sub.hideIt();
			}
		}
		else{
			this.sub[j].hideIt();
			if (foldImg) {
			    this.ref["imgFold"+num].src = foldinImg.src;
			}
			if (!substayfolded) {
			    this.sub[j].sub.hideIt();
			}
			else if (substayfolded) {
			    this.sub[j].sub.css.visibility="hidden";
			}
		}
	}
}

/************************************************************************************
Checking height of the menus, and moves them to the correct position.
************************************************************************************/
function checkheight(org){
	if(mainstayfolded) istart=org; else istart=0
	for(i=istart;i<oFold.length;i++){
		oFold[i].size=oFold[i].height
		for(j=0;j<oFold[i].sub.length;j++){
			oFold[i].sub[j].size=oFold[i].sub[j].height+pxbetweensub
			if(oFold[i].sub[j].status){
				oFold[i].size+=oFold[i].sub[j].size
				if(oFold[i].sub[j].sub.status){
					oFold[i].size+=oFold[i].sub[j].sub.height+pxbetweensub
					oFold[i].sub[j].size+=oFold[i].sub[j].sub.height+pxbetweensub
				}
			}
			if(j!=0) oFold[i].sub[j].moveIt(10,oFold[i].sub[j-1].y+oFold[i].sub[j-1].size)
		}
		if(i!=0) oFold[i].moveIt(0,oFold[i-1].y+oFold[i-1].size+pxbetweenmain)
	}
}

/************************************************************************************
Fold in and out the submenus.
************************************************************************************/
function subfoldmenu(main,sub){
	if (! substayfolded){
		for (var i=0; i<oFold[main].sub.length; i++){
			if (i!=sub){
				oFold[main].sub[i].sub.hideIt();

                if (myBoldLevel.main && myBoldLevel.sub && oFold[myBoldLevel.main].sub[myBoldLevel.sub]) {
                    if (! oFold[myBoldLevel.main].sub[myBoldLevel.sub].sub.status) {
                        // change font of parent of current item to bold, if current child becomes not visible
                        changeFontToBold(items[myBoldLevel.id].parent);
                    }
                }

				if (foldImg) oFold[main].sub[i].ref["imgFoldSub"+main+'_'+i].src = foldsubinImg.src
			}
		}
	}
	if (!oFold[main].sub[sub].sub.status){
		oFold[main].sub[sub].sub.showIt()

        if (myBoldLevel.main && myBoldLevel.sub && oFold[myBoldLevel.main].sub[myBoldLevel.sub]) {
            if (oFold[myBoldLevel.main].sub[myBoldLevel.sub].sub.status) {
                // change font of parent back to normal, if one of its children is bold
                changeFontToNormal(items[myBoldLevel.id].parent);
            }
            // als ander menu wordt opengeklapt, zet parent in bold
            //else {}
        }

		if(foldImg) oFold[main].sub[sub].ref["imgFoldSub"+main+'_'+sub].src = foldsuboutImg.src
	}
	else{
		oFold[main].sub[sub].sub.hideIt()

        if (myBoldLevel.main && myBoldLevel.sub && oFold[myBoldLevel.main].sub[myBoldLevel.sub]) {
            if (! oFold[myBoldLevel.main].sub[myBoldLevel.sub].sub.status) {
                // change font of parent of current item to bold, if current child becomes not visible
                changeFontToBold(items[myBoldLevel.id].parent);
            }
        }

		if(foldImg) oFold[main].sub[sub].ref["imgFoldSub"+main+'_'+sub].src = foldsubinImg.src
	}
	checkheight(main);
}

/************************************************************************************
Fold in and out the mainmenus
************************************************************************************/
function foldmenu(num){
    if (loaded_ok == 1) {
    	if (! mainstayfolded){
    		for(var i=0; i<oFold.length; i++){
    			if(i!=num) oFold[i].subs(0,i)
    		}
    	}
    	//alert(num);
    	if (oFold[num].sub[0] != null && ! oFold[num].sub[0].status) {
    	    oFold[num].subs(1,num);
    	}
    	else {
            oFold[num].subs(0,num);
        }
    	checkheight(num);
    }
    else {
        setTimeout('foldmenu('+num+')', 50);
    }
}

function changeFontToBold(h) {
    var layerref;

    if ( h == -1 ) {
        // no id
    }
    else if ( h.indexOf('_') == -1 ) {
        layerref = 'divFold';           // highest level
    }
    else {
        layerref = 'divFoldSub';        // deeper level
    }

    // Font weight can't be changed by NS4
    if ( layerref ) {
        a = new Array;
        a = h.split('_');
        var levelDepth = a.length;

        var toHighlight = "navHighlight" + levelDepth;
        //alert('Fatten:'+h+':toHighlight:'+toHighlight);

        if (bw.ie4) {
            eval('document.all["'+"span_"+layerref+h+'"].className="'+toHighlight+'"');
        } else if (bw.dom) {
            document.getElementById('span_'+layerref+h).className=toHighlight;
        }
    }
}

// Change font of div/layer to normal
function changeFontToNormal(h) {
    var layerref;

    if ( h == -1 ) {}                   // no id
    else if ( h.indexOf('_') == -1 ) {
        layerref = 'divFold';           // highest level
    }
    else {
        layerref = 'divFoldSub';        // deeper level
    }

    // Font weight can't be changed by NS4
    if ( layerref ) {
        a = new Array;
        a = h.split('_');
        var levelDepth = a.length;

        var toNormalise = "navNormal" + levelDepth;
        //alert('Normalise:'+h+':toNormalise:'+toNormalise);

        if (bw.ie4) {
            eval('document.all["'+"span_"+layerref+h+'"].className="'+toNormalise+'"');
        } else if (bw.dom) {
            document.getElementById('span_'+layerref+h).className=toNormalise;
        }
    }
}



var loaded_ok = 0;

//Initiating the menus onload, if the browser is ok.
if(bw.bw) onload = foldInit;
