/* 
=============================================
DETERMINE WHICH PAGE IS BEING VIEWED
=============================================
*/
var rootPath = "";

// array of possible paths that the green campaign is in
// e.g. the live server is under /seeinggreen/, but the development directory is under /green_campaign/
// make sure that the web site structure doesn't duplicate any folders
// e.g.  having the home page as  /seeinggreen/seeinggreen/index.html
var validPaths = new Array("/climateconference2007/", "/dev/climateconference2007/");

var langID = "en";
var windowPath = window.location.pathname + "";
var windowURL = window.location.href + "";
if (windowURL.indexOf(".html") == -1) {
	windowURL = windowURL + "index.html";
}
if( windowURL.indexOf(".fr.")>0)
{
	langID = "fr";
}


var urlParameters = "";
if (windowURL.indexOf("?") > 0) {
	// we got a parameter in the url...
	urlParameters = stripSubPath(windowURL, "?");
}

var namedAnchor = "";
if (windowURL.indexOf("#") > 0) {
	// we got a named anchor...
	namedAnchor = stripSubPath(windowURL, "#");
}

// used in the page template...
var tempURL = windowURL;

var pagePath = "";
for (x = 0; x < validPaths.length; x++) {
	pagePath = stripSubPath(windowPath, validPaths[x]);
	if (pagePath == false) {
	} else {
		x = validPaths.length;
	}
}
// if for some reason the browser can't figure out the page we're on, default to index.html
if (pagePath == false) {
	pagePath = "index.html";
}

// if there is no .html extension in the current URL, it means we're browsing the folder
// so append index.html.
if (pagePath.indexOf(".html") == -1) {
	pagePath = pagePath + "index.html";
}

// figure out where the root of the site is, based on number of slashes
var num_slashes = pagePath.split("/");
for (x = 1; x < num_slashes.length; x++) {
	rootPath = rootPath + "../";
}

/*
=============================================
FUNCTIONS ARE DEFINED BELOW
=============================================
*/

// removes all portions of the path except for 
function stripSubPath(path, find) {
	var ret;
	var mypath = path;
	ret = false;
	if (path.indexOf("\\")) {
		mypath = mypath.replace(/\\/g, "/");
	}
	if (mypath.indexOf(find) > -1) {
		ret = mypath.substr(mypath.indexOf(find) + find.length);
	}

	return ret;
}

  		function arrangeMenus()
  		{
  			var k=0;
  			var maxLevel = 0;
  			for( var i=0; i<arrMenu.length; i++)
  			{
				if (arrMenu[i]["level"] > maxLevel) {
					maxLevel = arrMenu[i]["level"];
				}
  				if( pagePath + "" == arrMenu[i]["url_"+langID] + "")
  				{
  					arrMenu[i]["active"] = true;
  					arrMenu[i]["show"] = true;
  					arrMenu[i]["expand"] = true;
  					
  					// move up and set the parent to expand...
  					var curdepth = arrMenu[i]["level"];
  					for (ii = i; ii > 0; ii--) {
  						if (curdepth > arrMenu[ii]["level"]) {
  							arrMenu[ii]["expand"] = true;
		  					arrMenu[ii]["active"] = true;
	  						curdepth = arrMenu[ii]["level"];
  						}
  					}
  					k  = i;
  					kk = i;
  				}
  				else
  				{
  					arrMenu[i]["active"] = false;
  					arrMenu[i]["show"] = false;
  					arrMenu[i]["expand"] = false;
  				}

  			}

			
			// loop through the array "maxLevel" times to properly expand the entries
			// basically we only expand the immediate children of that entry... it will naturally expand...


			// always show top level menus
			for( var i=0; i<arrMenu.length; i++)
			{
				if (arrMenu[i]["level"] == 0) {
					arrMenu[i]["show"] = true;
				}
			}
			var expanding = false;
			for (var currentLevel = 0; currentLevel <= maxLevel; currentLevel++) {
				expanding = false;
				for( var i=0; i<arrMenu.length; i++)
				{
					if (arrMenu[i]["expand"] == true) {
						// show immediate children..
						for( var ii=i+1; ii<arrMenu.length; ii++)
						{
							if (arrMenu[ii]["level"] == currentLevel + 1) {
								arrMenu[ii]["show"] = true;
							}  else {
								if (arrMenu[ii]["level"] == currentLevel) {
									break;
								}
							}
						}
					}
				}
			}


  			return;
  		}




/*
	showMenus();
	
	This is the routine which outputs the actual menu structure. 
	Modify the appropriate levels HTML to adjust the style as necessary
*/
  		function showMenus()
  		{

  			for( var i=0; i<arrMenu.length; i++)
  			{

  				if(arrMenu[i]["level"]==0)
  				{
  					
// ##################### Change Background Image ################################
// #
// # Look for i == and set ID to appropriate nav.
// # ID is generated through each navigation item added
// # Search for: background-image:url("+rootPath+"  the image path is located here
// ################################################################################
  					if(arrMenu[i]["active"] || arrMenu[i]["expand"])
  					{
  						if(i==1)
  						{
							// show arrow pointing down
							document.write("<tr><td valign='middle' class='LeftHandMenus_l0_on' style='padding-left:5px; padding-right:5px;'><img src='"+rootPath+"images/nav/top_arrow_down.gif' border='0'alt=''/></td><td class='LeftHandMenus_l0_on' style='padding-right:5px;background-image:url("+rootPath+"images/nav/what_can_do_gradient.gif);'  valign='top'>");
  						}
  						else
  						{
  							// show arrow pointing down
						  	document.write("<tr><td valign='middle' class='LeftHandMenus_l0_on' style='padding-left:5px; padding-right:5px;'><img src='"+rootPath+"images/nav/top_arrow_down.gif' border='0'alt=''/></td><td class='LeftHandMenus_l0_on' style='padding-right:5px;' valign='top'>");
  						}
  					
  					}
  					else
  					{
  						if(i==1)
  						{
  							// show arrow pointing right
  							document.write("<tr><td valign='middle' class='LeftHandMenus_l0_off' style='padding-left:5px;  padding-right:5px;'><img src='"+rootPath+"images/nav/top_level_arrow.gif' border='0' alt=''/></td><td class='LeftHandMenus_l0_off' style='padding-right:5px;background-image:url("+rootPath+"images/nav/what_can_do_gradient.gif);' valign='top'>");
  						}
  						else
						{
  							// show arrow pointing right
					  		document.write("<tr><td valign='middle' class='LeftHandMenus_l0_off' style='padding-left:5px;  padding-right:5px;'><img src='"+rootPath+"images/nav/top_level_arrow.gif' border='0' alt=''/></td><td class='LeftHandMenus_l0_off' style='padding-right:5px;' valign='top'>");
  						}
  					
  					
  					}

  					arrMenu[i]["show"] = true;

  				}
  				if(arrMenu[i]["level"]==1)
  				{
  					if(arrMenu[i]["show"])
  					{
  						if(arrMenu[i]["active"])
  						{
  							document.write('<tr><td colspan="2" style="padding-left:20px;" class="LeftHandMenus_l1_on">');
  						}
  						else
  						{
  							document.write('<tr><td colspan="2" style="padding-left:20px;" class="LeftHandMenus_l1_off"" onMouseover="this.className=\'LeftHandMenus_l1_on\';" onMouseout="this.className=\'LeftHandMenus_l1_off\';">');
  						}

  					}
  				}
  				if(arrMenu[i]["level"]==2)
  				{
  					if(arrMenu[i]["show"])
  					{
  						if(arrMenu[i]["active"])
  						{
  							document.write('<tr><td colspan="2" style="padding-left:30px;" class="LeftHandMenus_l2_on">');
  						}
  						else
  						{
  							document.write('<tr><td colspan="2" style="padding-left:30px;" class="LeftHandMenus_l2_off"" onMouseover="this.className=\'LeftHandMenus_l2_on\';" onMouseout="this.className=\'LeftHandMenus_l2_off\';">');
  						}

  					}
  				}


  				if(arrMenu[i]["show"])
  				{
					document.write("<a href='");
					document.write(rootPath+arrMenu[i]["url_"+langID]);
					document.write("' title='");
					document.write(arrMenu[i]["text_"+langID]);
					document.write("'>");
					document.write(arrMenu[i]["text_"+langID]);
					document.write("</a>");

  					document.write("</td></tr>");
  					if(i<arrMenu.length-1)
  					{
  						document.write("<tr><td colspan='2' class='white_line'><img src='"+rootPath+"images/spacer.gif' border='0' width='1' height='1' alt=''/></td></tr>");
					}
  				}

  			}

  			return false;
  		}



/*
generateSiteMap()
- creates a site map using the contents of the arrMenu


*/
		function generateSiteMap()
		{
			document.write("<br>");
			for( var i=0; i<arrMenu.length; i++)
			{
				if(arrMenu[i]["level"]==2)
				{
					document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
				}
				if(arrMenu[i]["level"]==1)
				{
					document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
				}
				
				if(arrMenu[i]["level"]==0)
				{
					document.write("<br>");
				}

				document.write("<a href='");
				document.write(rootPath+arrMenu[i]["url_"+langID]);
				document.write("' title='");
				document.write(arrMenu[i]["text_"+langID]);
				document.write("'>");
				document.write(arrMenu[i]["text_"+langID]);
				document.write("</a>");

				if(i<arrMenu.length-1)
				{
					document.write("<br>");
				}
			}
			return false;
		}




/*
	flipLanguage()
	- switches between the languages of the current page based on the parameter
*/
function flipLanguage(new_lang_id)
{

	// text to search
	var searchExp = /\.html/gi;
	if (langID== "en") {
		searchExp = /\.html/gi;
	}
	if (langID == "fr") {
		searchExp = /\.fr\.html/gi;
	}

	// text to replace with
	var repExp = ".html";
	if (new_lang_id == "en") {
		repExp = ".html";
	}
	if (new_lang_id == "fr") {
		repExp = ".fr.html";
	}
	windowURL = windowURL.replace(searchExp, repExp);

	window.location=windowURL;
	return false;
}


// reloads page with printer friendly version  		
function showPrinterFriendly()
{
	var newLocation = windowURL;
	if (newLocation.indexOf("?") > -1) {
		newLocation = newLocation.substr(0,  newLocation.indexOf("?"));
	} else {
		if (newLocation.indexOf("#") > -1) {
			newLocation = newLocation.substr(0,  newLocation.indexOf("#"));
		}
	}
	if (urlParameters != "") {
		// automatically includes named anchor...
		newLocation = newLocation + "?print&" + urlParameters;
	} else {
		if (namedAnchor != "") {
			newLocation = newLocation + "?print#" + namedAnchor;
		} else {
			newLocation = newLocation + "?print";
		}
	}
	// launch printer version in new window...
	newwin = window.open(newLocation);
	
	if (newwin) {
	} else {
		alert("Please enable popups for the printer friendly page to show.");
	}
	return false;
}


// sets appropriate stylesheet
function setActiveStyleSheet(title) 
{
   var i, a, main;
   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;
	 }
   }
}
		
		
		
// used to determine which stylesheet to use when the page loads.
function checkPrint()
{
	if (windowURL.indexOf("?print") > -1) {
		setActiveStyleSheet("print");
	} else {
		setActiveStyleSheet("web");
	}
	return false;
}


// misc. rollover image code

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}




/*
==========================================================================
DEFINE MENU ARRAYS BELOW:

- english pages use the ".html" extension
- french pages use the ".fr.html" extension
- make sure that the english and equivalent french page are in the same folder
- define the menus as if you were creating a site map page.
- make sure to escape double quotes with a backslash (\")
e.g.  


x++;  // always increment x for each menu item
arrMenu[x] = new Array();
arrMenu[x]["level"] = 0;  // 0 - top level, 1 - second level, 2 - third level
arrMenu[x]["text_en"] = 'The English Label';
arrMenu[x]["text_fr"] = 'The French Label';
arrMenu[x]["url_en"] = "introduction/index.html";
arrMenu[x]["url_fr"] = "introduction/index.fr.html";

==========================================================================
*/


	arrMenu = new Array();
//********
	x=0;

	arrMenu[x] = new Array();
	arrMenu[x]["level"] = 0;
	arrMenu[x]["text_en"] = "Agenda";
	arrMenu[x]["text_fr"] = "Agenda";
	arrMenu[x]["url_en"] = "agenda.html";
	arrMenu[x]["url_fr"] = "agenda.html";

	x++;
	arrMenu[x] = new Array();
	arrMenu[x]["level"] = 0;
	arrMenu[x]["text_en"] = "Speaker Biographies";
	arrMenu[x]["text_fr"] = "Speaker Biographies";
	arrMenu[x]["url_en"] = "bios.html";
	arrMenu[x]["url_fr"] = "bios.html";
	
	x++;
	arrMenu[x] = new Array();
	arrMenu[x]["level"] = 0;
	arrMenu[x]["text_en"] = "Brochure";
	arrMenu[x]["text_fr"] = "Brochure";
	arrMenu[x]["url_en"] = "pdfs/oct23_brochure.pdf";
	arrMenu[x]["url_fr"] = "pdfs/oct23_brochure.pdf";

	x++;
	arrMenu[x] = new Array();
	arrMenu[x]["level"] = 0;
	arrMenu[x]["text_en"] = "Climate and Green Initiatives";
	arrMenu[x]["text_fr"] = "Climate and Green Initiatives";
	arrMenu[x]["url_en"] = "http://www.gov.mb.ca/stem/climate/index.html";
	arrMenu[x]["url_fr"] = "http://www.gov.mb.ca/stem/climate/index.html";

	x++;
	arrMenu[x] = new Array();
	arrMenu[x]["level"] = 0;
	arrMenu[x]["text_en"] = "Government of Manitoba - Home";
	arrMenu[x]["text_fr"] = "Voir la vie en vert pour réduire la consommation d'énergie";
	arrMenu[x]["url_en"] = "http://www.gov.mb.ca/index.html";
	arrMenu[x]["url_fr"] = "http://www.gov.mb.ca/index.html";
	
	x++;
	arrMenu[x] = new Array();
	arrMenu[x]["level"] = 0;
	arrMenu[x]["text_en"] = "Conference Workshop Summaries";
	arrMenu[x]["text_fr"] = "Conference Workshop Summaries";
	arrMenu[x]["url_en"] = "workshopsummaries.html";
	arrMenu[x]["url_fr"] = "workshopsummaries.html";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Agriculture";
		arrMenu[x]["text_fr"] = "Agriculture";
		arrMenu[x]["url_en"] = "pdfs/agriculture_workshop_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/agriculture_workshop_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Northern and Aboriginal";
		arrMenu[x]["text_fr"] = "Northern and Aboriginal";
		arrMenu[x]["url_en"] = "pdfs/aboriginal_and_northern_communities_workshop_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/aboriginal_and_northern_communities_workshop_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Transportation";
		arrMenu[x]["text_fr"] = "Transportation";
		arrMenu[x]["url_en"] = "pdfs/transportation_workshop_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/transportation_workshop_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Municipalities";
		arrMenu[x]["text_fr"] = "Municipalities";
		arrMenu[x]["url_en"] = "pdfs/municipalities_workshop_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/municipalities_workshop_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Business";
		arrMenu[x]["text_fr"] = "Business";
		arrMenu[x]["url_en"] = "pdfs/business_workshop_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/business_workshop_summary.pdf";
	
		
	x++;
	arrMenu[x] = new Array();
	arrMenu[x]["level"] = 0;
	arrMenu[x]["text_en"] = "Round Tables";
	arrMenu[x]["text_fr"] = "Round Tables";
	arrMenu[x]["url_en"] = "roundtables.html";
	arrMenu[x]["url_fr"] = "roundtables.html";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Aboriginal and Northern Communities";
		arrMenu[x]["text_fr"] = "Aboriginal and Northern Communities";
		arrMenu[x]["url_en"] = "pdfs/aboriginal_northern_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/aboriginal_northern_round_table_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Agriculture Community Leaders";
		arrMenu[x]["text_fr"] = "Agriculture Community Leaders";
		arrMenu[x]["url_en"] = "pdfs/agriculture_leaders_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/agriculture_leaders_round_table_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Agriculture Producer Groups";
		arrMenu[x]["text_fr"] = "Agriculture Producer Groups ";
		arrMenu[x]["url_en"] = "pdfs/agriculture_producers_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/agriculture_producers_round_table_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Business";
		arrMenu[x]["text_fr"] = "Business";
		arrMenu[x]["url_en"] = "pdfs/business_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/business_round_table_summary.pdf";
		
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Municipalities";
		arrMenu[x]["text_fr"] = "Municipalities";
		arrMenu[x]["url_en"] = "pdfs/municipalities_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/municipalities_round_table_summary.pdf";
				
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Transportation";
		arrMenu[x]["text_fr"] = "Transportation";
		arrMenu[x]["url_en"] = "pdfs/transportation_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/transportation_round_table_summary.pdf";
				
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "NGO/Academic";
		arrMenu[x]["text_fr"] = "NGO/Academic";
		arrMenu[x]["url_en"] = "pdfs/ngo_academic_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/ngo_academic_round_table_summary.pdf";
				
		x++;
		arrMenu[x] = new Array();
		arrMenu[x]["level"] = 1;
		arrMenu[x]["text_en"] = "Manitoba Round Table for Sustainable Development";
		arrMenu[x]["text_fr"] = "Manitoba Round Table for Sustainable Development";
		arrMenu[x]["url_en"] = "pdfs/mrtsd_round_table_summary.pdf";
		arrMenu[x]["url_fr"] = "pdfs/mrtsd_round_table_summary.pdf";

// =======================================
// END OF MENU ARRAYS
// =======================================