var txt = ''; // initialize the txt variable holding the submenus
var temptxt=''; // initialize the temp variable holding the text
var pagetxt=''; // initialize the temp variable holding all the page text
var addedChildMenus = new Array('item1-1','item1-1-1','item1-2-1'); // array holding the names of the child menus
var addedChildMenuRefs = new Array(); // array holding references to the child menus

function init_menus()
{
	pagetxt=createMenu(); // create the menu
	writeOut(); // write information out to the page
}

function createHref(menuObj) // create the href portion of the menu tree
{
	hreftxt="<a class='"+css_menu+"' href='"+eval(menuObj+'.menuURL')+"'";
	hreftxt+="onmouseover='javascript:"+menuObj+".Highlight()'";
	hreftxt+="onmouseout='javascript:"+menuObj+".Unhighlight()'>"+eval(menuObj+'.label');
	
	// if there are submenus then display the arrow
	
	if(eval(menuObj+'.child') != 0) hreftxt+=" <img src='images/menu/tri.gif' width='7' border='0'>";
	hreftxt+="</a>"; // close the reference
	return(hreftxt);
	
}

function createChild(menuId,iter) // create the children layers
{
	var menuChildId = ''; // name of the child ID
	var menuChildObj = ''; // name of the child object
	var tempchild = ''; // initialize the string to zero
	
	for(loop=0;loop<iter;loop++){ // iterate over the submenus
		menuChildId = menuId.concat(eval(loop+1));
		menuChildObj = txtreplace(menuChildId,'.','_'); // name of the child menuItem

		tempchild+="<tr><td><div id='"+menuChildId+"'>";
		tempchild+=createHref(menuChildObj);
		tempchild+="</div></td></tr>";
	}

	return(tempchild);
	
}

function createHead() // creates the main index headers
{
	var menuRoot = 'item'; // name of the menu ID
	var menuObj = ''; // name of the menu object
	var menuName = ''; // name of the menu name
	var tempmenu = ''; // initialize the string to zero
	
	if(sizeSelection == 0) var headscl=30;
	else var headscl=50;
	
	for(headitr=0;headitr<numMenu;headitr++){
		menuId = menuRoot.concat(eval(headitr+1)); // change the index of the menu header
		menuId = menuId.concat('-0'); // add '-0' on the name
		menuObj = txtreplace(menuId,'-','_'); // name of the menuItem obj
		menuName = txtreplace(menuId,'-','.'); // name of the menuItem obj

		// -- item 1 and sub menus --

		tempmenu+="<div id='"+menuId+"' style=\"POSITION: absolute; VISIBILITY: visible; TOP: "+(60+(headitr*headscl))+"px; LEFT: 10px; z-Index: 800;\">";
		tempmenu+="<table><tr><td>";
		tempmenu+="<div id='"+menuName+"'>";
		tempmenu+=createHref(menuObj); // create the link
		tempmenu+="</div></td></tr></table>";
		tempmenu+="</div>";
	}
	
	return(tempmenu);
}

function createMenu() // create the menu explicitly
{
	var temptxt=''; // initialize temp variable

	temptxt+=createHead()

	return(temptxt);
}

function writeOut() // write the information out to the page
{
		// write the information to the page
	dispMenu=GetObject('menuItems');
	writeInfo(dispMenu,pagetxt);
}

function txtreplace(text,orig,replace) // finds the current container from the current layer
{
	newtxt='' // initialize a temporary string
	for(charitr=0;charitr<text.length;charitr++){
		if(text.charAt(charitr) == orig) newtxt=newtxt.concat(replace); // replace the orig char with the replacement
		else newtxt=newtxt.concat(text.charAt(charitr)); // else appent the current char from text string
	}

	return(newtxt);
}

