var pm = '';
var am = '';
var th = null;
var ts = null;

function initMenus()
{
	if (document.getElementById)
	{
		buildMenus();
		if (document.addEventListener)
			document.addEventListener('mousemove', handleMenus, false);
		else
			document.onmousemove = handleMenus;
	}
}

function buildMenus()
{
	var aboutArray = [ 'tm_about', ['History', '/about/history.asp'], ['Directory/Contacts', '/about/directory/'], ['Employment & Internships', '/about/employment/'], ['Programs', '/about/programs/'], ['Associations', '/associations/'], ['Committees', '/about/committees/'], ['USATF Foundation', 'http://www.usatffoundation.org/'], ['Annual Meeting', '/about/AnnualMeeting/'], ['Annual Report', '/about/annualReport/'], ['Competition Rules', '/about/rules/'], ['Bylaws & Operating Regulations', '/about/governance/'], ['Privacy & Other Policies', '/about/policies/'], ['Anti-Doping', '/about/legal/antidoping/'], ['Disciplinary Actions', '/about/legal/statuses.asp'], ['Links', '/links.asp'] ];
	var newsArray = [ 'tm_news', ['Press Releases', '/news/'], ['Multimedia', '/news/multimedia/'], ['Photo Galleries','/news/PhotoGalleries/'], ['Social Media', '/news/socialMedia/'] ];
	var athletesArray = [ 'tm_athletes', ['Track & Field', '/athletes/bios/'], ['Road Running', '/athletes/bios/RoadRunning/'], ['Race Walking', '/athletes/bios/RaceWalking/'], ['Cross Country', '/athletes/bios/CrossCountry/'], ['Mountain/Ultra/Trail', '/athletes/bios/MountainUltraTrail/'] ];
	var eventsArray = [ 'tm_events', ['Event Coverage/Results', '/events/'], ['Visa Championship Series', '/events/2009/VisaChampionshipSeries/'], ['Team USA Events', '/calendars/teamUSA.aspx'], ['National Championships', '/calendars/national.aspx'], ['Search the Calendar', '/calendars/search/'], ['TV Schedule', '/calendars/TVSchedule.asp'], ['USATF Annual Meeting', '/about/AnnualMeeting/']  ];
	var statsArray = [ 'tm_stats', ['Records', '/statistics/records/'], ['Top Marks Lists', '/statistics/topMarks/'], ['All-Time Lists', '/statistics/all-time/'], ['USA Champions', '/statistics/champions/'], ['Team USA', '/statistics/TeamUSA/'], ['Annual Awards', '/statistics/awards/'], ['Calculators', '/statistics/calculators/'] ];
	var productsArray = [ 'tm_products', ['Merchandise', '/store/?sc=TM'], ['Publications', '/store/showProducts.asp?category=Publications&sc=TM'], ['Tickets', '/store/showProducts.asp?category=Tickets&sc=TM'], ['Individual Memberships', '/membership/?sc=TM'], ['Club Memberships', '/clubs/application/'], ['Event Sanctions', '/events/sanctions/'], ['Course Certification', '/events/courses/certification/'], ['Championships Bids', '/groups/EventDirectors/bids/'], ['Coaching Education', '/groups/Coaches/education/'], ['Officials Certification', '/groups/Officials/certification/'], ['USATF Visa Card', '/store/USATFVisa/'], ['Tours & Travel', '/events/2009/IAAFWorldOutdoorChampionships/fanTours.asp'] ];
	var sportsArray = [ 'tm_sports', ['Track & Field', '/groups/TrackAndField/'], ['Road Running', '/groups/RoadRunning/'], ['Race Walking', '/groups/RaceWalking/'], ['Cross Country', '/groups/CrossCountry/'], ['Mountain/Ultra/Trail', '/groups/MountainUltraTrail/'] ];
	var resourcesArray = [ 'tm_resources', ['Youth Athletes', '/groups/Youth/'], ['Masters Athletes', '/groups/Masters/'], ['Elite Athletes', '/groups/Elite/'], ['Clubs', '/clubs/'], ['Coaches', '/groups/Coaches/'], ['Officials', '/groups/Officials/'], ['Event Directors', '/groups/EventDirectors/'], ['Athlete Reps.', '/groups/AthleteRepresentatives/'], ['Media', '/groups/Media/'], ['Athlete Alumni', '/groups/Alumni/'] ];		//, ['Disabled Athletes', '/groups/Disabled/']
	addMenu(aboutArray);
	addMenu(newsArray);
	addMenu(athletesArray);
	addMenu(eventsArray);
	addMenu(statsArray);
	addMenu(productsArray);
	addMenu(sportsArray);
	addMenu(resourcesArray);
}

function addMenu(myArray)
{
	var isSSL = eval(location.protocol == 'https:');
	var newA;
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', myArray[0]);
	for (var i = 1; i < myArray.length; i++)
	{
		newA = document.createElement('a');
		if (! isSSL)
			newA.setAttribute('href', myArray[i][1]);
		else
			newA.setAttribute('href', 'http://www.usatf.org' + myArray[i][1]);
		newA.appendChild(document.createTextNode(myArray[i][0]));
		newDiv.appendChild(newA);
		newDiv.appendChild(document.createElement('br'));
	}
	var n = document.getElementById(myArray[0] + '_a');
	n.parentNode.insertBefore(newDiv, n.nextSibling);
}

function showMenu(menuID)
{
	pm = menuID;
	clearTimeout(ts);
	if (am == '')
		ts = setTimeout('showMenu_doIt(\'' + menuID + '\')', 80);
	else
		showMenu_doIt(menuID);
}

function showMenu_doIt(menuID)
{
	if (document.getElementById)
	{
		if (am != '')
			hideMenu(am);
		am = menuID;
		pm = '';
		document.getElementById(am + '_a').style.color = '#CE3152';
		if (document.getElementById(menuID))
		{
			document.getElementById(menuID).style.display = 'block';
			posL = document.getElementById(menuID + '_a').offsetLeft;
			document.getElementById(menuID).style.left = posL + 'px';
			posT = document.getElementById(menuID + '_a').offsetTop + document.getElementById(menuID + '_a').offsetHeight;
			document.getElementById(menuID).style.top = posT + 'px';
		}
	}
}

function hideMenu(menuID)
{
	clearTimeout(th);
	th = null;
	if (document.getElementById(menuID))
		document.getElementById(menuID).style.display = 'none';
	document.getElementById(menuID + '_a').style.color = '#183C47';
	am = '';
}

function handleMenus(e)
{
	if (! document.addEventListener)
		handleMenu(event.srcElement);
	else if (e)
		handleMenu(e.target);
}

function handleMenu(myEvent)
{
	holdMenu = false;
	mv = myEvent;
	if (am != '')
	{
		while (mv)
		{
			if (mv.id == am || mv.id == am + '_a')
			{
				holdMenu = true;
				break;
			}
			mv = mv.parentNode;
		}
		if (! holdMenu)
		{
			if (th == null)
				th = setTimeout('hideMenu(\'' + am + '\')', 325);
		}
		else
		{
			clearTimeout(th);
			th = null;
		}
	}
	else if (pm != '')
	{
		while (mv)
		{
			if (mv.id == pm + '_a')
			{
				holdMenu = true;
				break;
			}
			mv = mv.parentNode;
		}
		if (! holdMenu)
		{
			clearTimeout(ts);
			ts = null;
		}
	}
}