//**************************************************************************//
// Global Variables and Parameters 										    //
//**************************************************************************//

var t;


//**************************************************************************//
// Array of Objects containing  Link Names and URL's for Drop Down Menu's   //
//**************************************************************************//

// BMO & Soccer
var soccerArray = new Array();
soccerArray[0] = new menuObj("Grassroots","grassroots.html");
soccerArray[1] = new menuObj("BMO Report from the Pitch","reportFromPitch.html");
soccerArray[2] = new menuObj("Soccer Tips", "soccerTips.html");
soccerArray[3] = new menuObj("News Releases", "news.html");
soccerArray[4] = new menuObj("Toronto FC", "tfc.html");
soccerArray[5] = new menuObj("Vancouver Whitecaps FC", "whitecaps.html");
soccerArray[6] = new menuObj("BMO Field", "bmofield.html");

// Promotions Links
var promotionsArray = new Array();
promotionsArray[0] = new menuObj("BMO Power of Blue","powerOfBlue.html");
promotionsArray[1] = new menuObj("BMO Soccer Spirit Awards","spiritAwards.html");
promotionsArray[2] = new menuObj("BMO Ultimate Fan TFC", "ultimateFan.html");

// Community
var communityArray = new Array();
communityArray[0] = new menuObj("Featured BMO Soccer Clubs","bmoSoccerClubs.html");
communityArray[1] = new menuObj("Minifests","csaMinifests.html");
communityArray[2] = new menuObj("National Team","csaNationalTeam.html");
communityArray[3] = new menuObj("National Championships","nationalChampionships.html");
communityArray[4] = new menuObj("Play Soccer", "playSoccer.html");

// Downloads
var downloadsArray = new Array();
downloadsArray[0] = new menuObj("Screensavers","screensavers.html");
downloadsArray[1] = new menuObj("Shootout","shootOut.html");
downloadsArray[2] = new menuObj("Wallpapers","wallpapers.html");
downloadsArray[3] = new menuObj("Gameday Video &amp; Photo","gameDayVideo.html");




//**************************************************************************//
// Output Top Menu														    //
//**************************************************************************//

function createTopMenu(selected) {

	document.write('&nbsp;'); // fixes bug in IE7
	document.write('<ul id="menuLinks">');
	document.write('	<li><a href="index.html"><img src="images/btn_home_off.gif" alt="Home" id="home" /></a></li>');
	document.write('	<li>');
	document.write('		<a href="'+soccerArray[0].url+'"><img src="images/btn_bmoAndSoccer_off.gif" alt="BMO &amp; Soccer" id="soccer" /></a>');
							createDropDown("soccer");	
	document.write('	</li>');
	document.write('	<li>');
	document.write('		<a href="'+promotionsArray[0].url+'"><img src="images/btn_promotions_off.gif" alt="Promotions" id="promotions" /></a>');
							createDropDown("promotions");
	document.write('	</li>');
	document.write('	<li>');
	document.write('		<a href="'+communityArray[0].url+'"><img src="images/btn_community_off.gif" alt="Community" id="community" /></a>');
							createDropDown("community");
	document.write('	</li>');
	document.write('	<li>');
	document.write('		<a href="'+downloadsArray[0].url+'"><img src="images/btn_gamesAndDownloads_off.gif" alt="Games &amp; Downloads" id="downloads" /></a>');
							createDropDown("downloads");
	document.write('	</li>');
	document.write('</ul>');
	
	// set current menu tab image
	if (selected != null) {
		document.getElementById(selected).src = document.getElementById(selected).src.replace("_off","_current");
	}
}



//**************************************************************************//
// Output Side Menu															//
//**************************************************************************//

function createSideMenu(section, displayName, subsectionID) { // where subsectionID is the array number to highlight
	document.write('<h2>'+displayName+'</h2>');
	document.write('<ul id="sideMenu">');
	for (x = 0; x < eval(section + "Array").length; x++) {
	    if (eval(section + "Array")[x] != null) {
	        document.write('<li><a href="' + eval(section + "Array")[x].url + '" id="' + eval(section + "Array")[x].url + '_link" ' + (subsectionID == x + 1 ? "class=\"selected\"" : "") + ' title="' + eval(section + "Array")[x].name + '" >' + eval(section + "Array")[x].name + '</a></li>');
	    }
	}	
	document.write('</ul>');
	
}



//**************************************************************************//
// Supporting Functions														//
//**************************************************************************//

// Object Constructor for Promotions
function menuObj(name, url) {
	this.name = name;
	this.url = url;
}

// Create UL List for Drop Down and write to screen
function createDropDown(section) {
    document.write("<ul id='" + section + "DropDown' class='dropDown'>");
    var numResults = 0;
	for (x = 0; x < eval(section + "Array").length; x++) {
	    if (eval(section + "Array")[x] != null) {
	        if (x == (eval(section + "Array").length - 1)) { // if last item in menu, apply style
	            document.write("<li class='last'><a href='" + eval(section + "Array")[x].url + "'>" + eval(section + "Array")[x].name + "</a></li>");
	        }
	        else {
	            document.write("<li><a href='" + eval(section + "Array")[x].url + "'>" + eval(section + "Array")[x].name + "</a></li>");
	        }
	        numResults++;
	    }
	}
	document.write("</ul>");

	var boxHeight = (20 * numResults); // calculate the height of the drop down menu (line height x rows)
	
	eval("attributes" + section + " = { height: { to: "+boxHeight+" } } ");

	// create a dynamic variable name for each animation instance ie. (anim + "promotions")
	eval("anim" + section + "DropDown = new YAHOO.util.Anim('"+section+"DropDown', attributes"+section+", 0.75, YAHOO.util.Easing.backOut)"); 
	//var anim = new YAHOO.util.Anim('demo', attributes, 0.75, YAHOO.util.Easing.backOut);
	
}


// Function to show drop down menu
function showMenu() {
	hideAllMenus(); // hide all menus before displaying selected one
	this.src = this.src.replace(/_off/,"_on");	
		if (t == t) { // if timer id hasn't changed, clear current timer
			clearTimeout(t);
		}
		eval("anim"+this.id+"DropDown").animate(); // calls animation function to show menu ie. instance.animate()
		document.getElementById(this.id+"DropDown").style.display = "block";
		t = setTimeout("hideMenu('"+this.id+"')",4000); // hide menu after 4 seconds
}


// Hide all Drop Down Menus
function hideAllMenus() {
	document.getElementById("soccerDropDown").style.display = "none";
	document.getElementById("promotionsDropDown").style.display = "none";
	document.getElementById("communityDropDown").style.display = "none";
	document.getElementById("downloadsDropDown").style.display = "none";

	document.getElementById("soccerDropDown").style.height = "0px";
	document.getElementById("promotionsDropDown").style.height = "0px";
	document.getElementById("communityDropDown").style.height = "0px";	
	document.getElementById("downloadsDropDown").style.height = "0px";	
	
	if (document.getElementById("soccer").src.match("_on")) {
		document.getElementById("soccer").src = (document.getElementById("soccer").src).replace(/_on/,"_off");	
	}	
	if (document.getElementById("promotions").src.match("_on")) {
		document.getElementById("promotions").src = (document.getElementById("promotions").src).replace(/_on/,"_off");
	}
	if (document.getElementById("community").src.match("_on")) {	
		document.getElementById("community").src = (document.getElementById("community").src).replace(/_on/,"_off");
	}
	if (document.getElementById("downloads").src.match("_on")) {
		document.getElementById("downloads").src = (document.getElementById("downloads").src).replace(/_on/,"_off");	
	}
}


// Hide Individual Drop Down Menu
function hideMenu(id) {
	document.getElementById(id+"DropDown").style.display = "none";
	document.getElementById(id+"DropDown").style.height = "0px";
	document.getElementById(id).src = (document.getElementById(id).src).replace(/_on/,"_off");	
}



// Mouse Over to Toggle Menu Image
function mouseOver() {

	hideAllMenus(); // hide all drop down menus
	
	if (this.src.match("_off")) {
		this.src = this.src.replace(/_off/,"_on");
	}
	else if (this.src.match("_on")) {
		this.src = this.src.replace(/_on/,"_off");	
	}
	
}





//**************************************************************************//
// Page Load Initialization for Menu									    //
//**************************************************************************//

window.onload = init; // Perform init onload



// Onclick Event Handlers for Menu
function init() {
	
	// Pre-Load Menu Images
	img1 = new Image();
	img2 = new Image();
	img3 = new Image();
	img4 = new Image();
	img5 = new Image();
	img6 = new Image();
	img7 = new Image();
	img8 = new Image();
	img9 = new Image();
	img10 = new Image();
	img11 = new Image();

		
	img1.src = 'images/btn_home_off.gif';
	img2.src = 'images/btn_bmoAndSoccer_off.gif';
	img3.src = 'images/btn_promotions_off.gif';	
	img4.src = 'images/btn_community_off.gif';	
	img5.src = 'images/btn_gamesAndDownloads_off.gif';	
	img6.src = 'images/btn_home_on.gif';
	img7.src = 'images/btn_bmoAndSoccer_on.gif';
	img8.src = 'images/btn_promotions_on.gif';	
	img9.src = 'images/btn_community_on.gif';	
	img10.src = 'images/btn_gamesAndDownloads_on.gif';		
	img10.src = 'images/sideMenuItem_over_bg.gif';
	
	// Roll Over Effects
	document.getElementById("home").onmouseover = mouseOver; // no dropdown menu, so only do mouseover
	document.getElementById("soccer").onmouseover = showMenu;
	document.getElementById("promotions").onmouseover = showMenu; 
	document.getElementById("community").onmouseover = showMenu; 
	document.getElementById("downloads").onmouseover = showMenu; 

	// Roll Our Effects	
	document.getElementById("home").onmouseout = mouseOver; // no dropdown menu, so only do mouseover

				
}