function textSize(language) {
	if (language==null) {
		if (isFrenchSite()) {
			language='FR';
		} else {
			language='EN';
		}
	}
	var upArrow = (language=="EN" ? "arrowUp":"arrowUp_French");
	var downArrow = (language=="EN" ? "arrowDown":"arrowDown_French");
	var greyUp = (language=="EN" ? "arrowUp_grey":"arrowUp_grey_French");
	var grreyDown = (language=="EN" ? "arrowDown_grey":"arrowDown_grey_French");
	var largerTitle = (language=="EN" ? "Larger Text":"Caract&egrave;res plus gros");
	var smallerTitle = (language=="EN" ? "Smaller Text":"Caract&egrave;res plus petits");
	
	document.write('<form id=\"tab\"><a class=\"' + upArrow + '\" name=\"largertext\" title=\"' + largerTitle + '\" onclick=\"return fontsize(\'larger\');\" id=\"largertext\" ></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"' + downArrow + '\" name=\"Smaller Text\" title=\"' + smallerTitle + '\" onclick=\"return fontsize(\'smaller\');\" id=\"smallertext\" ></a></form>');

	if(getActiveStyleSheet()=='A-'){
		document.getElementById('smallertext').className = grreyDown;
	}
	if(getActiveStyleSheet()=='A+++'){
		document.getElementById('largertext').className = greyUp;
	}
}

function fontsize(direction) {
	var f = document.forms[0];
	var fonts = new Array("A-","A","A+","A++","A+++");
	if (WM_acceptsCookies==false) {
		if (isFrenchSite()) {
			alert("Vous devrez activer des t&eacute;moins pour changer la taille de la police.");
		} else {
			alert("You will need to enable cookies to use the text-size changer");
		}
		return false;
	}
	active = getActiveStyleSheet();
	if (active=='A-' && direction=='smaller') {
		if (isFrenchSite()) {
			alert("Il est impossible d'obtenir une police plus petite que la police actuelle.");
		} else {
			alert("You cannot go any smaller than the current font");
		}
		return false;
	} else if (active=='A+++' && direction=='larger') {
		if (isFrenchSite()) {
			alert("Il est impossible d'obtenir une police plus grande que la police actuelle.");
		} else {
			alert("You cannot go any larger than the current font");
		}
		return false;
	} else {
		//loop through array to get match
		var i=0;
		for (i=0;i<fonts.length;i++) {
			if (active == fonts[i]) {
				if (direction=="smaller") {
					i--;
					if (i<0) {
						i=0;
					}
				} else {
					i++;
					if (i>4) {
						i=4;
					}
				}
				break;
			}
		}
		setActiveStyleSheet(fonts[i]);
		f.submit();
		return true;
	}
}

function setActiveStyleSheet(title) {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) {
				a.disabled = false;
			}
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
			return a.getAttribute("title");
		}
	}
	return null;
}

function getPreferredStyleSheet() {
	return ('A');
}

window.onload = function(e) {
	var cookie = WM_readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	WM_setCookie("style", title, 365);
}

var cookie = WM_readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
	title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);

/*** fade.js ***/
var over = 0;

/****
* Developed from an original idea at brainerror.net and Communis 2004, Manitoba Hydro 2007
****/
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart >= opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++){
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	if (document.getElementById('ahem').style.display == 'none' && getActiveStyleSheet() != 'xpda') {
		var object = document.getElementById(id).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	} 
}

function dy(id){
	document.getElementById(id).style.display = 'none';
}

function instantClear(id) {
	if (document.getElementById('ahem').style.display == 'none' && getActiveStyleSheet() != 'xpda') {
		if (document.getElementById(id)) {
			var object = document.getElementById(id).style;
			instantOpac(0,id)
			object.visibility = "hidden";
			object.display = "none";
		}
	}
}

function instantOpac(opac,id) {
	if (document.getElementById('ahem').style.display == 'none' && getActiveStyleSheet() != 'xpda') {
		if (document.getElementById(id)) {
			var object = document.getElementById(id).style;
			object.opacity = opac;
			object.MozOpacity = opac;
			object.KhtmlOpacity = opac;
			object.filter = "alpha(opacity=" + opac + ")";
		}
	} 
}
	
/*** Site-Specific Code ***/

/*** menu calls ***/

function bye(theId) {
	if(over==0) {
		instantClear(theId);
	}
}

function byeAllNow() {
	instantClear('corporate'); // top menus
	instantClear('community');
	instantClear('environment');
	instantClear('safety');
	instantClear('careers');
	instantClear('projects');
}

function byeAll() {
	if(over == 0) {
		byeAllNow();
	}
}	

function mOver() {
	over = 1;
}

function mOut() {
	over=0;
	string="byeAll();";
	setTimeout(string,1400);
}

function subnav(theId,num) {
	if (document.getElementById('ahem').style.display == 'none' && getActiveStyleSheet() != 'xpda' && document.getElementById(theId).style.visibility != "visible") {
		if (num == null) {
			num = 0.5;
		}
		byeAllNow();
		mOver();
		emstring = ' '+num+'em';
		changeOpac(0, theId);
		document.getElementById(theId).style.display="inline";		// remove from some screenreaders
		document.getElementById(theId).style.visibility="visible";	// remove from other screenreaders
		document.getElementById(theId).style.position='absolute';	// relative to parent element
		document.getElementById(theId).style.top='1.75em';		// move down
		document.getElementById(theId).style.left=emstring;
		opacity(theId,0,90,100);
	}
}

function submenu(id,here) {
	var a = 'onmouseover="mOver();" onmouseout="mOut();">';
	var b = '</a></li><li title=""><a';
	var c = '" class="sub"><li title=""><a';

	if (here == 0) {
		here = ' class="here"';
	} else {
		here = ' ';
	}
	if (document.getElementById('ahem').style.display == 'none' && getActiveStyleSheet() != 'xpda' && (document.getElementById(id) == null )) {
		if (isFrenchSite()) {
			if (id == 'corporate') {
				document.write('<ul title="Corporate submenu" id="' + id + c + here + ' href="/francais/corporate/about_us.shtml" ' + a + 'Qui nous sommes' + b + here + ' href="/francais/corporate/electricity_exports.shtml" ' + a + 'Exportations d\'&eacute;lectricit&eacute;' + b + here + ' href="/francais/corporate/facilities_operations.shtml" ' + a + 'Installations et activit&eacute;s' + b + here + ' href="/francais/corporate/financial.shtml" ' + a + 'Donn&eacute;es financi&egrave;res' + b + here + ' href="/francais/corporate/history/history.shtml" ' + a + 'Histoire' + b + here + ' href="/francais/corporate/media.shtml" ' + a + 'Nouvelles et rapports avec les m&eacute;dias' + b + here + ' href="/francais/regulatory_affairs/index.shtml" ' + a + 'Questions r&eacute;glementaires' + b + here + ' href="/francais/corporate/research_and_development.shtml" ' + a + 'Recherche-d&eacute;veloppement' + b + here + ' href="/francais/corporate/water_regimes/general_information.shtml" ' + a + 'R&eacute;gimes et niveaux des eaux</a></li></ul>');
			}
			if (id == 'community') {
				document.write('<ul title="Community submenu" id="' + id + c + here + ' href="/francais/community/index.shtml" ' + a + 'Aper&ccedil;u' + b + here + ' href="/francais/community/aboriginal_relations/index.shtml" ' + a + 'Relations avec les Autochtones' + b + here + ' href="/francais/community/spirit_walkway.shtml" ' + a + '&Eacute;v&eacute;nements' + b + here + ' href="/francais/community/neighbours_helping_neighbours/index.shtml" ' + a + 'Programmes</a></li></ul>');
			}
			if (id == 'environment') {
				document.write('<ul title="Environment submenu" id="' + id + c + here + ' href="/francais/environment/index.shtml" ' + a + 'Aper&ccedil;u' + b + here + ' href="/francais/environment/greenhouse_gas/index.shtml" ' + a + 'Rapports sur les gaz &agrave; effet de serre' + b + here + ' href="/francais/environment/policy/ems.shtml" ' + a + 'Politique et principes' + b + here + ' href="/francais/environment/programs/events.shtml" ' + a + 'Programmes' + b + here + ' href="/francais/environment/projects/index.shtml" ' + a + 'Projets' + b + here + ' href="/francais/environment/energy_sources/index.shtml" ' + a + 'Sources d\'&eacute;nergie</a></li></ul>');
			}
			if (id == 'safety') {
				document.write('<ul title="Safety submenu" id="' + id + c + here + ' href="/francais/safety_and_education/index.shtml" ' + a + 'Aper&ccedil;u' + b + here + ' href="/francais/safety_and_education/emergencies/index.shtml" ' + a + 'Urgences' + b + here + ' href="/francais/safety_and_education/emf/index.shtml" ' + a + '&Eacute;tudes et rapports sur les C&Eacute;M' + b + here + ' href="/francais/safety_and_education/farm/index.shtml" ' + a + 'S&eacute;curit&eacute; &agrave; la ferme' + b + here + ' href="/francais/safety_and_education/home/index.shtml" ' + a + 'S&eacute;curit&eacute; &agrave; la maison' + b + here + ' href="/francais/safety_and_education/job/index.shtml" ' + a + 'S&eacute;curit&eacute; au travail' + b + here + ' href="/francais/safety_and_education/seasonal_safety_tips.shtml" ' + a + 'S&eacute;curit&eacute; saisonni&egrave;re' + b + here + ' href="/francais/safety_and_education/outdoor/index.shtml" ' + a + 'S&eacute;curit&eacute; &agrave; l\'ext&eacute;rieur' + b + here + ' href="/francais/learning_zone/index.shtml" ' + a + 'Zone d\'apprentissage</a></li></ul>');
			}
			if (id == 'projects') {
				document.write('<ul title="Projects submenu" id="' + id + c + here + ' href="/francais/projects/index.shtml" ' + a + 'Aper&ccedil;u' + b + here + ' href="/francais/projects/bipoleIII/index.shtml" ' + a + 'Bipolaire III'  + b + here + ' href="/francais/projects/conawapa.shtml" ' + a + 'Centrale de Conawapa' + b + here + ' href="/francais/projects/keeyask/index.shtml" ' + a + 'Centrale de Keeyask' + b + here + ' href="/francais/projects/pointe_du_bois/index.shtml" ' + a + 'Remplacement de l&rsquo;&eacute;vacuateur de crues de la centrale de Pointe-du-Bois' + b + here + ' href="/francais/projects/riel/index.shtml" ' + a + 'Initiative Riel d&rsquo;am&eacute;lioration de la fiabilit&eacute;' + b + here + ' href="/francais/projects/wind_powered.shtml" ' + a + 'Production d&rsquo;&eacute;nergie &eacute;olienne' + b + here + ' href="/francais/projects/wuskwatim/overview.shtml" ' + a + 'Projet de centrale de Wuskwatim</a></li></ul>');
			}
		} else {
			if (id == 'corporate') {
				document.write('<ul title="Corporate submenu" id="' + id + c + here + ' href="/corporate/about_us.shtml?WT.mc_id=2102" ' + a + 'About Us' + b + here + ' href="/corporate/subsidiaries.shtml?WT.mc_id=2105" ' + a + 'Business Interests' + b + here + ' href="/corporate/electricity_exports.shtml?WT.mc_id=2105" ' + a + 'Electricity Exports' + b + here + ' href="/corporate/facilities_operations.shtml?WT.mc_id=2108" ' + a + 'Facilities & Operations' + b + here + ' href="/corporate/financial.shtml?WT.mc_id=2111" ' + a + 'Financial' + b + here + ' href="/corporate/history/history.shtml?WT.mc_id=2114" ' + a + 'History' + b + here + ' href="/corporate/media.shtml?WT.mc_id=2120" ' + a + 'News & Media Contact' + b + here + ' href="/regulatory_affairs/index.shtml?WT.mc_id=2123" ' + a + 'Regulatory Affairs' + b + here + ' href="/corporate/research_and_development.shtml?WT.mc_id=2126" ' + a + 'Research & Development' + b + here + ' href="/corporate/water_regimes/general_information.shtml?WT.mc_id=2129" ' + a + 'Water Regimes & Levels</a></li></ul>');
			}
			if (id == 'community') {
				document.write('<ul title="Community submenu" id="' + id + c + here + ' href="/community/index.shtml?WT.mc_id=2202" ' + a + 'Overview' + b + here + ' href="/community/aboriginal_relations/index.shtml?WT.mc_id=2204" ' + a + 'Aboriginal Relations' + b + here + ' href="/community/events.shtml?WT.mc_id=2207" ' + a + 'Events' + b + here + ' href="/community/neighbours_helping_neighbours/index.shtml?WT.mc_id=2210" ' + a + 'Programs</a></li></ul>');
			}
			if (id == 'environment') {
				document.write('<ul title="Environment submenu" id="' + id + c + here + ' href="/environment/index.shtml?WT.mc_id=2302" ' + a + 'Overview' + b + here + ' href="/environment/electric_vehicles.shtml" ' + a + 'Electric Vehicles' + b + here + ' href="/environment/greenhouse_gas/index.shtml?WT.mc_id=2307" ' + a + 'Greenhouse Gas Reports' + b + here + ' href="/environment/policy/ems.shtml?WT.mc_id=2310" ' + a + 'Policy & Principles' + b + here + ' href="/environment/programs/events.shtml?WT.mc_id=2313" ' + a + 'Programs' + b + here + ' href="/environment/projects/index.shtml?WT.mc_id=2316" ' + a + 'Projects' + b + here + ' href="/environment/publications.shtml?WT.mc_id=2319" ' + a + 'Publications' + b + here + ' href="/environment/energy_sources/index.shtml?WT.mc_id=2305" ' + a + 'Sources of Energy</a></li></ul>');
			}
			if (id == 'safety') {
				document.write('<ul title="Safety submenu" id="' + id + c + here + ' href="/safety_and_education/index.shtml?WT.mc_id=2402" ' + a + 'Overview' + b + here + ' href="/safety_and_education/emergencies/index.shtml?WT.mc_id=2404" ' + a + 'Emergencies' + b + here + ' href="/safety_and_education/emf/index.shtml?WT.mc_id=2407" ' + a + 'EMF Studies & Reports' + b + here + ' href="/safety_and_education/farm/index.shtml?WT.mc_id=2410" ' + a + 'Farm Safety' + b + here + ' href="/safety_and_education/home/index.shtml?WT.mc_id=2413" ' + a + 'Home Safety' + b + here + ' href="/safety_and_education/job/index.shtml?WT.mc_id=2416" ' + a + 'Job Safety' + b + here + ' href="/safety_and_education/seasonal_safety_tips.shtml?WT.mc_id=2419" ' + a + 'Seasonal Safety' + b + here + ' href="/safety_and_education/outdoor/index.shtml?WT.mc_id=2425 " ' + a + 'Outdoor Safety' + b + here + ' href="/learning_zone/index.shtml?WT.mc_id=2422" ' + a + 'The Learning Zone</a></li></ul>');
			}
			if (id == 'careers') {
				document.write('<ul title="Careers submenu" id="' + id + c + here + ' href="/careers/index.shtml?WT.mc_id=2502" ' + a + 'Overview' + b + ' href="/careers/current_initiatives/index.shtml?WT.mc_id=2519" ' + a + 'Jobs' + b + here + ' href="/careers/training_programs/professional_development/index.shtml?WT.mc_id=2531" ' + a + 'Professionals' + b + here + ' href="/careers/training_programs/trades/index.shtml?WT.mc_id=2528" ' + a + 'Trades' + b + here + ' href="/careers/technology/index.shtml" ' + a + 'Technology' + b + here + ' href="/careers/student_opportunities/index.shtml?WT.mc_id=2525" ' + a + 'Students' + b + here + ' href="/careers/employment_equity/index.shtml" ' + a + 'Employment Equity</a></li></ul>');
			}
			if (id == 'projects') {
				document.write('<ul title="Projects submenu" id="' + id + c + here + ' href="/projects/index.shtml?WT.mc_id=2602" ' + a + 'Overview' + b + here + ' href="/projects/bipoleIII/index.shtml?WT.mc_id=2604" ' + a + 'Bipole III'  + b + here + ' href="/projects/conawapa.shtml?WT.mc_id=2607" ' + a + 'Conawapa Generating Station' + b + here + ' href="/projects/keeyask/index.shtml?WT.mc_id=2612" ' + a + 'Keeyask Generating Station' + b + here + ' href="/projects/pointe_du_bois/index.shtml?WT.mc_id=2615" ' + a + 'Pointe du Bois Spillway Replacement' + b + here + ' href="/projects/riel/index.shtml?WT.mc_id=2618" ' + a + 'Riel Reliability Improvement Initiative' + b + here  + ' href="/projects/wind_powered.shtml?WT.mc_id=2621" ' + a + 'Wind-Powered Generation' + b + here + ' href="/projects/wuskwatim/overview.shtml?WT.mc_id=2624" ' + a + 'Wuskwatim Generation Project</a></li></ul>');
			}
		}
	}
}

function submenusep(id,here,subNum) {
	if (document.getElementById('ahem').style.display == 'none' && getActiveStyleSheet() != 'xpda') {
		if (here != 1) {
			subNum = 0;
			here = ' ';
		} else {
			here = ' class="here"';
			subNum = subNum;
		}

	}
}
