// constants/configuration
	var intFoldTabId = 0;
	var arrFoldTabIds = new Array();
	var intFoldButId = 0;
	var arrFoldButIds = new Array();
	var arrTerminator = new Array(0,100); 
	var strOnePixel = '/images/spacing.gif';
	var intFoldTabOpenDelay = 0;
	var intFoldTabCloseDelay = 512;
		var intFoldTabCloseHandle = 0;
	var intFoldTabActive = getId();

// button tabs
	function getFoldTabs(){
		var strFoldTabs = '';
		// filter all root items
		arrIndex = FilterContent(1,0,0);
		for(var intA=0; intA<arrIndex.length; intA++){
			// gather data
			intIndex = arrIndex[intA];
			strName = DBarray[intIndex][2];
			strTitle = DBarray[intIndex][10];
			intTerm = DBarray[intIndex][12];
			strUrl = DBarray[intIndex][3];
			strTarget = DBarray[intIndex][4];
			strTitle = DBarray[intIndex][10];
			// add button
			if(intTerm>=arrTerminator[0]&&intTerm<=arrTerminator[1]){
				// events
				strMouseover = "suggestFoldTabs("+intIndex+");";
				strMouseout = "suggestFoldTabs(-1);";
				strMouseclick = "";
				// button
				strFoldTabs += '<a href="' + strUrl + '" target="' + strTarget + '"><img border="0" alt="'+strTitle+'" src="'+strOnePixel+'" id="foldtabs0id'+intIndex+'" class="foldtabs0id'+intIndex+'st0" onmouseover="'+strMouseover+'" onmouseout="'+strMouseout+'" onclick="'+strMouseclick+'"></a>';
				// store valid id
				arrFoldTabIds[arrFoldTabIds.length] = intIndex;
			}
		}
		// pass back
		return strFoldTabs;
	}
		
	function suggestFoldTabs(intNewId){
		// cancel last close-order
		clearTimeout(intFoldTabCloseHandle);
		// pick the correct delay
		intFoldTabDelay = (intNewId>=0) ? intFoldTabOpenDelay : intFoldTabCloseDelay ;
		// new order
		intFoldTabCloseHandle = setTimeout("setFoldTabs("+intNewId+")",intFoldTabDelay);
	}	
	
	function setFoldTabs(intNewId){
		// trace the old Id to the root
		var arrOldId = TraceBranch(intFoldTabId);
		var intOldIdRoot = arrOldId[1];
		// change back the style of the previous root item
		if(isElementOfArray(intOldIdRoot,arrFoldTabIds)>=0){
			if(!v4) setClassSuffix('foldtabs0id'+intOldIdRoot,-1,true);
			if(intFoldTabActive<=0) setClassSuffix('foldbar'+intOldIdRoot,0,false);
		}
		// trace the new Id to the root
		var arrNewId = TraceBranch(intNewId);
		var intNewIdRoot = arrNewId[1];
		// change the style of the new root item
		if(isElementOfArray(intNewIdRoot,arrFoldTabIds)>=0){
			if(!v4) setClassSuffix('foldtabs0id'+intNewIdRoot,1,true);
			if(intFoldTabActive<=0) setClassSuffix('foldbar'+intNewIdRoot,1,false);
		}
		// note the change
		intFoldTabId = intNewId;
	}
	
	function setFoldTabsId(intNewId) {
		if(typeof(intNewId)=='undefined') intNewId = getId();
		// trace the new Id to the root
		var arrNewId = TraceBranch(intNewId);
		var intNewIdRoot = arrNewId[1];
		// change the style of the new root item
		if(isElementOfArray(intNewIdRoot,arrFoldTabIds)>=0)
		{
			if(!v4) setClassSuffix('foldtabs0id'+intNewIdRoot, 2, true);
			setClassSuffix('foldbar'+intNewIdRoot, 1, false);
		}
		// change theme
		switch (intNewIdRoot)
		{
			case 1:
				setTheme('gemeenten');
				break;
			case 2:
				setTheme('publiek');
				break;
			case 3:
				setTheme('waterschappen');
				break;
			case 4:
				setTheme('dienstverleners');
				break;
			case 5:
				setTheme('waarderingskamer');
				break;
			default:
				setTheme('homepage');
		}
	}
	
// button bars	
	function getFoldBars(){
		var strFoldButs = '';
		// for every valid tab
		for(var intA=0; intA<arrFoldTabIds.length; intA++){
			// get tab's child-items
			intParent = arrFoldTabIds[intA];
			arrIndex = FilterContent(1,intParent,0);
			// header
			strFoldButs += '<div id="foldbar'+intParent+'" class="foldbar'+intParent+'st0">\n<table border="0" cellspacing="0" cellpadding="0"><tr>\n'
			// buttons
			for(var intB=0; intB<arrIndex.length; intB++){
				// data
				intIndex = arrIndex[intB];
				strName = DBarray[intIndex][2];
				strUrl = DBarray[intIndex][3];
				strTarget = DBarray[intIndex][4];
				strTitle = DBarray[intIndex][10];
				intTerm = DBarray[intIndex][12];
				// add button
				if(intTerm>=arrTerminator[0]&&intTerm<=arrTerminator[1]){
					// events
					/* disables due to external control
					strMouseover = "setClassSuffix(this.id,1,true);suggestFold("+intIndex+",true)";
					strMouseout = "setClassSuffix(this.id,-1,true)";
					 */
					strMouseover = "suggestFold("+intIndex+",true);suggestFoldTabs("+intParent+")";
					strMouseout = "suggestFold("+intIndex+",false);suggestFoldTabs(-1)";
					strMouseclick = "";
					
					// buttons
					strFoldButs += '<td id="foldbar0id'+intIndex+'" class="foldbut'+intParent+'st0" onmouseover="'+strMouseover+'" onmouseout="'+strMouseout+'" onmouseclick="' + strMouseclick + '"><a href="'+strUrl+'" target="'+strTarget+'">'+strTitle+'</td>';
					// store valid id
					arrFoldButIds[arrFoldButIds.length] = intIndex;
				}
			}
			// footer
			strFoldButs += '</tr></table>\n</div>\n'
		}
		// pass back
		return strFoldButs;
	}
	
	function setFoldBars(intNewId){
		// change back the old button
		if(isElementOfArray(intFoldButId,arrFoldButIds)>=0) setClassSuffix('foldbar0id'+intFoldButId,-1,true);
		// open the new button
		if(isElementOfArray(intNewId,arrFoldButIds)>=0) setClassSuffix('foldbar0id'+intNewId,1,true);
		// store the new Id
		 intFoldButId = intNewId;
	}

// startup
	function startFoldTab(){
		setContent('foldtabs0',getFoldTabs());
		setContent('foldbars0',getFoldBars());
		setFoldTabsId(intFoldTabActive);
	}

// execute inline
	if(v4){
		onload = startFoldTab;
	}else{
		startFoldTab();
	}


//setting cookies
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//get querystring
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}


//get hoofdonderwerp
var topgroup = getQuerystring('sec');
var topid = getQuerystring('id');
//alert(topgroup +" - "+ topid );
if((topgroup == "grouphome") && (topid == "1")){createCookie('topgroup', 'group1', 1);}
if((topgroup == "grouphome") && (topid == "2")){createCookie('topgroup', 'group2', 1);}
if((topgroup == "grouphome") && (topid == "3")){createCookie('topgroup', 'group3', 1);}
if((topgroup == "grouphome") && (topid == "4")){createCookie('topgroup', 'group4', 1);}
if((topgroup == "grouphome") && (topid == "5")){createCookie('topgroup', 'group5', 1);}

var readcoc = readCookie('topgroup');
if(readcoc == "group1")	{
	setTimeout("document.getElementById('foldbar1').style.display='block'; setTheme('gemeenten'); document.getElementById('foldtabs0id1').setAttribute('class', 'foldtabs0id1st2');",10);
	setTimeout("document.getElementById('foldbar2').style.display='none'; document.getElementById('foldtabs0id2').setAttribute('class', 'foldtabs0id2st0');",10);
	setTimeout("document.getElementById('foldbar3').style.display='none'; document.getElementById('foldtabs0id3').setAttribute('class', 'foldtabs0id3st0');",10);
	setTimeout("document.getElementById('foldbar4').style.display='none'; document.getElementById('foldtabs0id4').setAttribute('class', 'foldtabs0id4st0');",10);
	setTimeout("document.getElementById('foldbar5').style.display='none'; document.getElementById('foldtabs0id5').setAttribute('class', 'foldtabs0id5st0');",10); 
	}			
if(readcoc == "group2")	{
	setTimeout("document.getElementById('foldbar1').style.display='none'; document.getElementById('foldtabs0id1').setAttribute('class', 'foldtabs0id1st0');",10);
	setTimeout("document.getElementById('foldbar2').style.display='block'; setTheme('publiek'); document.getElementById('foldtabs0id2').setAttribute('class', 'foldtabs0id2st2');",10);
	setTimeout("document.getElementById('foldbar3').style.display='none'; document.getElementById('foldtabs0id3').setAttribute('class', 'foldtabs0id3st0');",10);
	setTimeout("document.getElementById('foldbar4').style.display='none'; document.getElementById('foldtabs0id4').setAttribute('class', 'foldtabs0id4st0');",10);
	setTimeout("document.getElementById('foldbar5').style.display='none'; document.getElementById('foldtabs0id5').setAttribute('class', 'foldtabs0id5st0');",10); 
	}
if(readcoc == "group3")	{
	setTimeout("document.getElementById('foldbar1').style.display='none'; document.getElementById('foldtabs0id1').setAttribute('class', 'foldtabs0id1st0');",10);
	setTimeout("document.getElementById('foldbar2').style.display='none'; document.getElementById('foldtabs0id2').setAttribute('class', 'foldtabs0id2st0');",10);
	setTimeout("document.getElementById('foldbar3').style.display='block'; setTheme('waterschappen'); document.getElementById('foldtabs0id3').setAttribute('class', 'foldtabs0id3st2');",10);
	setTimeout("document.getElementById('foldbar4').style.display='none'; document.getElementById('foldtabs0id4').setAttribute('class', 'foldtabs0id4st0');",10);
	setTimeout("document.getElementById('foldbar5').style.display='none'; document.getElementById('foldtabs0id5').setAttribute('class', 'foldtabs0id5st0');",10);  
	}
if(readcoc == "group4")	{
	setTimeout("document.getElementById('foldbar1').style.display='none'; document.getElementById('foldtabs0id1').setAttribute('class', 'foldtabs0id1st0');",10);
	setTimeout("document.getElementById('foldbar2').style.display='none'; document.getElementById('foldtabs0id2').setAttribute('class', 'foldtabs0id2st0');",10);
	setTimeout("document.getElementById('foldbar3').style.display='none'; document.getElementById('foldtabs0id3').setAttribute('class', 'foldtabs0id3st0');",10);
	setTimeout("document.getElementById('foldbar4').style.display='block'; setTheme('dienstverleners'); document.getElementById('foldtabs0id4').setAttribute('class', 'foldtabs0id4st2');",10);
	setTimeout("document.getElementById('foldbar5').style.display='none'; document.getElementById('foldtabs0id5').setAttribute('class', 'foldtabs0id5st0');",10); 
	}
if(readcoc == "group5")	{
	setTimeout("document.getElementById('foldbar1').style.display='none'; document.getElementById('foldtabs0id1').setAttribute('class', 'foldtabs0id1st0');",10);
	setTimeout("document.getElementById('foldbar2').style.display='none'; document.getElementById('foldtabs0id2').setAttribute('class', 'foldtabs0id2st0');",10);
	setTimeout("document.getElementById('foldbar3').style.display='none'; document.getElementById('foldtabs0id3').setAttribute('class', 'foldtabs0id3st0');",10);
	setTimeout("document.getElementById('foldbar4').style.display='none'; document.getElementById('foldtabs0id4').setAttribute('class', 'foldtabs0id4st0');",10);
	setTimeout("document.getElementById('foldbar5').style.display='block'; setTheme('waarderingskamer'); document.getElementById('foldtabs0id5').setAttribute('class', 'foldtabs0id5st2');",10); 
	}


