<!-- Begin

/*
====================================================================================
   Menu Array Setup: *** BEFORE EDITING, READ THIS SECTION CAREFULLY! ***

   The Menu Object
	Syntax:
		menu[iMenuNumber][0] = new Menu(sDirection, iXPosition, iYPosition, iWidth, sOverColor, 
						sBackColor, sBorderClass, sTextClass, sChildIndicator);

	Notes:
		sDirection - string stating direction.  Either 'Vertical' or 'Horizontal'
		iXPosition, iYPosition - integer determining position from top-left corner
			pr previous trigger, or for the root menu, from the corner of the page
		iWidth - integer determining width/height of the menu (depending on direction)
		sOverColor, sBackColor - strings representing hexidecimal values for colors - '#000000'.
		sBorderClass, sTextClass - strings representing style sheet classes to be used
		sChildIndicator - string representing a child menu indicator - '>'.

   The Item Object
	Syntax:
		menu[iMenuNumber][iItemNumber] = new Item(sText, sHref, sFrame, iLength, iSpacing, iChildMenuNumber)

	Notes:
		sText - 'Text'
		sHref - 'URL'
		sFrame - 'target frame'
		iLength - length of menu item. The height value is set at the Item level. Increase if an item needs to wrap words.
		iSpacing - integer representing additional spacing to next menu item.
		iChildMenuNumber - integer of target menu to popout. If no child menu is desired, 
			set iChildMenuNumber to 0.

====================================================================================
*/


var menu = new Array();


// Default colours passed to most menu constructors (just passed to functions, not
// a global variable - makes things easier to change later in bulk).
var ItemHeight = 22, ItemBack = '#D2CDCD', ItemOver = '#F90000';

// Menu 0 is the root menu from which everything else arises.
menu[0] = new Array();
menu[0][0] = new Menu('Horizontal', 0, 153, 22, '#F90000', '#F90000', '', 'MainText', '');
menu[0][1] = new Item('Home', '', '', 120, 0, 1);
menu[0][2] = new Item('Travel', '', '', 120, 0, 2);
menu[0][3] = new Item('Weekend', '', '', 140, 0, 3);
menu[0][4] = new Item('Competition', '', '', 120, 0, 4);
menu[0][5] = new Item('Registration', '', '', 120, 0, 5);
menu[0][6] = new Item('Contact Us', '', '', 120, 0, 6);


// Home menu
menu[1] = new Array();
menu[1][0] = new Menu('Vertical', 0, 23, 120, ItemOver, ItemBack, 'itemBorder', 'itemText', '');
menu[1][1] = new Item('Home', '../home.php', '', ItemHeight, 0, 0);

// Travel info menu
menu[2] = new Array();
menu[2][0] = new Menu('Vertical', 0, 23, 120, ItemOver, ItemBack, 'itemBorder', 'itemText', '');
menu[2][1] = new Item('Hotels', '../hotels.php', '', ItemHeight, 0, 0);
menu[2][2] = new Item('Airport', '../airport.php', '', ItemHeight, 0, 0);
menu[2][3] = new Item('Directions', '../directions.php', '', ItemHeight, 0, 0);

// Weekend menu
menu[3] = new Array();
menu[3][0] = new Menu('Vertical', 0, 23, 150, ItemOver, ItemBack, 'itemBorder', 'itemText', '');
menu[3][1] = new Item('Schedule', '../weekendSchedule.php', '', ItemHeight, 0, 0);
menu[3][2] = new Item('Open Schedule', '../openSchedule.php', '', ItemHeight, 0, 0);
menu[3][3] = new Item('Women\'s Schedule', '../womenSchedule.php', '', ItemHeight, 0, 0);
menu[3][4] = new Item('Party/Award Ceremony', '../partyInfo.php', '', ItemHeight, 0, 0);

// teams menu
menu[4] = new Array();
menu[4][0] = new Menu('Vertical', 0, 23, 120, ItemOver, ItemBack, 'itemBorder', 'itemText', '');
menu[4][1] = new Item('Teams', '../teams.php', '', ItemHeight, 0, 0);
menu[4][2] = new Item('Results', '../results.php', '', ItemHeight, 0, 0);
menu[4][3] = new Item('Writeups', '../writeups.php', '', ItemHeight, 0, 0);
menu[4][4] = new Item('Pictures', '../pictures.php', '', ItemHeight, 0, 0);

// registration menu
menu[5] = new Array();
menu[5][0] = new Menu('Vertical', 0, 23, 130, ItemOver, ItemBack, 'itemBorder', 'itemText', '>');
menu[5][1] = new Item('Registration', '../registration.php', '', ItemHeight, 0, 0);

// Contact Us menu
menu[6] = new Array();
menu[6][0] = new Menu('Vertical', 0, 23, 130, ItemOver, ItemBack, 'itemBorder', 'itemText', '>');
menu[6][1] = new Item('Contact Us', '../contact.php', '', ItemHeight, 0, 0);

/*  ***********************************************************************
    ***    Menu Generation:    ***     EDIT WITH EXTREME CAUTION!!!     ***
    *********************************************************************** */

//  *** MENU OBJECT CONSTRUCTION FUNCTION ***

function Menu(sDirection, iXPosition, iYPosition, iWidth, sOverColor, sBackColor, sBorderClass, sTextClass, sChildIndicator)
{

	// Direction of Menu passed in as a string.  Default is Vertical.
	this.isVert = (sDirection == 'Horizontal' ? false : true);

	// Position and size settings.
	this.x = iXPosition;
	this.y = iYPosition;
	this.width = iWidth;

	// Colors of menu and items.
	this.overColor = sOverColor;
	this.backColor = sBackColor;

	// The stylesheet class used for item borders and the text within items.
	this.borderClass = sBorderClass;
	this.textClass = sTextClass;

	// String representing Child Menu Indicator (example: '>', '<img src="arrow.gif">')
	this.childIndicator = sChildIndicator

	// Parent menu and item numbers, indexed later.
	this.parentMenu = null;
	this.parentItem = null;

	// Reference to the object's style properties (set later).
	this.ref = null;
}

//  *** MENU ITEM OBJECT CONSTRUCTION FUNCTION ***

function Item(sText, sHref, sFrame, iLength, iSpacing, iChildMenuNumber)
{
	this.text = sText;
	this.href = sHref;
	this.frame = sFrame;
	this.length = iLength;
	this.spacing = iSpacing;
	this.childMenu = iChildMenuNumber;

	// Reference to the object's style properties (set later).
	this.ref = null;
}


//  *** MENU FUNCTIONALITY FUNCTIONS ***
//  These functions handle mouseOver, mouseOut and colorChange events

//  Determine basic browser type by the way it handles document objects
var bDOM = (document.getElementById ? true : false); 
var bIE4 = ((document.all && !bDOM) ? true : false);
var bNS4 = (document.layers ? true : false);

function getReference(id)
{
	if (bDOM) return document.getElementById(id);
	if (bIE4) return document.all[id];
	if (bNS4) return document.layers[id];
}

function getStyle(id) 
{
	return (bNS4 ? getReference(id) : getReference(id).style);
}


//  Global variable to delay hiding the child menus on a mouseOut event.
var iHideTimer = 0;

//  Array showing curently highlighted menu items.
var aHighlighted = new Array();


function eventClick(iMenuNumber, iItemNumber)
{
	window.location.href = menu[iMenuNumber][iItemNumber].href;
}

function eventOver(iMenuNumber, iItemNumber)
{
	clearTimeout(iHideTimer);
	hideAllBut(iMenuNumber);
	aHighlighted = getHierarchy(iMenuNumber, iItemNumber);
	changeColor(aHighlighted, true);
	childMenuNumber = menu[iMenuNumber][iItemNumber].childMenu;
	if (childMenuNumber > 0)
	{
		thisX = parseInt(menu[iMenuNumber][0].ref.left) + parseInt(menu[iMenuNumber][iItemNumber].ref.left);
		thisY = parseInt(menu[iMenuNumber][0].ref.top) + parseInt(menu[iMenuNumber][iItemNumber].ref.top);
		with (menu[childMenuNumber][0].ref)
		{
			left = parseInt(thisX + menu[childMenuNumber][0].x);
			top  = parseInt(thisY + menu[childMenuNumber][0].y);
			visibility = 'visible';
		}
	}
}


function eventOut(iMenuNumber, iItemNumber)
{
	if ((iMenuNumber == 0) && !menu[iMenuNumber][iItemNumber].childMenu)
	{
		hideAllBut(0);
	}
	else
	{
		iHideTimer = setTimeout('hideAllBut(0)', 500);
	}
}


function getHierarchy(iMenuNumber, iItemNumber)
{
	// Array index is the menu number. The contents are null if that menu is not a parent
	// or the item number of that menu that is an ancestor.

	aItemArray = new Array(menu.length);
	
	while(1)
	{
		aItemArray[iMenuNumber] = iItemNumber;
		// If we've reached the top of the hierarchy, return.
		if (iMenuNumber == 0)
		{
			return aItemArray;
		}
		iItemNumber = menu[iMenuNumber][0].parentItem;
		iMenuNumber = menu[iMenuNumber][0].parentMenu;
	}
}


//  Change the colors of the div/layer background. Pass an array and a boolean to specify which color (true = over color).

function changeColor(aChangeArray, bOver)
{
	for (iCount = 0; iCount < aChangeArray.length; iCount++)
	{
		if (aChangeArray[iCount])
		{
			sColor = bOver ? menu[iCount][0].overColor : menu[iCount][0].backColor;
			with (menu[iCount][aChangeArray[iCount]].ref)
			{
				if (bNS4) {bgColor = sColor;}
				else {backgroundColor = sColor;}
			}
		}
	}
}


function hideAllBut(iMenuNumber)
{
	var aKeepMenus = getHierarchy(iMenuNumber, 1);
	for (iCount = 0; iCount < menu.length; iCount++)
	if (!aKeepMenus[iCount]) {menu[iCount][0].ref.visibility = 'hidden';}
	changeColor(aHighlighted, false);
}

//  *** HTML CONSTRUCTION FUNCTIONS ***
//  These functions generate the HTML of the menu section and writes it to the document object

//  Generates the contents of a menu item (default: table with link inside).
function generateTable(currMenu, currItem)
{
	with (menu[currMenu][0]) with (menu[currMenu][currItem])
	{
		// The width and height of the menu item - dependent on orientation!
		var w = (menu[currMenu][0].isVert ? width : length);
		var h = (menu[currMenu][0].isVert ? length : width);

		var sTable = ''

		// In IE/NS6+, add padding if there's a border to emulate NS4's layer padding.
		// If a target frame is specified, also add that to the <a> tag.

		sTable += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!bNS4 && borderClass ? 3 : 0) + '">';

		if (currMenu == 0)
		{	sTable += '<tr>';
			if (currItem != 1) sTable += '<td width="24px"><img src="../images/RedRed.gif" width="24px" height="22px" border="0" /></td>';
			sTable += '<td class="' + textClass + '" align="center" height="22px">' +  text + '</a></td>';
		}
		else
		{
			sTable += '<tr><td class="' + textClass + '" align="left" height="' + (h - 7) + '">' + text + '</td>';
		}

		if (childMenu > 0)
		{
			// Set target's parents to this menu item.
			menu[childMenu][0].parentMenu = currMenu;
			menu[childMenu][0].parentItem = currItem;

			// Add a child menu indicator.
			if (childIndicator) sTable += '<td class="' + textClass + '" align="right">' + childIndicator + '</td>';
		}

		sTable += '</tr></table>';
		return sTable;
	}
}

function writeMenus()
{
	if (!bDOM && !bIE4 && !bNS4) return;

	for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0])
	{
		// Variable for holding HTML for items and positions of next item.
		var str = '', itemX = 0, itemY = 0;

		// Remember, items start from 1 in the array (0 is menu object itself, above).
		// Also use properties of each item nested in the other with() for construction.
		for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem])
		{
			var itemID = 'menu' + currMenu + 'item' + currItem;

			// The width and height of the menu item - dependent on orientation!
			var w = (isVert ? width : length);
			var h = (isVert ? length : width);

			// Create a div or layer text string with appropriate styles/properties.
			if (bDOM || bIE4)
			{
				str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; z-index:10; visibility: inherit; ';
				if (backColor) str += 'background: ' + backColor + '; ';
				str += '" ';
			}
			if (bNS4)
			{
				str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
				if (backColor) str += 'bgcolor="' + backColor + '" ';
			}
			if (borderClass) str += 'class="' + borderClass + '" ';

			// Add mouseover handlers and finish div/layer.
			str += 'onClick="eventClick(' + currMenu + ',' + currItem + ')" onMouseOver="eventOver(' + currMenu + ',' + currItem + ')" onMouseOut="eventOut(' + currMenu + ',' + currItem + ')">';

			// Add contents of item (default: table with link inside).
			// In IE/NS6+, add padding if there's a border to emulate NS4's layer padding.
			// If a target frame is specified, also add that to the <a> tag.

			str += generateTable(currMenu, currItem) + (bNS4 ? '</layer>' : '</div>');

			if (isVert) itemY += length + spacing;
			else itemX += length + spacing;
		}
		if (bDOM)
		{
			var newDiv = document.createElement('div');
			document.getElementsByTagName('body').item(0).appendChild(newDiv);
			newDiv.innerHTML = str;
			ref = newDiv.style;
			ref.position = 'absolute';
			ref.visibility = 'hidden';
		}

		// Insert a div tag to the end of the BODY with menu HTML in place for IE4.
		if (bIE4)
		{
			document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
			ref = getStyle('menu' + currMenu + 'div');
		}

		// In NS4, create a reference to a new layer and write the items to it.
		if (bNS4)
		{
			ref = new Layer(0);
			ref.document.write(str);
			ref.document.close();
		}

		for (currItem = 1; currItem < menu[currMenu].length; currItem++)
		{
			itemName = 'menu' + currMenu + 'item' + currItem;
			if (bDOM || bIE4) menu[currMenu][currItem].ref = getStyle(itemName);
			if (bNS4) menu[currMenu][currItem].ref = ref.document[itemName];
		}
	}
	with(menu[0][0])
	{
		ref.left = x;
		ref.top = y;
		ref.visibility = 'visible';
	}
}


//  *** OPTIONAL CODE FROM HERE DOWN ***

// These two lines handle the window resize bug in NS4. See <body onResize="...">.
// I recommend you leave this here as otherwise when you resize NS4's width menus are hidden.

var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');


// This is a quick snippet that captures all clicks on the document and hides the menus
// every time you click. Use if you want.

if (bNS4) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;

function clickHandle(evt)
{
	if (bNS4) document.routeEvent(evt);
	hideAllBut(0);
}


//  End -->
