//**************************************************************************//
// Global Variables and Parameters 										    //
//**************************************************************************//

var t;


//**************************************************************************//
// Array of Objects containing  Link Names and URL's for Drop Down Menu's   //
//**************************************************************************//

// BMO Skating
//var bmoFigureSkatingArray = new Array();
//bmoFigureSkatingArray[0] = new menuObj("Grassroots","grassroots.html");
//bmoFigureSkatingArray[1] = new menuObj("BMO Report from the Pitch","reportFromPitch.html");
//bmoFigureSkatingArray[2] = new menuObj("Soccer Tips", "soccerTips.html");
//bmoFigureSkatingArray[3] = new menuObj("News Releases", "news.html");
//bmoFigureSkatingArray[4] = new menuObj("Toronto FC", "tfc.html");
//bmoFigureSkatingArray[5] = new menuObj("Vancouver Whitecaps FC", "whitecaps.html");
//bmoFigureSkatingArray[6] = new menuObj("BMO Field", "http://www.bmofield.com/");

// Power of Blue Links
//var pobArray = new Array();
//pobArray[0] = new menuObj("BMO Power of Blue","powerOfBlue.html");
//pobArray[1] = new menuObj("BMO Soccer Spirit Awards","spiritAwards.html");
//pobArray[2] = new menuObj("BMO Ultimate Fan TFC", "ultimateFan.html");
//
// national Team
//var nationalTeamArray = new Array();
//nationalTeamArray[0] = new menuObj("Featured BMO Soccer Clubs","bmoSoccerClubs.html");
//nationalTeamArray[1] = new menuObj("Minifests","csaMinifests.html");
//nationalTeamArray[2] = new menuObj("National Team","csaNationalTeam.html");
//nationalTeamArray[3] = new menuObj("National Championships","nationalChampionships.html");
//nationalTeamArray[4] = new menuObj("Play Soccer", "playSoccer.html");

// Canskate 
var canSkateArray = new Array();
//canSkateArray[0] = new menuObj("About the Medal Program","about_canskate.html");
//canSkateArray[1] = new menuObj("Medal Criteria","medal_criteria.html");
//canSkateArray[2] = new menuObj("BMO CanSkater of the Year","canskater_of_the_year_program.html");
//canSkateArray[3] = new menuObj("Dates to remember","canskate_dates.html");
canSkateArray[0] = new menuObj("Laur&eacute;ats du prix Patineur de l'ann&eacute;e Patinage Plus BMO Groupe financier","canskate_winners.html");

// Events
var eventsArray = new Array();
eventsArray[0] = new menuObj("Championnats canadiens de patinage artistique BMO","skating_championships.html");
eventsArray[1] = new menuObj("Championnats nationaux juniors BMO &ndash; <br />Patinage Canada","junior_nationals.html");
eventsArray[2] = new menuObj("D&eacute;fis de l'Est et de L'Ouest BMO &ndash; <br />Patinage Canada","eastern_and_western_challenge.html");
eventsArray[3] = new menuObj("Championnats de section BMO &ndash; <br />Patinage Canada","financial_group_skate_canada_sectionals.html");
eventsArray[4] = new menuObj("Championnats de patinage synchronis&eacute; BMO &ndash; Patinage Canada","synchronized_championships.html");

// Ultimate Fan
var ultimateFanArray = new Array();
ultimateFanArray[0] = new menuObj("Fan extr&#234;me BMO","bmo_ultimate_fan.html");
ultimateFanArray[1] = new menuObj("Papiers peints","wallpapers.html");
ultimateFanArray[2] = new menuObj("&Eacute;conomiseurs d'&eacute;cran","screensavers.html");
ultimateFanArray[3] = new menuObj("Livre &agrave; colorier","colouring_book.html");

// MasterCard
//var masterCardArray = new Array();
//masterCardArray[0] = new menuObj("Screensavers","screensavers.html");
//masterCardArray[1] = new menuObj("Shootout","shootOut.html");
//masterCardArray[2] = new menuObj("Wallpapers","wallpapers.html");
//masterCardArray[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/fr_home_off.gif" alt="Accueil" id="home" /></a></li>');
	document.write('	<li><a href="figure_skating.html"><img src="images/fr_bmoFigureSkating_off.gif" alt="BMO Groupe financier et le patinage artistique" id="bmoFigureSkating" /></a></li>');
	document.write('	<li><a href="power_of_blue.html"><img src="images/fr_pob_off.gif" alt="Privil&#232;ges bleu BMO" id="pob" /></a> </li>');
	document.write('	<li><a href="national_figure_team.html"><img src="images/fr_nationalTeam_off.gif" alt="&Eacute;quipe Canadienne de Patinage Artistique" id="nationalTeam" /></a></li>');
	document.write('	<li>');
	document.write('		<a href="canskate.html"><img src="images/fr_canSkate_off.gif" alt="Programme Patinage Plus" id="canSkate" /></a>');
							createDropDown("canSkate");
	document.write('	</li>');
	
	document.write('	<li>');
	document.write('		<a href="events.html"><img src="images/fr_events_off.gif" alt="Activit&eacute;s BMO - Patinage Canada" id="events" /></a>');
							createDropDown("events");
	document.write('	</li>');
	document.write('	<li>');
	document.write('		<a href="fan_centre.html"><img src="images/fr_fanZone_off.gif" alt="Zone des Partisans BMO" id="ultimateFan" /></a>');
							createDropDown("ultimateFan");
	document.write('	</li>');
	document.write('	<li><a href="mastercard.html"><img src="images/fr_masterCard_off.gif" alt="Carte Mastercard BMO de Patinage Canada" id="masterCard" /></a></li></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
  if (displayName == "BMO Skate Canada Mastercard") {
	document.write('<center><br /><a href="mastercard.html" title="Procurez-vous la carte MasterCard BMO de Patinage Canada."><img src="images/dont_have_mc_top.gif" alt="Procurez-vous la carte MasterCard BMO de Patinage Canada."></a><br /><a href="http://www4.bmo.com/cartesdecredit/affinite/recompenses/0,4978,35702_79459748,00.html" target="_blank" title="Pour en savoir plus"><img src="images/dont_have_mc_bottom.gif"alt="Pour en savoir plus"></a></center>');
  }

//	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>");

	// Gets the client heigt of the UL
	// Note: the UL must not be set to display:none, in order to caluclate client height
	var boxHeight = document.getElementById(section + "DropDown").clientHeight - 15; 
	
    eval("attributes" + section + " = { height: { to: "+boxHeight+" } } ");
	
	document.getElementById(section+"DropDown").style.display = 'none';
	document.getElementById(section+"DropDown").style.visibility = 'visible';
	
	// 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("bmoFigureSkatingDropDown").style.display = "none";
	//document.getElementById("pobDropDown").style.display = "none";
	//document.getElementById("nationalTeamDropDown").style.display = "none";
	document.getElementById("canSkateDropDown").style.display = "none";
	document.getElementById("eventsDropDown").style.display = "none";
	document.getElementById("ultimateFanDropDown").style.display = "none";
	//document.getElementById("masterCardDropDown").style.display = "none";

	//document.getElementById("bmoFigureSkatingDropDown").style.height = "0px";
	//document.getElementById("pobDropDown").style.height = "0px";
	//document.getElementById("nationalTeamDropDown").style.height = "0px";	
	document.getElementById("canSkateDropDown").style.height = "0px";	
	document.getElementById("eventsDropDown").style.height = "0px";
	document.getElementById("ultimateFanDropDown").style.height = "0px";	
	//document.getElementById("masterCardDropDown").style.height = "0px";	
	
	//if (document.getElementById("bmoFigureSkating").src.match("_on")) {
	//	document.getElementById("bmoFigureSkating").src = (document.getElementById("bmoFigureSkating").src).replace(/_on/,"_off");	
	//}	
	//if (document.getElementById("pob").src.match("_on")) {
	//	document.getElementById("pob").src = (document.getElementById("pob").src).replace(/_on/,"_off");
	//}
	//if (document.getElementById("nationalTeam").src.match("_on")) {	
	//	document.getElementById("nationalTeam").src = (document.getElementById("nationalTeam").src).replace(/_on/,"_off");
	//}
	if (document.getElementById("canSkate").src.match("_on")) {
		document.getElementById("canSkate").src = (document.getElementById("canSkate").src).replace(/_on/,"_off");	
	}
	if (document.getElementById("events").src.match("_on")) {
		document.getElementById("events").src = (document.getElementById("events").src).replace(/_on/,"_off");	
	}
	if (document.getElementById("ultimateFan").src.match("_on")) {
		document.getElementById("ultimateFan").src = (document.getElementById("ultimateFan").src).replace(/_on/,"_off");	
	}
	//if (document.getElementById("masterCard").src.match("_on")) {
	//	document.getElementById("masterCard").src = (document.getElementById("masterCard").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();
	img12 = new Image();
	img13 = new Image();
	img14 = new Image();
	img15 = new Image();
	img16 = new Image();
	img17 = new Image();

		
	img1.src = 'images/fr_home_off.gif';
	img2.src = 'images/fr_bmoFigureSkating_off.gif';
	img3.src = 'images/fr_pob_off.gif';	
	img4.src = 'images/fr_nationalTeam_off.gif';	
	img5.src = 'images/fr_canSkate_off.gif';	
	img6.src = 'images/fr_events_off.gif';
	img7.src = 'images/fr_ultimateFan_off.gif';
	img8.src = 'images/fr_masterCard_off.gif';	
	img9.src = 'images/fr_home_on.gif';	
	img10.src = 'images/fr_bmoFigureSkating_on.gif';	
	img11.src = 'images/fr_pob_on.gif';
	img12.src = 'images/fr_nationalTeam_on.gif';
	img13.src = 'images/fr_canSkate_on.gif';
	img14.src = 'images/fr_events_on.gif';
	img15.src = 'images/fr_ultimateFan_on.gif';
	img16.src = 'images/fr_masterCard_on.gif';
	img17.src = 'images/sideMenuItem_over_bg.gif';
	
	// Roll Over Effects
	document.getElementById("home").onmouseover = mouseOver; // no dropdown menu, so only do mouseover
	document.getElementById("bmoFigureSkating").onmouseover = mouseOver;
	document.getElementById("pob").onmouseover = mouseOver; 
	document.getElementById("nationalTeam").onmouseover = mouseOver; 
	document.getElementById("canSkate").onmouseover = showMenu; 
	document.getElementById("events").onmouseover = showMenu; 
	document.getElementById("ultimateFan").onmouseover = showMenu; 
	document.getElementById("masterCard").onmouseover = mouseOver; 

	// Roll Our Effects	
	document.getElementById("home").onmouseout = mouseOver; // no dropdown menu, so only do mouseover
	document.getElementById("bmoFigureSkating").onmouseout = mouseOver;
	document.getElementById("pob").onmouseout = mouseOver;
	document.getElementById("nationalTeam").onmouseout = mouseOver;
	document.getElementById("masterCard").onmouseout = mouseOver;
				
}
