var pm = '';
var am = '';
var th = null;
var ts = null;

/*
function initMenus()
{
	if (document.getElementById)
	{
		buildMenus();
		if (window.buildLeftFlyMenus)
			buildLeftFlyMenus();
		if (document.addEventListener)
			document.addEventListener('mousemove', handleMenus, false);
		else
			document.onmousemove = handleMenus;
	}
}
*/

function buildMenus()
{
	var aboutArray = [ 'tm_about', ['History', '/About/History.aspx'], ['Directory/Contacts', '/About/Directory---Contacts.aspx'], ['Employment & Internships', '/About/Employment---Internships.aspx'], ['Financials', '/About/Financials.aspx'], ['Programs', '/About/Programs.aspx'], ['Associations', '/About/Associations.aspx'], ['Committees', '/About/Committees.aspx'], ['USATF Foundation', '/About/USATF-Foundation.aspx'], ['Community Outreach', '/About/Community.aspx'], ['Annual Meeting', 'About/Annual-Meeting.aspx'], ['Annual Report', '/About/Annual-Report.aspx'], ['Competition Rules', '/About/Competition-Rules.aspx'], ['Bylaws & Operating Regulations', '/About/Bylaws---Operating-Regulations.aspx'], ['Privacy & Other Policies', '/About/Privacy---Other-Policies.aspx'], ['Anti-Doping', '/About/Anti-Doping.aspx'], ['Disciplinary Actions', '/About/Disciplinary-Actions.aspx'], ['Links', '/About/Links.aspx'] ];
	var newsArray = [ 'tm_news', ['Press Releases', '/news/index.asp'], ['Social Media', '/news/socialMedia/index.asp'] ];
	var athletesArray = [ 'tm_athletes', ['Track & Field', '/Athlete-Bios.aspx'], ['Race Walking', '/Athlete-Bios/Race-Walking.aspx'], ['Mountain/Ultra/Trail', '/Athlete-Bios/Mountain---Ultra---Trail.aspx'], ['Hall of Fame','/Athlete-Bios/Hall-of-Fame.aspx'] ];
	var eventsArray = [ 'tm_events', ['Event Coverage/Results', '/Events---Calendar/Event-Coverage---Results.aspx'], ['Visa Championship Series', '/Events---Calendar/Visa-Championship-Series.aspx'], ['Team USA Events', '/Events---Calendar/Team-USA-Events.aspx'], ['National Championships', '/Events---Calendar/National-Championships.aspx'], ['Search the Calendar', '/Events---Calendar/Search-the-Calendar.aspx'], ['TV Schedule', '/Events---Calendar/TV-Schedule.aspx'], ['USATF Annual Meeting', '/Events---Calendar/USATF-Annual-Meeting.aspx']  ];
	var statsArray = [ 'tm_stats', ['Event/Meet Records', '/statistics/Event-Records.aspx'], ['Records', '/Stats/Records.aspx'], ['Yearly Top US Marks', '/Stats/Top-Marks-Lists.aspx'], ['All-Time Lists', '/Stats/All-Time-Lists.aspx'], ['USA Champions', '/Stats/USA-Champions.aspx'], ['Team USA Stats', '/Stats/Team-USA.aspx'], ['Annual Awards', '/Stats/Annual-Awards.aspx'], ['Calculators', '/Stats/Calculators.aspx'] ];
	var productsArray = [ 'tm_products', ['Merchandise', '/Products---Services/Merchandise.aspx'], ['Youth Video', '/Products---Services/Youth-Video.aspx'], ['Publications', '/Products---Services/Publications.aspx'], ['Tickets', '/Products---Services/Tickets.aspx'], ['Individual Memberships', '/Products---Services/Individual-Memberships.aspx'], ['Club Memberships', '/Products---Services/Club-Memberships.aspx'], ['Event Sanctions', '/Products---Services/Event-Sanctions.aspx'], ['Course Certifications', '/Products---Services/Course-Certifications.aspx'], ['Championship Bids', '/Products---Services/Championship-Bids.aspx'], ['Coaching Education', '/Products---Services/Coaching-Education.aspx'], ['Officials Certification', '/Products---Services/Officials-Certification.aspx'], ['USATF Visa Card', '/Products---Services/USATF-Visa-Card.aspx'], ['Tours & Travel', '/Products---Services/Tours---Travel.aspx'], ['Driving the Sport', '/Products---Services/Driving-the-Sport.aspx'], ['Web Browser Theme', '/Products---Services/Web-Browser-Theme.aspx'] ];
	var sportsArray = [ 'tm_sports', ['Cross Country','/Sports/Cross-Country.aspx'], ['Mountain/Ultra/Trail', '/Sports/Mountain---Ultra---Trail.aspx'], ['Race Walking', '/Sports/Race-Walking.aspx'],['Road Running','/Sports/Road-Running.aspx'],['Track & Field', '/Sports/Track---Field.aspx'] ];
	var resourcesArray = [ 'tm_resources', ['Youth Athletes', '/Resources-for---/Youth-Athletes.aspx'], ['Masters Athletes', '/Resources-for---/Masters-Athletes.aspx'], ['Elite Athletes', '/Resources-for---/Elite-Athletes.aspx'], ['Clubs', '/Resources-for---/Clubs.aspx'], ['Coaches', '/Resources-for---/Coaches.aspx'], ['Officials', '/Resources-for---/Officials.aspx'], ['Event Directors', '/Resources-for---/Event-Directors.aspx'], ['Athlete Reps.', '/Resources-for---/Athlete-Reps-.aspx'], ['Media', '/Resources-for---/Media.aspx'], ['Athlete Alumni', '/Resources-for---/Athlete-Alumni.aspx'] ];		//, ['Disabled Athletes', '/groups/Disabled/']
	addMenu(aboutArray);
	addMenu(newsArray);
	addMenu(athletesArray);
	addMenu(eventsArray);
	addMenu(statsArray);
	addMenu(productsArray);
	addMenu(sportsArray);
	addMenu(resourcesArray);
}

function addMenu(myArray, isFlyMenu)
{
	var isSSL = eval(location.protocol == 'https:');
	var newLi, newA, newUl = document.createElement('ul');
	
	if (isFlyMenu)
	{
		newUl.setAttribute('id', myArray[0]);
		newUl.setAttribute('class', 'flyM');
		newUl.className = 'flyM';
	}
	
	for (var i = 1; i < myArray.length; i++)
	{
		newLi = document.createElement('li');
		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]));
		
		newLi.appendChild(newA);
		newUl.appendChild(newLi);
	}
	
	if (! isFlyMenu)
		document.getElementById(myArray[0]).appendChild(newUl);
	else
	{
		var n = document.getElementById(myArray[0] + '_a');
		n.parentNode.insertBefore(newUl, n.nextSibling);
	}
}

function showMenu(menuID, lnkColor)
{
	pm = menuID;
	clearTimeout(ts);
	if (am == '')
		ts = setTimeout('showMenu_doIt(\'' + menuID + '\'' + (lnkColor ? ', \'' + lnkColor + '\'' : '') + ')', 80);
	else
		showMenu_doIt(menuID, lnkColor);
}

function showMenu_doIt(menuID, lnkColor)
{
	if (document.getElementById)
	{
		if (am != '')
			hideMenu(am);
		am = menuID;
		pm = '';
		document.getElementById(am + '_a').style.color = (lnkColor ? lnkColor : '#CE3152');
		if (document.getElementById(menuID))
		{
			var posT = 0, posL = 0;
			var tempEl = document.getElementById(menuID + '_a');
			do
			{
				posL += (tempEl.offsetLeft) ? tempEl.offsetLeft : 0;
				posT += (tempEl.offsetTop) ? tempEl.offsetTop : 0;
			} while (tempEl = tempEl.offsetParent)
			posT += document.getElementById(menuID + '_a').offsetHeight;
			
			document.getElementById(menuID).style.left = posL + 'px';
			document.getElementById(menuID).style.top = posT + 'px';
			document.getElementById(menuID).style.display = 'block';
		}
	}
}

function hideMenu(menuID)
{
	clearTimeout(th);
	th = null;
	if (document.getElementById(menuID))
		document.getElementById(menuID).style.display = 'none';
	document.getElementById(menuID + '_a').style.color = '';
	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;
		}
	}
}
