// menu by robert staniskis
// array of all menu items
var menuItems = new Array();

// MENUNAME, LINKTEXT, URL

// menu 1
menuItems[0] = 'smenu1,weekend services,weekend.html';
menuItems[1] = 'smenu1,location,location.html';
menuItems[2] = 'smenu1,children,children_weekends.html';
menuItems[3] = 'smenu1,middle school,identity/week.html';
menuItems[4] = 'smenu1,high school,renovate/shed.php';
menuItems[5] = 'smenu1,college &amp; young adult,fusion/sunday.php';
menuItems[6] = 'smenu1,equipping classes,equippingclasses.html';
menuItems[7] = 'smenu1,recent messages,messages.html';

// menu 2
menuItems[8]  = 'smenu2,the path,thepath.html';
menuItems[9]  = 'smenu2,location,location.html';
menuItems[10]  = 'smenu2,our campus,campus.html';
menuItems[11] = 'smenu2,purpose &amp; values,purpose.html';
menuItems[12] = 'smenu2,what we believe,what_we_believe.html';
menuItems[13] = 'smenu2,leadership,leadership.html';

// menu 3
menuItems[14] = 'smenu3,the path,thepath.html';
menuItems[15] = 'smenu3,new member class,new_member_class.html';
menuItems[16] = 'smenu3,get connected,ministry_connections.html';
menuItems[17] = 'smenu3,get baptized,baptism.html';
menuItems[18] = 'smenu3,serve,serve.html';
menuItems[19] = 'smenu3,operation timothy,op_tim.html';
menuItems[20] = 'smenu3,celebrate recovery,cr.html';
menuItems[21] = 'smenu3,request prayer,contact_prayer.html';
menuItems[22] = 'smenu3,s.h.a.p.e. class,shape.html';
menuItems[23] = 'smenu3,child dedications,child_dedication.html';

// menu 4
menuItems[24] = 'smenu4,the path,thepath.html';
menuItems[25] = 'smenu4,ministries,ministries.html';
menuItems[26] = 'smenu4,covenant caf&eacute;,cafe.html';
menuItems[27] = 'smenu4,so others may live,soml.html';
menuItems[28] = 'smenu4,dance studio,dance.html';
menuItems[29] = 'smenu4,videos,videos.html';
menuItems[30] = 'smenu4,online devotional,devotions.html';
menuItems[31] = 'smenu4,bible search,bible_search.html';
menuItems[32] = 'smenu4,first cov preschool,preschool.html';
menuItems[33] = 'smenu4,radio program,radio.html';
menuItems[34] = 'smenu4,tithe online,tithe.html';
menuItems[35] = 'smenu4,contact us,contact.html';

// 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';
	}
}