// need to know which menu is open
// some of this is taken from webreference.org
var openStatus = 'home';
// ns4 support --  we need the INDEX of a layer not it's ID.
// ns4 stores an array of all the elements by type
     function getIndex(el) {
         ind = null;
         for (i=0; i<document.layers.length; i++)
		  {
             whatEl = document.layers[i];
             if (whatEl.id == el) {
                 ind = i;
               break;
             }
          } 
		return ind;
     }


// ns4 support --  we need to calculate the height and stack all the visable layers on top of each other
function arrange() { 
	if (ns4) {
    var nextY = document.layers[firstInd].pageY + document.layers[firstInd].document.height;
	for (i=firstInd+1; i<document.layers.length; i++)
		{
		    whichEl = document.layers[i];
	        if (whichEl.visibility != "hide") {
                whichEl.pageY = nextY;
                nextY += whichEl.document.height;
				whichEl.pageX = document.layers[firstInd].pageX;
			}
		 }
     }
}

// To turn an on image to off or turn an off image to on
// it is a helper function for expandIt
function toggleImg(el) {
	var imgsrc = document.getElementById(el).src;
	if (imgsrc.indexOf('_off.gif') != -1) {
		var re = new RegExp("_off.gif","g");
		imgsrc = imgsrc.replace(re,"_on.gif");
	}
	else {
		var re = new RegExp("_on.gif","g");
		imgsrc = imgsrc.replace(re,"_off.gif");
	}
	document.getElementById(el).src = imgsrc;
}

// global variable that stores the id of the currently open menu
var openMenu;

// expands or contracts the menu item
// sets global openStatus toggle
// chances are good that this function will be overwritten in any specific package due to design
function expandIt(el,cmd) { //hides, unhides menu images (needs arrange to look proper)
		if (bV < 4 && opera > 6) return;
		parentEl = el.replace('menuChildren', 'parent');
		if (openMenu == el && cmd) {
		    if (document.getElementById(parentEl).className == 'menuParent_on') {
					if (cmd == 'on') {
						return;
					}
				} else {
					if (cmd == 'off') {
						return;
					}
				}
		}

		if ((openMenu != null) && (openMenu != el)) {
			// only toggle the image when there is an img
			if (document.getElementById(openMenu + '-img')) {
				toggleImg(openMenu + '-img');
			}
			hideElement(openMenu);
			parentOpen = openMenu.replace('menuChildren', 'parent');
			changeClass(parentOpen, 'menuParent_off');
		}
		// only toggle the image when there is an img
		if (document.getElementById(el+'-img')) {
			toggleImg(el + '-img');
		}
		hideElement(el);
		if (document.getElementById(parentEl).className == 'menuParent_off')
			changeClass(parentEl, 'menuParent_on');
		else 
			changeClass(parentEl, 'menuParent_off');
        if(ns4){
			 arrange();
        }  
		if (openMenu == el) openMenu = null;
		else openMenu = el;
} 
