/*	ecmenu.js
 *
 *		Predefine menu bar. Done here to simplify things
 */

/************************************************************************/
/*																		*/
/*	Common Menu Stuff													*/
/*																		*/
/************************************************************************/

/*	StartMenu
 *
 *		Start the menu declaration and image declarations
 */

function StartMenu(prefix)
{
	// EC Image header
	document.write('<div class="titlebar"><img src="' + prefix + 'images/titleart.png"></div>');
	// Table header
	document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0" class="mainmenu">');
	document.writeln('<tr>');
	document.writeln('<td align="left">');
	document.writeln('<table border="0" cellspacing="0" cellpadding="0">');
	document.writeln('<tr>');
}

/*	EndMenu
 *
 *		Writes the end of the main menu
 */

function EndMenu()
{
	document.writeln('</tr>');
	document.writeln('</table>');
	document.writeln('</td>');
	document.writeln('<td align="right">');
	document.writeln('<table border="0" cellspacing="0" cellpadding="0">');
	document.writeln('<tr>');
	document.writeln('<td class="menuitem menuright"><a href="http://www.oto-usa.org" target="_blank">U.S. Grand Lodge</a></td>');
	document.writeln('</tr>');
	document.writeln('</table>');
	document.writeln('</td>');
	document.writeln('</tr>');
	document.writeln('</table>');
}

/*	AddMenuItem
 *
 *		Adds a single menu item.
 */

function AddMenuItem(name,link,sel)
{
	if (sel) {
		document.write('<td class="menuitem menusel"><a href="');
	} else {
		document.write('<td class="menuitem"><a href="');
	}
	document.write(link);
	document.write('">');
	document.write(name);
	document.writeln('</a></td>');
}

/*	StartSubMenu
 *
 *		Start the submenu if it exists
 */

function StartSubMenu()
{
	document.writeln('<div class="submenu">');
}

function EndSubMenu()
{
	document.writeln('</div>');
}

function AddSubMenuItem(name,link,sel)
{
	if (sel) {
		document.write('<a class="selected" href="');
	} else {
		document.write('<a href="');
	}
	document.write(link);
	document.write('">');
	document.write(name);
	document.writeln('</a>');
}

/************************************************************************/
/*																		*/
/*	Standard Menu Navigation											*/
/*																		*/
/************************************************************************/

var TopMenu = [
	{ name:"Home",			link:"index.html",			submenu:0 },
	{ name:"Electors", 		link:"electors.html",		submenu:0 },
	{ name:"Services",		link:"services.html", 		submenu:1 },
	{ name:"Information", 	link:"references.html",		submenu:2 },
	{ name:"News",			link:"news_misc.html",  submenu:3 },
	{ name:"FAQ",			link:"faq.html",			submenu: 0 }
];

var SubMenus = [
	// Services submenu 1
	[
		{	name:"About",	link:"services.html" 	},
		{	name:"Chartering New Bodies",	link:"services_newbodies.html"	},
		{	name:"Bodymaster Services",		link:"services_bmservices.html" },
		{	name:"Mentorship Program",		link:"services_mentorship.html" },
		{	name:"CiF Program",				link:"services_cif.html" },
		{	name:"V&deg; Application Process", link:"RC/index.html" }
	],
	
	// References submenu 2
	[
		{	name:"About", link:"references.html"	},
		{	name:"E.C. Criteria for Camps, Oases and Lodges", link:"references_criteria.html" },
		{	name:"Annual Report Statistical Data", link:"references_arf.html" },
		{	name:"Camp in Formation Organizers", link:"references_cif.html" }
	],
	
	// References submenu 3
	[
		{   name:"Electoral College News", link:"news_misc.html" },
		{	name:"Electoral College Meetings", link:"news_upcoming.html"	},
		{	name:"Kaaba Colloquium", link:"news_events.html" }
	]
];

/*	WriteMenus
 *
 *		Yes, this is dorky. But it guarantees a very short preamble on the
 *	HTML pages, and that all the menus are the same.
 */

function WriteMenus(index,subindex,prefix)
{
	var submenu = 0;
	
	// Write menu, capture submenu
	var i;
	var len = TopMenu.length;
	StartMenu(prefix);
	for (i = 0; i < len; ++i) {
		AddMenuItem(TopMenu[i].name,prefix + TopMenu[i].link,(i == index));
		if (i == index) submenu = TopMenu[i].submenu;
	}
	EndMenu();
	
	// Write submenu if it exists
	if (submenu > 0) {
		var menu = SubMenus[submenu-1];
		
		StartSubMenu();
		len = menu.length;
		for (i = 0; i < len; ++i) {
			AddSubMenuItem(menu[i].name,prefix + menu[i].link,(i == subindex));
		}
		EndSubMenu();
	}
	
	// Write ARF line
	if (new Date().getMonth() == 0) {
		document.writeln('<p class="arfline"><a href="news_misc.html">The Annual Report Form season is here.</a></p>');
	}
}

