
	/* MENUE.JS */

//declare the variables
var oTable = document.createElement('TABLE');
var padding = document.createAttribute("cellpadding");
var spacing = document.createAttribute("cellspacing");
padding.nodeValue = "0";
spacing.nodeValue = "0";
oTable.setAttributeNode(padding);
oTable.setAttributeNode(spacing);
var oTBody = document.createElement('TBODY');
var oRow, oCell;
var i;
var col;

//#################################################################################################
//# set the values of col1 and col2 to the last charcters of the names of your images so that the #
//# dark ones for example have a "d" and the bright ones got a "h" at the end                     #
//# u need this because of the changing effect for the onMouseOver and onMouseOut methods         #
//#################################################################################################

var col1 = "d";
var col2 = "h";
var mainCount = 0;

// insert the created elements into oTable.
oTable.appendChild(oTBody);

// creates mainmenue depending on which items are declared as mainmenue items
for (i=0; i<db.length; i++)
{
	if(db[i].indent==0)
	{
		oRow = oTBody.insertRow(mainCount);
  	oCell = oRow.insertCell(0);
		var newName= 'name';
		oCell.innerHTML='<a onClick="changeGrey(this.firstChild.getAttributeNode(newName).nodeValue);toggel(this.firstChild.getAttributeNode(newName).nodeValue);" onFocus=blur(); onMouseOver="changeGrey(this.firstChild.getAttributeNode(newName).nodeValue);" onMouseOut="changeDark(this.firstChild.getAttributeNode(newName).nodeValue);">'+db[i].display+'</a>';
		mainCount++;
	}
}

// #####################################################################################################
// # be sure that all of your images are in a folder called gfx which is located in the same directory #
// # as your html files                                                                                #
// #####################################################################################################

// changeing color of images to grey on mouseover
function changeGrey(n)
{
	actfile = eval("window.document.images." + n + ".src");
	patharr = actfile.split("/");
	actfile = patharr[patharr.length-1];
	col = col2;
	newfile = "gfx/nav/" + actfile.substring(0, actfile.length-5) + col + "." + actfile.substring(actfile.length-3, actfile.length);
	targetimg = eval("window.document.images." + n);
	targetimg.src = newfile;
}

// changeing color of images to dark on mouseout
function changeDark(n)
{
	var id = eval("window.document.images." + n + ".id");
	if (id != "active") {
		var actfile = eval("window.document.images." + n + ".src");
		var patharr = actfile.split("/");
		actfile = patharr[patharr.length-1];
		if (actfile.charAt(actfile.length-5) == col2) col = col1; 
		var newfile = "gfx/nav/" + actfile.substring(0, actfile.length-5) + col + "." + actfile.substring(actfile.length-3, actfile.length);
		var targetimg = eval("window.document.images." + n);
		targetimg.src = newfile;
	}
}

//closes opened submenues
function closeMenue(value)
{
	for(i=value+1;i!=db.length&&db[i].indent==1;i++)
	{
		oTBody.deleteRow(db[value].navnr);
		db[i].state=0;
	}
	var actpoint = eval("window.document.images.i" + value);
	actpoint.id = "notactive";
	changeDark("i"+value);
	db[value].state=0;
}
	
//reacts onclick and opens or closes the submenue		
function toggel(n)
{
	var item = ""
	var value;
	item = n.substring(1,n.length);
	value = parseInt(item);
	
	if (db[value].URL!='#') 
	{
		showContent(value);
	}
	var actpoint = eval("window.document.images." + n);
	actpoint.id = "active";
	if(db[value].state==0)
	{
		// closes open submenue when another item is clicked
		for(i=0;i<db.length;i++)
		{
			var oldpoint;
			if((db[i].state==1)&&(db[i].indent==0))
			{
				oldpoint = eval("window.document.images.i" + i);
				oldpoint.id = "notactive";
				changeDark("i"+i);
				closeMenue(i);
					
			}
		}
		// opens the submenue of the clicked item
		for(i=value+1;i!=db.length&&db[i].indent==1;i++)
		{
			iRow = oTBody.insertRow(db[value].navnr);
			iCell = iRow.insertCell(0);
			iCell.innerHTML='<a href="javascript:showContent('+i+');setActive('+i+','+(value+1)+')" onFocus="blur();" onMouseOver="changeGrey(this.firstChild.getAttributeNode(newName).nodeValue);" onMouseOut="changeDark(this.firstChild.getAttributeNode(newName).nodeValue);">'+db[i].display+'</a>';
			db[i].state=1;
		}
		db[value].state=1;
	}
	//closes submenue when the same item is clicked
	else
	{
		closeMenue(value);
	}
}//END

function setActive(n,start) {
	var oldpoint;
	for(i=start;i!=db.length&&db[i].indent==1;i++) {
		if (i!=n) {
			oldpoint = eval("window.document.images.i" + i);
			if (oldpoint.id == "active") {
				oldpoint.id = "notactive";
				changeDark("i"+i);
			}
		}
	}
	var actpoint = eval("window.document.images.i" + n);
	actpoint.id = "active";
}

//changes Headline in another frame
function showContent(line)
{  
	document.getElementById("MainTitle").src = "gfx/titles/" + db[line].mainTitle + ".gif";
	document.getElementById("MainTitle").alt = db[line].mainTitle
	var oContent = document.getElementById("Content");
	oContent.deleteRow(0);
	var text = db[line].content;
	var tRow = oContent.insertRow(0);
	var tCell = tRow.insertCell(0);
	var valign = document.createAttribute("valign");
	valign.nodeValue = "top";
	tCell.setAttributeNode(valign);
	tCell.innerHTML = text;
}

function footContent(line)
{  
	document.getElementById("MainTitle").innerHTML = foot[line].mainTitle;
	document.getElementById("SubTitle").innerHTML = foot[line].subTitle;
	var oContent = document.getElementById("Content");
	oContent.deleteRow(0);
	var text = foot[line].content;
	var tRow = oContent.insertRow(0);
	var tCell = tRow.insertCell(0);
	var valign = document.createAttribute("valign");
	valign.nodeValue = "top";
	tCell.setAttributeNode(valign);
	tCell.innerHTML = text;
}
