// Holds the object of the menu item which is currently highlighted
var current_highlight = -1;

// Function called at load time to display the main menu, built from the mItems array.
// h_or_v : 1 = horizontal, 2 = vertical
function display_menu(a, h_or_v)
{
	var menu_html = "", set_separator = "&nbsp;-&nbsp;";

	if (h_or_v == 1) // Horizontal menu
	{
		// Loop through all the menu items in the main array including the script for changing the submenu when clicked.
		for (i = 0; i < mItems.length; i++)
		{
			// The SPAN tag allows the background colour to be changed for the highlighted menu item. 
			if (mItemLinks[i] == '#') // There *is* a submenu
			{
				document.write("<span class='nav_bg' id='nav_" + i + "' onMouseDown='javascript:display_horizontal_submenu(" + i + ", this);'><a href='#'>&nbsp;" + mItems[i] + "&nbsp;</a></span>");
			}
			else // There *isn't* a submenu
			{
				document.write("<span class='nav_bg' id='nav_" + i + "'><a href='" + mItemLinks[i] + "'>&nbsp;" + mItems[i] + "&nbsp;</a></span>");
			}
			
			// Only add the separator if it's not the final item.
			if (i < (mItems.length - 1))
			{
				document.write(set_separator);		
			}
		}
	}
	else // Vertical menu
	{
		// Loop through the number of main menu items and also show the submenu for the specified main item.
		for (i = 0; i < mItems.length; i++)
		{
			if (mItemLinks[i] == '#') // There *is* a submenu
			{
				menu_html = menu_html + "<span class='nav_sub_bg' id='nav_" + i + "' onMouseDown='javascript:display_menu(" + i + ", 2);'><a href='" + mItemLinks[i] + "'>" + mItems[i] + "</a></span><br>";
			}
			else // There *isn't* a submenu
			{
				menu_html = menu_html + "<span class='nav_sub_bg' id='nav_" + i + "'><a href='" + mItemLinks[i] + "'>" + mItems[i] + "</a></span><br>";
			}

			// Show the sub menu for the specified item if there is a submenu.
			if (i == a && mItemLinks[i] == '#')
				menu_html = menu_html + display_vertical_submenu(a);
		}
	
		// Change the sub menu HTML - different methods for IE and Netscape browsers
		if (document.all) // IE
			side_menu.innerHTML = menu_html;
		else
			document.getElementById("side_menu").innerHTML = menu_html;
	}
}

// Function called when user clicks on a *main* menu item.  Changes the background colour and the sub menu items.
// For horizontal menus only
function display_horizontal_submenu(a, this_obj)
{
	var html_output, set_separator = "&nbsp;&nbsp;/&nbsp;&nbsp;";
	var i;

	// Clear the current highlight
	if (current_highlight != -1)
	{
    	current_highlight.className = "";
	}

	// Set the new highlight of the menu item
	this_obj.className = "nav_sub_bg";
	// Store the object of the new highlighted menu item
	current_highlight = this_obj;

	// Set a default sub menu HTML contents (i.e. blank)
	html_output = "";

	// Loop through all the submenu items for the specified main menu item.
	for (i = 0; i < smItems[a].length; i++)
	{
		html_output = html_output + "<a href='" + smItemsLinks[a][i] + "'>" + smItems[a][i] + "</a>";

		// Only add the separators if it's not the final item.
		if (i < (smItems[a].length - 1))
		{
			html_output = html_output + set_separator;
		}
	}

	// Change the sub menu HTML - different methods for IE and Netscape browsers
	if (document.all) // IE
		submenu.innerHTML = html_output;
    else
   		document.getElementById("submenu").innerHTML = html_output;
}

// Creates the submenu list under it's parent menu item.
// For vertical menus only
function display_vertical_submenu(a)
{
	var html_output = "", set_spaces = "&nbsp;&nbsp;&nbsp;&nbsp;";
	var i;

	// Loop through the submenu items for the specified main item.
	for (i = 0; i < smItems[a].length; i++)
	{
		html_output = html_output + set_spaces + "<span class='nav_sub_links'><a href='" + smItemsLinks[a][i] + "'>" + smItems[a][i] + "</a></span><br>";
	}

	return (html_output);
}

