/*
Linked look-up tables need to be declared/assigned in reverse order
with the deepest sub-menu look-up table being declared/assigned first
and the top-level menu look-up table being declared last.
*/

//menus at directory level 2
var menu_2 = new Array();
menu_2[0] = ["prairie","experimental_prairie"];


// menus at directory level 1
var menu_1 = new Array();
menu_1[1] = ["about_us"];
menu_1[2] = ["nature_and_art_education", "scout_badges"];
menu_1[3] = ["outdoor_spaces", menu_2[0][0], "wetland", "ruth_park_woods", "arboretum"];
menu_1[4] = ["volunteer_programs", "volunteer_opportunities"];
menu_1[5] = ["facility_rental"];
menu_1[6] = ["support_us"];
menu_1[7] = ["contact_us"];


var bg_color = new Array();
bg_color[0] = "#EEEEFF";
bg_color[1] = "#E5EBFA";
bg_color[2] = "#669966";
bg_color[3] = "#71A874";


var hide;

/*
Function showMenu
Shows a sub menu by setting
its display property to "inline"
and its visibility property to
"visible" and setting its background color
to a "on color", color value determined by
top-level menu id.
Parameters:
	Input: on_menu_index of menu to show
	       must be 1+ menu array index of
	       sub menu to display
	Output: n/a
*/
function showMenu(on_menu_index)
{
	var obj;
	var menu_obj;
	var indices = new Array();
	
	indices = on_menu_index.split(",");
	
	// for top-level menus, turn off any currently on
	// menus before turning on menu specified by current call to showMenu()	
	if(indices[1]==0)
	{
		for(var x=1;x<menu_1.length;x++)
		{
			obj = getObjReference(menu_1[x][0]);
			menu_obj = getObjReference(menu_1[x][0] +"_menu");
				
			if((testObject(obj)) && (testObject(menu_obj)))
			{
				var bg;
				if(x != indices[0])
				{
					bg = getBgColor(x,0);
					turnBgColor(menu_obj,bg);
				
					obj.display = "none";
					obj.visibility="hidden";
				}
			}
		}		
	}
	
	// turn on menu 			
	obj = (testObjectExistence(menu_1[indices[0]][indices[1]])) ? getObjReference(menu_1[indices[0]][indices[1]]) : getObjReference(eval(menu_1[indices[0]][indices[1]])[indices[2]]);
	menu_obj = (testObjectExistence(menu_1[indices[0]][indices[1]] + "_menu")) ? getObjReference(menu_1[indices[0]][indices[1]] + "_menu") : getObjReference(eval(menu_1[indices[0]][indices[1]])[indices[2]] + "_menu");
			
		
	if((testObject(obj)) && (testObject(menu_obj)))
	{
		var bg;
		
		bg = getBgColor(indices[0],1);
		turnBgColor(menu_obj,bg);
		
		obj.display = "inline";
		obj.visibility = "visible";		
	}	
}

/*
Function hideMenu
Hides a sub menu by setting
its display property to "none"
and its visibility property to
"hidden"
Parameters:
Input: on_menu_index of menu to hide
Output: n/a
*/
function hideMenu(on_menu_index)
{	
	if(hide == 1)
	{
		var obj;
		var menu_obj;
		var bg;
		var indices = new Array();
		indices = on_menu_index.split(",");
				
		obj = (testObjectExistence(menu_1[indices[0]][indices[1]])) ? getObjReference(menu_1[indices[0]][indices[1]]) : getObjReference(eval(menu_1[indices[0]][indices[1]])[indices[2]]);
		menu_obj = (testObjectExistence(menu_1[indices[0]][indices[1]] + "_menu")) ? getObjReference(menu_1[indices[0]][indices[1]] + "_menu") : getObjReference(eval(menu_1[indices[0]][indices[1]])[indices[2]] + "_menu");
		
		// set the off state background color based on whether it is a top
		// menu we are turning; i.e. indices[1] will equal 0; or a sub-menu
		// we are turning; i.e. indices[1] will not equal 0
		if(indices[1] == 0)
		{
			bg = getBgColor(indices[0],0);
		}
		else
		{
			bg = getBgColor(indices[0],1);
		}
		
		if(testObject(obj))
		{
			turnBgColor(menu_obj,bg);
			obj.display = "none";
			obj.visibility = "hidden";
		}
	}
}

/*
Function getObjReference
Establishes and returns a CSS Style Object Reference
based on the user's browser
Parameters:
	Input: object id for which to create an obj reference
	Output: obj reference to css tag with id specified
		by input object id
*/
function getObjReference(obj)
{
	var objReference;

	if(document.all)
	{
		objReference = eval("document.all." +obj +".style");
	}
	else if(document.getElementById)
	{
		// I.E. 5, Netscape 6.2
		objReference = eval("document.getElementById('" +obj + "').style");
	}

	return objReference;

}

/*
Function testObject
Tests to determine if object reference var is defined
returns true if defined, false if undefined
Parameters:
	Input: undefined or defined object reference var
	Output: boolean
*/
function testObject(cur_obj)
{
	if(cur_obj)
	{
		return true;
	}
	else
	{
		return false;
	}
}

/*
Function testObjectExistence
Tests to determine if object exists in html page including this
instance of nav.js 
returns "object" or browser specific equivalent, if defined
"undefined", if undefined
Parameters:
	Input: object_name as string
	Output: "object" or "defined" as string
*/
function testObjectExistence(obj_name)
{
	var is_type;
	
	if(document.all)
	{
		is_type = document.all[obj_name];
	}
	else if(document.getElementById)
	{
		// I.E. 5, Netscape 6.2
		is_type = document.getElementById(obj_name);
	}
	
	return is_type;
}



/*
Function getBgColor
Gets the bgColor index number for a menu based on its menu number (id_num), plus
its state (0 for off, 1 for on)
Parameters:
	Input: id_num of the menu for which to retrieve its bgColor
	       state (0 for off, 1 for on)
	Output: bgcolor index number
*/
function getBgColor(id_num,state)
{
	var start_id;
	
	if(id_num < 6)
	{
	  start_id = 0		
	}
	else
	{
	  start_id = 2;
	}

	return start_id + state;
}

/*
Function turnBgColor
Changes the background color of a css style object
Parameters:
	Input: menu_obj (obj reference to the object whose background color should
					 be changed)
	       color_id id number of the bg_color array that stores the color to 
	       which the background should be set
	Output: n/a
*/
function turnBgColor(menu_obj,color_id)
{
	menu_obj.backgroundColor = bg_color[color_id];
}


/*
Function getDescription
Changes the location.href of the current window based on the selected index
of select list argument stored in s_list and resets the select list index
to 0
Parameters:
	Input: s_list containing a reference to a select list
	Output: n/a
*/
function getDescription(s_list)
{
	if(s_list.options.selectedIndex != 0)
	{
		location.href = s_list.options[s_list.selectedIndex].value + ".aspx";
		s_list.options.selectedIndex = 0;
	}
}
