function writemenu(rootindex) 
{	
	var i;
	if(rootindex != 0)
	{
		document.write("<tr ");

		if(myMenu[rootindex].target == "")
		{
			document.write("onClick=\"clicked(" + rootindex + ")\" ");
		}
		
		document.write("id=\"Menu_ID_" + rootindex + "\" ");
		if(myMenu[rootindex].level > 1)
		{
			document.write("style=\"display:none\"");
		}
		document.write(">");
        document.write("<td class=\"td_menu_lvl_" + myMenu[rootindex].level + "\">");
		if(myMenu[rootindex].target != "")
		{
			document.write("<a href=\"");
			if (myMenu[rootindex].target.length > 0)
				if ((myMenu[rootindex].target.substr(0,4) != "http") && (myMenu[rootindex].target.substr(0,7) != "mailto:")) document.write(MenuInitialization.PathToTheRoot);
			document.write(myMenu[rootindex].target + "\" ");
			document.write("class=\"level_" + myMenu[rootindex].level + "_link\"");

				if (myMenu[rootindex].target.length > 0)
				if (myMenu[rootindex].target.substr(0,4) == "http") document.write(" target=\"_blank\"");
			document.write(">");
		}
		document.write(myMenu[rootindex].caption);

		if(myMenu[rootindex].target != "") document.write("</a>");
		document.write("</td></tr>");
	}
	
	for(i = 0; i < myMenu[rootindex].children.length; i++)
	{
		writemenu(myMenu[rootindex].children[i]);	
	}
}

function makechildren()
{
	var i;
	myMenu[0].children = new Array();
	for(i=1; i<myMenu.length; i++)
	{
		myMenu[i].children = new Array();
		var parent = myMenu[i].parent;
		myMenu[parent].children.push(i);
	}
}

function assignlevels(index, level)
{
	myMenu[index].level = level;
	var i;
	for(i=0; i<myMenu[index].children.length; i++)
	{
		assignlevels(myMenu[index].children[i], level+1)
	}
}

function init()
{
	if(MenuInitialization.id != "") clicked(MenuInitialization.id);
}


function HideAll(){
	for(cptHide = 0; cptHide < myMenu.length; cptHide++){
		if(myMenu[cptHide].level > 1) document.getElementById("Menu_ID_" + cptHide).style.display = "none";
	}
}

function ShowAllChildsOf(myIdMenu){
	for(i = 0; i < myMenu[myIdMenu].children.length; i++){
		document.getElementById("Menu_ID_" + myMenu[myIdMenu].children[i]).style.display = "";
	}
}

function HideAllChildsOf(myIdMenu){
	for(i = 0; i < myMenu[myIdMenu].children.length; i++){
		document.getElementById("Menu_ID_" + myMenu[myIdMenu].children[i]).style.display = "none";
	}
}

function ShowTree(myIdClicked){
	if (myIdClicked == 0) {
		HideAll();
	} else {
		ShowTree(myMenu[myIdClicked].parent);
		ShowAllChildsOf(myIdClicked);
	}
	MenuInitialization.currentMenu = myIdClicked;
}

function clicked(myIdClicked)
{
	if (MenuInitialization.currentMenu == myIdClicked){
		ShowTree(myMenu[myIdClicked].parent);
	} else {
		ShowTree(myIdClicked);
	}
	if (myMenu[MenuInitialization.currentMenu].children.length == 0) 
		MenuInitialization.currentMenu = myMenu[MenuInitialization.currentMenu].parent;
}


