// menu by robert staniskis
// array of all menu items
var menuItems = new Array();

// MENUNAME, LINKTEXT, URL

// menu 1
menuItems[0] = 'smenu2,The Need,need.php';
menuItems[1] = 'smenu2,The Solution,solution.php';
menuItems[2] = 'smenu2,The Experience,experience.php';
menuItems[3] = 'smenu2,The History,history.php';

// menu 2
menuItems[4] = 'smenu3,After-School Drop In,afterschool.php';
menuItems[5] = 'smenu3,Late Lunch,lunch.php';
menuItems[6] = 'smenu3,Second Mile,secondmile.php';
menuItems[7] = 'smenu3,Campus Life Club,campuslife.php';
menuItems[8] = 'smenu3,Computers 4 Kids,c4k.php';

// menu 3
menuItems[9] = 'smenu4,Events Calendar,calendar.php';
menuItems[10] = 'smenu4,Grad Nite,gradnite.php';
menuItems[11] = 'smenu4,Tournaments,tournaments.php';
menuItems[12] = 'smenu4,Trips,trips.php';

// menu 4
menuItems[13] = 'smenu6,20/20 Campaign,campaign.php';
menuItems[14] = 'smenu6,Collings Cup,collingscup.php';
menuItems[15] = 'smenu6,Community Lights<br />&nbsp;&nbsp;&nbsp;Dinner,dinner.php';

// menu 6
menuItems[16] = 'smenu9,Getting Here,directions.php';
menuItems[17] = 'smenu9,Our Facility,facilities.php';

// iterate through the array and build the menu
var debug ='';
var currentMenu = 'smenu1';
var currentPage = window.location.href;
for (var i=0; i<menuItems.length; i++)
{
	var menuItem = menuItems[i].toString().split(',');
	var menu = document.getElementById(menuItem[0]);

	if(menu) //exists
	{
		menu.style.display = 'none';
		
		if( currentMenu != menuItem[0] )
		{
			if(document.getElementById(currentMenu))
			{
				var strMenu = document.getElementById(currentMenu).innerHTML;
				document.getElementById(currentMenu).innerHTML = '\r\n<ul>\r\n'+strMenu;
			}
		}
		
		menu.innerHTML += '\r\n<li>\r\n<a id="'+menuItem[2].substring(menuItem[2].lastIndexOf('/') + 1, menuItem[2].lastIndexOf('.'))+'" href="'+menuItem[2]+'">'+menuItem[1]+'</a></li>';
	}
	currentMenu = menuItem[0]; // the name of the current menu we are parsing
}
// for the tags on the last unordered list
if(document.getElementById(currentMenu))
{
	var strMenu = document.getElementById(currentMenu).innerHTML;
	document.getElementById(currentMenu).innerHTML = '\r\n<ul>\r\n'+strMenu;
}
// find the root menu and expand it
for (var i=0; i<menuItems.length; i++)
{
	var menuItem = menuItems[i].toString().split(',');
	if( currentPage.substring(currentPage.lastIndexOf('/') + 1, currentPage.lastIndexOf('.')) == menuItem[2].substring(menuItem[2].lastIndexOf('/') + 1, menuItem[2].lastIndexOf('.')))
	{
		var menu = document.getElementById(menuItem[0]);
		if (menu)
		{
			menu.style.display = 'block';
			break;
		}
	}
}

//alert(document.getElementById('menu').innerHTML);

// highlight the current link if available	
var myVar = currentPage.substring(currentPage.lastIndexOf('/') + 1, currentPage.lastIndexOf('.'))
var menuItem = document.getElementById(myVar);
if(menuItem)
{
	menuItem.className = "CurrentMenuItem";
}

// function to switch menus
function show(id) 
{
	var d = document.getElementById(id);
	
	for (var i = 1; i<=100; i++) 
	{
		if (document.getElementById('smenu'+i)) 
		{
			document.getElementById('smenu'+i).style.display = 'none';
		}
	}
	
	if (d)
	{
		d.style.display = 'block';
	}
}
