/**
* Copyright MacLaren MRM 2010
* Written By: Daniel Dahan
* Date: February 3 / 2010
*
* Title: Global Navigation New Legacy JavaScript File
*/

	/***
	getStyle()
	Description: Utility function. Returns the width of a div element.
	***/
	
	function getStyle(element,styleProp)	{
		if (element.currentStyle)
			var y = element.currentStyle[styleProp];
		else if (window.getComputedStyle)
			var y = document.defaultView.getComputedStyle(element,null).getPropertyValue(styleProp);
		return y;
	}
	

	function switchLangWithSession () {

		var engDelimiter = 'english',
	
		freDelimiter = 'french',
	
		newURL = switchLangSearch(engDelimiter, freDelimiter);
	
		if (newURL != 'null') {
	
			self.location = newURL;
	
			return;
	
		}
	
		engDelimiter = "lang=en";
	
		freDelimeter = "lang=fr";
	
		newURL = switchLangSearch(engDelimiter, freDelimeter);
	
		if (newURL != 'null') {
	
			self.location = newURL;
	
			return;
	
		}
	
		engDelimiter = "_code=en";
	
		freDelimeter = "_code=fr";
	
		newURL = switchLangSearch(engDelimiter, freDelimeter);
	
		if (newURL != 'null') {
	
			self.location = newURL;
	
			return;
	
		}
	
	}

	function switchLangSearch (engDelim, freDelim) {
	
		var docURL = document.URL,
	
		newURL = 'null',
	
		engPosition = 0,
	
		frePosition = 0,
	
		charStart = 0,
	
		charEnd = docURL.length + 1,
	
		engDelimiter = engDelim,
	
		freDelimiter = freDelim;
	
		do {
	
			var test = docURL.substr(charStart, engDelimiter.length);
	
			if (test == engDelimiter) { engPosition = charStart;}
	
			charStart++;
	
		}
	
		while (charStart < charEnd - engDelimiter.length);
	
		if (engPosition > 0) {
	
			newURL = docURL.substr(0,engPosition) + freDelimiter + docURL.substr((engPosition + engDelimiter.length),docURL.length);
	
		} else {
	
			charStart = 0;
	
			do {
	
				var test = docURL.substr(charStart, freDelimiter.length)
	
				if (test == freDelimiter) { frePosition = charStart;}
	
				charStart++;
	
			}
	
			while (charStart < charEnd - freDelimiter.length);
	
			if (frePosition > 0) {
	
				newURL = docURL.substr(0,frePosition) + engDelimiter + docURL.substr((frePosition + freDelimiter.length),docURL.length);
			}
	
		}
	
		return newURL;
	}

	function GlobalNavBarhoverOver ()
	{
		var oEve = window.event, oMenu = oEve.srcElement;
	
		while (oMenu)
		{
			if (oMenu.className == 'GlobalNameMenuListLI')
			{
				oMenu.className = 'GlobalNavBarMenuListOpen';
			}
			
			/**
			* @note		Check the next parentNode.
			*/
			oMenu = oMenu.parentNode;
		}
	}
	
	function GlobalNavBarhoverOut ()
	{
		var oEve = window.event, oMenu = oEve.srcElement;
	
		while (oMenu)
		{
			if (oMenu.className == 'GlobalNavBarMenuListOpen')
			{
				oMenu.className = 'GlobalNameMenuListLI';
			}
			
			/**
			* @note		Check the next parentNode.
			*/
			oMenu = oMenu.parentNode;
		}
	}
	
	
	/***
	GlobalNavBeforeRender()
	Description: This function is called prior to init() to fix any legacy issues in the page structure
	***/

	function GlobalNavBeforeRender()
	{
		var navContainer = document.getElementById('GlobalNavMarker');
		
		// Check width of parent node to the GlobalNavMarker container.
		var navContainerWidth = getStyle(navContainer.parentNode, "width");
		navContainerWidth = Number(navContainerWidth.substr(0, navContainerWidth.length-2));
		
		// If parent node width has not been set, getStyle returns 0 (Safari) or 1 (IE, FF, Chrome). In this case set the parent width to 100%.
		if (navContainerWidth == 0 || navContainerWidth == 1) {
			navContainer.parentNode.style.width = "100%";
		}
		
	}
	
	
	(function () 
	{
	
		/**
			* @note		Determine the language value for the menus. (document.cookie.match('(gmcanada_lang=french)') && document.cookie.match('(gmcanada_lang=french)').length > 0)
			*/
		var sLanguage = window.location.href.indexOf('/english/') != -1 || window.location.href.indexOf('lang=en') != -1 || window.location.href.indexOf('_code=en') != -1 || window.location.href.indexOf('/en/') != -1;
			
			if (sLanguage)
			{
				sLanguage = 'en';	
			}
			else if (window.location.href.indexOf('/french/') != -1 || window.location.href.indexOf('lang=fr') != -1 || window.location.href.indexOf('_code=fr') != -1 || window.location.href.indexOf('/fr/') != -1 || window.location.href.indexOf('=french_pref_search') != -1)
			{
				sLanguage = 'fr';
			}
			else if (document.cookie.match('(gmcanada_lang=french)') && document.cookie.match('(gmcanada_lang=french)').length > 0)
			{
				sLanguage = 'fr';
			}
			else
			{
				sLanguage = 'en';
			}
	
	
		/**
		* * note	Create a single instance of the GlobalNavBar object.
		*/
		var GlobalNavBar = (function ()
		{
			var _ =
			{
				/**
				* @note		Determine the language value for the menus.
				*/
				language: sLanguage,
				
				/**
				* @note		Used for the IE6 fix for drop down menus.
				*/
				currentNode: null,
				
				/**
				* @function		getServerInfoObj
				*/
				getServerInfoObj: function ()
				{
					var sLoc = window.location.href,
						protocal = sLoc.indexOf('https://') != -1 ? 'https://' : 'http://',
						retObj;
						
						/**
						* @note		Possible location, itl, preprod, prodprev, localhost, and www.
						* 			www, is checked first because it is the most critical for performance.
						*/
						if (sLoc.indexOf('www.') != -1)
						{
							retObj =
							{
								mainServer: 'http://www.gm.ca',
								devPath: '',
								xmlGlobalNavDomain: protocal + 'www.gm.ca',
								imgServer : protocal + 'www.gm.ca'
							};
						}
						else if (sLoc.indexOf('itl.preview.') != -1)
						{
							retObj =
							{
								mainServer: 'http://itl.preview.tech.mminteractive.com',
								devPath: 'dev/',
								xmlGlobalNavDomain: protocal + 'itl.preview.tech.mminteractive.com',
								imgServer : protocal + 'itl.preview.tech.mminteractive.com'
							};
						}					
						else if (sLoc.indexOf('itl.') != -1)
						{
							retObj =
							{
								mainServer: 'http://itl.gm.ca',
								devPath: 'dev/',
								xmlGlobalNavDomain: protocal + 'itl.gm.ca',
								imgServer : protocal + 'itl.gm.ca'
							};
						}
						else if (sLoc.indexOf('preprod.preview.') != -1)
						{
							retObj =
							{
								mainServer: 'http://preprod.preview.tech.mminteractive.com',
								devPath: 'dev/',
								xmlGlobalNavDomain: protocal + 'preprod.preview.tech.mminteractive.com',
								imgServer : protocal + 'preprod.preview.tech.mminteractive.com'
							};
						}						
						else if (sLoc.indexOf('preprod.') != -1)
						{
							retObj =
							{
								mainServer: 'http://preprod.gm.ca',
								devPath: 'dev/',
								xmlGlobalNavDomain: protocal + 'preprod.gm.ca',
								imgServer : protocal + 'preprod.gm.ca'
							};
						}					
						else if (sLoc.indexOf('prod.preview.') != -1)
						{
							retObj =
							{
								mainServer: 'http://prod.preview.tech.mminteractive.com',
								devPath: 'dev/',
								xmlGlobalNavDomain: protocal + 'prod.preview.tech.mminteractive.com',
								imgServer : protocal + 'prod.preview.tech.mminteractive.com'
							};
						}
						else if (sLoc.indexOf('localhost') != -1)
						{
							retObj =
							{
								mainServer: 'http://localhost',
								devPath: '',
								xmlGlobalNavDomain: protocal + 'www.gm.ca',
								imgServer : protocal + 'www.gm.ca'
							};
						}
						else
						{
							retObj =
							{
								mainServer: 'http://www.gm.ca',
								devPath: '',
								xmlGlobalNavDomain: protocal + 'www.gm.ca',
								imgServer : protocal + 'www.gm.ca'
							};
						}
						
						/**
						* @idea		concept
						* @note		We are returning an object literal to avoid many variables being passed around.
						*/
						return retObj;
				},
				
				/**
				* @function 		create
				*/
				create: function (oData, sClassColumn, sClassSection, sClassTitle, sClassBlock, bHover)
				{
					/**
					* @note		Ensure the integrity of the initial data array
					*/
					if (typeof oData == 'object')
					{
						for (var i = 0, l = oData.length - 1, oColumn, oFrag = document.createDocumentFragment(); i <= l && (oColumn = oData[i]) && typeof oColumn == 'object'; ++i)
						{
							oFrag.appendChild(_.newColumn(oColumn, sClassColumn, sClassSection, sClassTitle, sClassBlock, bHover, i == l));
						}
						
						return oFrag;
					}
				},
				
				/**
				* @function		newColumn
				*/
				newColumn: function (oColumn, sClassColumn, sClassSection, sClassTitle, sClassBlock, bHover, bLastColumn)
				{
					var sOutput = '', 
						oDiv = document.createElement('div'),
						sValue,
						sLink,
						oInfo = _.getServerInfoObj();
					
					if (typeof oColumn == 'object')
					{
						/**
						* @note		Create the column element.
						*/
						oDiv.className = sClassColumn;
						
						/**
						* @note		Add the hover effect to the menu if it is IE6 and there is a hover notice.
						*/
						var sAgent = navigator.userAgent;
					
						if(sAgent.indexOf('compatible') > -1 && sAgent.indexOf('MSIE') > -1 && !(sAgent.indexOf('Opera') > -1))
						{
							var oReg = new RegExp('MSIE (\\d+\\.\\d+);');
								oReg.test(sAgent);
								oReg = parseFloat(RegExp['$1']);
								sAgent = oReg >= 7 ? 7 : oReg >= 6 ? 6 : 5;
						}
						
						/**
						* @note		Add the IE6 handlers.
						*/
						if (sAgent == 6 && bHover && oDiv.attachEvent)
						{
							oDiv.attachEvent('onmouseover', _.IE6HoverOverFix);
							oDiv.attachEvent('onmouseout', _.IE6hoverOutFix);
						}
						
						/**
						* @note		Check if a title exists for the column, and if so craete it.
						*/
						if (typeof oColumn.title == 'object' && typeof oColumn.title[_.language] == 'object')
						{
							sOutput += '<div ' + (typeof oColumn.title.id == 'string' ? 'id=' + oColumn.title.id : '') + ' class="' + sClassTitle + '">' + (oColumn.title.bLink == true ? oColumn.title.value : '<a ' + (bLastColumn ? 'style="border: none;"' : '') + (typeof oColumn.title[_.language].link === 'string' ? ' href="' + (oColumn.title.bURL == true ? '' : oInfo.mainServer) + oColumn.title[_.language].link + '"' : '') + '>' + oColumn.title[_.language].value + '</a>') + '</div><br />';		
						}
						
						/**
						* @note		Create row blocks for each row. At the end, a separator is added if it is not the first and last block.
						*/
						if (typeof oColumn.rows == 'object')
						{	
							for (var i = 0, l = oColumn.rows.length - 1, oBlock, j, k, oRow; i <= l && (oBlock = oColumn.rows[i]) && typeof oBlock == 'object'; ++i)
							{
								sOutput += '<div class="' + sClassSection + (i != l ? ' ' + sClassBlock : '') + '"><ul>';
								
								/**
								* @note		Create the link;
								*/
								for (j = 0, k = oBlock.length - 1; j <= k && (oRow = oBlock[j]) && typeof oRow == 'object'; ++j)
								{
									
									/**
									* @note		Capture the language object.
									*/
									sValue = oRow[_.language];
								
									/**
									* @note		Default to english if the French value does not exist and is set by the URL.
									*/
									if (typeof sValue == 'object')
									{
										sLink = sValue.link;
										sValue = sValue.value;
									}
									else if (typeof oRow['en'] == 'object')
									{
										sValue = oRow['en'].value;
										sLink = oRow['en'].link;
									}
									else
									{
										sValue = '';
										
										/**
										* @note		Current page (".").
										*/
										sLink = '.';
									}
									
									sOutput += '<li class="GlobalNameMenuListLI ' + (oRow.bHover == true ? 'bHover' : '') + '" ' + (sAgent == 6 ? 'onMouseOver="javascript: GlobalNavBarhoverOver();" onMouseOut="javascript: GlobalNavBarhoverOut();"' : '') + (j == k ? ' style="border: none;"' : '') + '>' + (oRow.bLink == true ? sValue : '<a href="' + (sLink) +'"><div class="GlobalNavBarMenuListItem">' + (sValue) + '</div></a>') + '</li>';	
								}
								
								sOutput += '</ul></div>' + (i != l ? '<br />' : '');
							}
						}
					}
					
					oDiv.innerHTML = sOutput;
					
					return oDiv;
				},
				
				/**
				* @function		IE6HoverOverFix
				*/
				IE6HoverOverFix: function ()
				{
					var oEve = window.event, oTarget = oEve.srcElement, oMenu = oTarget.parentNode;
						
						while (oMenu)
						{
							if (oMenu.className == 'MenuList')
							{
								if (oMenu.firstChild && oMenu.firstChild.nextSibling && oMenu.firstChild.nextSibling.nextSibling && oMenu.firstChild.nextSibling.nextSibling.className)
								{
									oMenu = oMenu.firstChild.nextSibling.nextSibling;
									
									oMenu = oMenu.style;
														
									oMenu.width = '0';
									oMenu.display = 'block';
									oMenu.visibility = 'visible';
									
									var x = document.getElementsByTagName("select");
									for (i = 0; i < x.length; i++) {
									   x[i].style.visibility = 'hidden';
									}
									
									/**
									* @note		Set the currentNode property so the IE6hoverOutFix function can hide the element that was just displayed.
									*/
									_.currentNode = oMenu;
								}
								
								break;
							}
							
							/**
							* @note		Check the next parentNode.
							*/
							oMenu = oMenu.parentNode;
						}
						
						oEve.cancelBubble = true;
						oEve.returnValue = false;
				},
				
				/**
				* @function		IE6hoverOutFix
				*/
				IE6hoverOutFix: function ()
				{
					if (_.currentNode)
					{
						_.currentNode.display = 'none';
						_.currentNode.visibility = 'hidden';
						_.currentNode = null;
						var x = document.getElementsByTagName("select");
						for (i = 0; i < x.length; i++) {
						   x[i].style.visibility = 'visible';
						}
					}
				}
			};
			
			/**
			* @note 	return the object literal.
			*/
			return _;
			
		}) (),
	
		/**
		* @note		Site map menu data.
		*/
		GlobalMenuDataLeft =
		[
			{
				title: {bURL: true, en: {value: 'Vehicles', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles'}, fr: {value: 'V&eacute;hicules', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles'}},
				rows:
				[
					[
						{en: {value: 'Buick', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles/buick/'}, fr: {value: 'Buick', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles/buick/'}},
						{en: {value: 'Cadillac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles/cadillac/'}, fr: {value: 'Cadillac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles/cadillac/'}},
						{en: {value: 'Chevrolet', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles/chevrolet/'}, fr: {value: 'Chevrolet', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles/chevrolet/'}},
						{en: {value: 'GMC', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles/gmc/'}, fr: {value: 'GMC', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles/gmc/'}},
						{en: {value: 'Hummer', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles/hummer/'}, fr: {value: 'Hummer', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles/hummer/'}},
						{en: {value: 'Pontiac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles/pontiac/'}, fr: {value: 'Pontiac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles/pontiac/'}},	
						{bLink: true, bHover: true, en: {value: '', link: ''}, fr: {value: '', link: ''}},
						{en: {value: 'New Vehicles', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/showrooms/?adv=72465'}, fr: {value: 'V&eacute;hicules Neufs', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/showrooms/?adv=72465'}},
						{en: {value: 'Certified Used Vehicles', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/UsedVehicleLocatorCriteria.do&lang=en&nav=040&adv=IOPTENH001&page=qsearch#ddType~dv~refresh~year~1111~make~'}, fr: {value: 'V&eacute;hicules d\'occasion', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/UsedVehicleLocatorCriteria.do&lang=fr&nav=040&adv=IOPTENH001&page=qsearch#ddType~dv~refresh~year~1111~make~'}},
						{en: {value: 'Fleet', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/fleet/overview'}, fr: {value: 'Parcs', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/fleet/overview'}},
						{en: {value: 'OnStar', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/shopping/accessories/onstar'}, fr: {value: 'OnStar', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/shopping/accessories/onstar'}},
						{en: {value: 'Commercial Trucks', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/vehicles/commercial/index'}, fr: {value: 'V&eacute;hicules commerciaux', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/vehicles/commercial/index'}}
					]
				]
			},
			
			{
				title: {bURL: true, en: {value: 'Shopping Tools', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/tools'}, fr: {value: 'Outils d\'achat', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/tools'}},
				rows:
				[
					[	
						{bURL: true, en: {value: 'New Vehicle Offers', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/offersearch/OfferSearch.do&lang=en'}, fr: {value: 'Offre de v&eacute;hicules neufs', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/offersearch/OfferSearch.do&lang=fr'}},
						{bURL: true, en: {value: 'Build &amp; Price', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://configurator.autodata.gm.ca/GMCanada/modelSelect.html&lang=en&access=0&lastsavedconfig='}, fr: {value: 'Fabriquer et obtenir un prix', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://configurator.autodata.gm.ca/GMCanada/modelSelect.html&lang=fr&access=0&lastsavedconfig='}},
						{en: {value: 'Estimate Payments', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/payment-estimator/selectMakeModel'}, fr: {value: 'Estimer les paiements', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/payment-estimator/selectMakeModel'}},
						{bURL: true, en: {value: 'Compare Vehicles', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://compare.autodata.gm.ca/compare/main.asp&lang=en&year=2010'}, fr: {value: 'Comparaison de v&eacute;hicules', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://compare.autodata.gm.ca/compare/main.asp&lang=fr&year=2010'}},
						{bURL: true, en: {value: 'Locate a Vehicle', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/NewVehicleLocatorCriteria.do&lang=en&nav=0&cta=blank&search_year=2010'}, fr: {value: 'Trouvez un v&eacute;hicules', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/NewVehicleLocatorCriteria.do&lang=fr&nav=0&cta=blank&search_year=2010'}},
						{bURL: true, en: {value: 'Locate a Dealer', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/DealerLocatorSearch.do&nav=0&cta=blank&lang=en'}, fr: {value: 'Trouvez un concessionnaire', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/DealerLocatorSearch.do&nav=0&cta=blank&lang=fr'}},
						{bURL: true, en: {value: 'Schedule a Test Drive', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=https://apps.gm.ca/app/GMCanada/RequestAQuote.do&lang=en&raqSource=scheduleTestDrive&scheduleSubSource=new&year=2010#ddType~dv~year~2010'}, fr: {value: 'Rendez-vous pour un essai routier', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=https://apps.gm.ca/app/GMCanada/RequestAQuote.do&lang=fr&raqSource=scheduleTestDrive&scheduleSubSource=new&year=2010#ddType~dv~year~2010'}},
						{bURL: true, en: {value: 'Request a Quote', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=https://apps.gm.ca/app/GMCanada/RequestAQuote.do&lang=en&raqSource=new&year=2010#ddType~dv~year~2010'}, fr: {value: 'Demande de soumission', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=https://apps.gm.ca/app/GMCanada/RequestAQuote.do&lang=fr&raqSource=new&year=2010#ddType~dv~year~2010'}},
						{en: {value: 'Appraise Trade-In Value', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/gmac/appraise-trade-in'}, fr: {value: '&Eacute;valuez votre v&eacute;hicule', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/gmac/appraise-trade-in'}},
						{bLink: true, bHover: true, en: {value: '', link: ''}, fr: {value: '', link: ''}},
						{en: {value: 'First New Car', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/shopping/first-new-car/overview'}, fr: {value: 'Premi&egrave;re voiture neuve', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/shopping/first-new-car/overview'}},
						{en: {value: 'Trailering Guide', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/trailering-guide/all-vehicles/home/overview'}, fr: {value: 'Guide sur le remorquage', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/trailering-guide/all-vehicles/home/overview'}},
						{en: {value: 'Financing &amp; Insurance', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/gmac/overview'}, fr: {value: 'Financement', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/gmac/overview'}}
					]
				]
			},
			
			{
				title: {bURL: true, en: {value: 'Offers and Promotions', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/offersearch/OfferSearch.do&lang=en'}, fr: {value: 'Offres et promotions', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/offersearch/OfferSearch.do&lang=fr'}},
				rows:
				[
					[
						{bURL: true, en: {value: 'New Vehicle Offers', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/offersearch/OfferSearch.do&lang=en'}, fr: {value: 'Offre de v&eacute;hicules neufs', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/offersearch/OfferSearch.do&lang=fr'}},
						{en: {value: 'Goodwrench Offers', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/goodwrench/offers'}, fr: {value: 'Offres Goodwrench', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/goodwrench/offers'}},
						{en: {value: 'Student Bonus', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/corporate/offers/student-bonus-program/overview'}, fr: {value: 'Prime GM pour &eacute;tudiants', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/corporate/offers/student-bonus-program/overview'}},
						{en: {value: 'GM Card', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/gm-card/overview'}, fr: {value: 'La Carte GM', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/gm-card/overview'}}
					]
				]
			},
			
			{
				title: {bURL: true, en: {value: ' For Owners', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/owners/home'}, fr: {value: 'Propri&eacute;taires', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/owners/home'}},
				rows:
				[
					[
						{en: {value: 'Buick', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/motion/buick/home/overview'}, fr: {value: 'Buick', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/motion/buick/home/overview'}},
						{en: {value: 'Cadillac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/motion/cadillac/home/overview'}, fr: {value: 'Cadillac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/motion/cadillac/home/overview'}},
						{en: {value: 'Chevrolet', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/motion/chevrolet/home/overview'}, fr: {value: 'Chevrolet', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/motion/chevrolet/home/overview'}},
						{en: {value: 'GMC', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/motion/gmc/home/overview'}, fr: {value: 'GMC', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/motion/gmc/home/overview'}},
						{en: {value: 'HUMMER', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/owner_centre/corporate/home/overview'}, fr: {value: 'HUMMER', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/owner_centre/corporate/home/overview'}},
						{en: {value: 'Pontiac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/owner_centre/corporate/home/overview'}, fr: {value: 'Pontiac', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/owner_centre/corporate/home/overview'}},
						{en: {value: 'Saab', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/owner_centre/corporate/home/overview'}, fr: {value: 'Saab', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/owner_centre/corporate/home/overview'}},
						{en: {value: 'Saturn', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/owner_centre/corporate/home/overview'}, fr: {value: 'Saturn', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/owner_centre/corporate/home/overview'}},
						{en: {value: 'Other', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/owner_centre/corporate/home/overview'}, fr: {value: 'Autres', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/owner_centre/corporate/home/overview'}},
						{bLink: true, bHover: true, en: {value: '', link: ''}, fr: {value: '', link: ''}},
						{en: {value: 'Goodwrench Service', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/goodwrench/overview'}, fr: {value: 'Service Goodwrench', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/goodwrench/overview'}},
						{en: {value: 'Financing and Insurance', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/gmac/overview'}, fr: {value: 'Financement', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/gmac/overview'}},
						{en: {value: 'Warranty', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/warranty/overview'}, fr: {value: 'Garanties et protection', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/warranty/overview'}},
						{en: {value: 'Parts', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/shopping/parts/overview'}, fr: {value: 'Pi&egrave;ces', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/shopping/parts/overview'}},
						{en: {value: 'Accessories', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/shopping/accessories/overview'}, fr: {value: 'Accessoires', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/shopping/accessories/overview'}},
						{en: {value: 'OnStar', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/shopping/accessories/onstar'}, fr: {value: 'OnStar', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/shopping/accessories/onstar'}},
						{en: {value: 'XM Radio', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/shopping/xm-radio/overview'}, fr: {value: 'Radio XM', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/shopping/xm-radio/overview'}},
						{en: {value: 'Appraise Trade-In Value', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/services/gmac/appraise-trade-in'}, fr: {value: '&Eacute;valuez votre v&eacute;hicule', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/services/gmac/appraise-trade-in'}}
						
					]
				]
			},
			
			{
				title: {bURL: true, en: {value: 'Dealers', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/DealerLocatorSearch.do&nav=0&cta=blank&lang=en'}, fr: {value: 'Concessionnaires', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/DealerLocatorSearch.do&nav=0&cta=blank&lang=fr'}},
				rows:
				[
					[
						{bURL: true, en: {value: 'Locate a Dealer', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=http://apps.gm.ca/app/GMCanada/DealerLocatorSearch.do&nav=0&cta=blank&lang=en'}, fr: {value: 'Trouvez un concessionnaire', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=http://apps.gm.ca/app/GMCanada/DealerLocatorSearch.do&nav=0&cta=blank&lang=fr'}}
					]
				]
			},
			
			{
				title: {bURL: true, en: {value: 'About Us', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/about'}, fr: {value: '&Agrave; notre sujet', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/about'}},
				rows:
				[
					[
						{en: {value: 'Our Company', link: GlobalNavBar.getServerInfoObj().mainServer+'/inm/gmcanada/english/about/index.html'}, fr: {value: 'Aper&ccedil;u de la soci&eacute;t&eacute;', link: GlobalNavBar.getServerInfoObj().mainServer+'/inm/gmcanada/french/about/index.html'}},
						{en: {value: 'News and Events', link: GlobalNavBar.getServerInfoObj().mainServer+'/inm/gmcanada/english/about/News/news.html'}, fr: {value: 'Nouvelles et &eacute;v&eacute;nements', link: GlobalNavBar.getServerInfoObj().mainServer+'/inm/gmcanada/french/about/News/news.html'}},
						{en: {value: 'The Olympic Games', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/corporate/olympics/overview'}, fr: {value: 'Les Jeux olympiques', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/corporate/olympics/overview'}},
						{en: {value: 'Career Centre', link: GlobalNavBar.getServerInfoObj().mainServer+'/inm/gmcanada/english/about/Careers/careers.html'}, fr: {value: 'Centre des carri&egrave;res', link: GlobalNavBar.getServerInfoObj().mainServer+'/inm/gmcanada/french/about/Careers/careers.html'}},
						{bURL: true, en: {value: 'Contact Us', link: 'https://contactus.gm.ca/english/email_us.aspx'}, fr: {value: 'Renseignements', link: 'https://contactus.gm.ca/french/email_us.aspx'}}
					]
				]
			}
		],
		
		/**
		* @note		Drop down menu data.
		*/
		GlobalMenuDataRight =
		[
			{
				title: {bURL: true, en: {value: 'GM Home', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/home'}, fr: {value: 'Accueil GM', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/home'}}
			},
			
			{
				title: {bURL: true, en: {value: 'My GM.ca', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=https://apps.gm.ca/app/mygm/Logon.do&lang=en'}, fr: {value: 'Mon GM.ca', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=https://apps.gm.ca/app/mygm/Logon.do&lang=fr'}},
				rows:
				[
					[
						{bURL: true, en: {value: 'My Showroom', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=https://apps.gm.ca/app/mygm/MyShowroom.do&lang=en&cta=myshowroom'}, fr: {value: 'Ma salle d\'exposition', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=https://apps.gm.ca/app/mygm/MyShowroom.do&lang=fr&cta=myshowroom'}},
						{bURL: true, en: {value: 'My Dealers', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=https://apps.gm.ca/app/mygm/MyDealers.do&lang=en&cta=mydealers&ComponentName=buycentre'}, fr: {value: 'Mes concessionnaires', link:GlobalNavBar.getServerInfoObj().mainServer+ '/gm/french/hostredirect?host=https://apps.gm.ca/app/mygm/MyDealers.do&lang=fr&cta=mydealers&ComponentName=buycentre'}},
						{bURL: true, en: {value: 'My Driveway', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=https://apps.gm.ca/app/mygm/MyDriveway.do&nav=mygm&lang=en'}, fr: {value: 'Mon garage', link:GlobalNavBar.getServerInfoObj().mainServer+ '/gm/french/hostredirect?host=https://apps.gm.ca/app/mygm/MyDriveway.do&nav=mygm&lang=fr'}},
						{bURL: true, en: {value: 'My Preferences', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/hostredirect?host=https://apps.gm.ca/app/mygm/ManageProfile.do&lang=en'}, fr: {value: 'Mes pr&eacute;f&eacute;rences', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/hostredirect?host=https://apps.gm.ca/app/mygm/ManageProfile.do&lang=fr'}}
					]
				]
			}
			/**
			,{
				title: {en: {value: 'Help', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/corporate/help/overview'}, fr: {value: 'Aide', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/corporate/help/overview'}},
				rows:
				[
					[
						{en: {value: 'Search', link: GlobalNavBar.getServerInfoObj().mainServer+'/servlet/advsearch?client=english_pref_search&proxystylesheet=english_pref_search&output=xml_no_dtd&site=english_pref_search&proxycustom=%3CHOME/%3E'}, fr: {value: 'Recherche', link: GlobalNavBar.getServerInfoObj().mainServer+'/servlet/advsearch?client=french_pref_search&proxystylesheet=french_pref_search&output=xml_no_dtd&site=french_pref_search&proxycustom=%3CHOME/%3E'}},
						{en: {value: 'FAQ', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/corporate/help/faq'}, fr: {value: 'FAQ', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/corporate/help/faq'}},
						{en: {value: 'Privacy Policy', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/corporate/help/privacy/overview'}, fr: {value: 'Vie Priv&eacute;e', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/corporate/help/privacy/overview'}},
						{en: {value: 'Legal', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/english/corporate/help/legal'}, fr: {value: 'Juridique', link: GlobalNavBar.getServerInfoObj().mainServer+'/gm/french/corporate/help/legal'}}
					]
				]
			},
			
			{
				title: {id: 'nav_lang', bURL: true, en: {value: 'Fran&#231;ais', link: GlobalNavBar.getServerInfoObj().mainServer+'javascript:switchLangWithSession();'}, fr: {bURL: true, value: 'English', link: GlobalNavBar.getServerInfoObj().mainServer+'javascript:switchLangWithSession();'}}
			}
			*/
		],
		
		
		/**
		* * note	Create a single instance of the GlobalNavBarCSS object.
		*/
		GlobalNavBarCSS = (function ()
		{
			var globalNavWidth = '100%';
			if (window.location.href.indexOf('ca/inm/') != -1){
				globalNavWidth = '990px';
			}
			
			var oStyle = document.createElement('style'),
				sCSS = '#GlobalNav, #GlobalNavMarker {position: relative; width: ' + globalNavWidth + '; height: 32px;z-index: 100000;}\
						#GlobalNavBar {position: absolute; top: 0; left: 0; width:  ' + globalNavWidth + '; z-index: 100000; background: #fff;}\
						#GlobalNavBar a {font-size: 11px; text-decoration: none;}\
						#GlobalNavBar a:hover {text-decoration: underline;}\
						#GlobalNavBar ul {padding: 0 0; margin: 0 0; list-style: none; text-align: left;}\
						#GlobalNavBar ul li {height: 16px; line-height: 16px; white-space: nowrap;}\
						#GlobalNavBar .GlobalNavBarMenuContainer {float: left; position: relative; width: 100%; height: 34px;}\
						#GlobalNavBarMenuListLeft, .MenuList, .MenuListName {float: left; position: relative;}\
						#GlobalNavBarMenuListRight {float: right; position: relative;}\
						#GlobalNavBarMenuListRight .MenuListItems {right: 0;}\
						#GlobalNavBarMenuListLeft .MenuListItems {left: 0;}\
						#GlobalNavBar .MenuListName {height: 32px; line-height: 32px; cursor: pointer; background: #fff;}\
						#GlobalNavBar .MenuListName a {padding: 0 8px; font-weight: bold; color: #000; white-space: nowrap; outline: none; border-right: 1px solid #000;}\
						#GlobalNavBar .MenuList:hover .MenuListName a {color: #777;}\
						#GlobalNavBar .MenuListItems {position: absolute; top: 32px; display: none; visibility: hidden; background: #fff; border: 1px solid #ccc; border-top: none; -moz-border-radius: 3px; -webkit-border-radius: 3px;}\
						#GlobalNavBar .MenuList:hover .MenuListItems {display: block; visibility: visible;}\
						#GlobalNavBar .MenuListItems ul {background: #fff; }\
						#GlobalNavBar .MenuListItems ul li {_width: 175px; height: 18px; border-bottom: 1px dashed #ccc; cursor: pointer;}\
						#GlobalNavBar .MenuListItems ul li:hover {background: #777;}\
						#GlobalNavBar .MenuListItems ul li.GlobalNavBarMenuListOpen {background: #777;}\
						#GlobalNavBar .MenuListItems ul li.bHover {background: #fff;}\
						#GlobalNavBar .MenuListItems ul li.GlobalNavBarMenuListOpen a {color: #fff; text-decoration: none;}\
						#GlobalNavBar .MenuListItems ul li a {height: 18px; line-height: 18px; outline: none; color: #000; text-decoration: none; cursor: pointer; }\
						#GlobalNavBar .MenuListItems ul li:hover a, .MenuListItems ul li:hover .GlobalNavBarMenuListItem {color: #fff; text-decoration: none;}\
						#GlobalNavBar .GlobalNavBarMenuListItem {position: relative; width: 100%; padding-left: 10px; height: 18px; line-height: 18px; padding-right: 25px;}';
						
				oStyle.type = 'text/css';
	
				if(oStyle.styleSheet)
				{
					oStyle.styleSheet.cssText = sCSS;
				}
				else
				{
					oStyle.appendChild(document.createTextNode(sCSS));
				}
				
				document.getElementsByTagName('head')[0].appendChild(oStyle);
				
				return oStyle;
		}) (),
		
		
		/**
		* * note	Create a single instance of the GlobalNavBarHTML object.
		*/
		GlobalNavBarHTML = (function ()
		{
			var sHTML = '<div id="GlobalNavBar">\
							<div class="GlobalNavBarMenuContainer">\
								<div id="GlobalNavBarMenuListLeft"></div>\
								<div id="GlobalNavBarMenuListRight"></div>\
							</div>\
						</div>';
				
				return sHTML;
		}) ();
		
		
		/**
		* @note		Set a marker, to determine if the script is placed in the header to avoid writing the GlobalNavMarker.
		*/
		document.write('<script type="text/javascript" id="GlobalNavScriptMarker"><\/script>');
		
		var oScript = document.getElementById('GlobalNavScriptMarker');
		
		if (oScript.parentNode != document.getElementsByTagName('head')[0])
		{
			document.write('<div id=\"GlobalNavMarker\" style=\"display:none;visibility:hidden;\"><\/div>');
		}
		
		/**
		* @function		init
		* @usage		Builds the Global Nav menu.
		*/
		function init ()
		{
			var oGlobal = document.getElementById('GlobalNav');
				
				/**
				* @note We are in an inline scenario
				*/
				if (!oGlobal)
				{
					var oDiv1 = document.getElementById('GlobalNavMarker');
					
						oGlobal = document.createElement('div');
						oGlobal.id = 'GlobalNav';
						
						if (oDiv1)
						{
							oDiv1.appendChild(oGlobal);
							oDiv1.style.display = 'block';
							oDiv1.style.visibility = 'visible';
						}
				}
				
				if (document.getElementById('GlobalNav'))
				{
					/***
					@note Prior to rendering GlobalNav, fix any problems in the page body structure
					***/
					GlobalNavBeforeRender();
					
					/**
					* @note If here before the if statement is executed, then the element GlobalNav was placed.
					*/
					oGlobal.innerHTML = GlobalNavBarHTML;
						
					/**
					* @note		Build the menus.
					*/
					var oMenu1 = document.getElementById('GlobalNavBarMenuListLeft');
					
					if (typeof oMenu1 == 'object')
					{
						oMenu1.appendChild(GlobalNavBar.create(GlobalMenuDataLeft, 'MenuList', 'MenuListItems', 'MenuListName', '', true));
					}
					
					var oMenu2 = document.getElementById('GlobalNavBarMenuListRight');
					
					if (typeof oMenu2 == 'object')
					{
						oMenu2.appendChild(GlobalNavBar.create(GlobalMenuDataRight, 'MenuList', 'MenuListItems', 'MenuListName', '', true));
					}
				}
		}
		
		
		/**
		* @note		DOM Ready handler.
		*/
		var alreadyrunflag = 0 //flag to indicate whether target function has already been run
		
		if (document.addEventListener)
		{
			document.addEventListener("DOMContentLoaded", function()
			{
				alreadyrunflag = 1;
				init();
			}, false)
		}
		else if (document.all && !window.opera)
		{
			var sSRC ="javascript:void(0)";
			var sAgent = navigator.userAgent;
			if(sAgent.indexOf('MSIE') > -1)
			{
				sSRC = (location.protocol == "https:") ? "//:" : "javascript:void(0)";
			}
			document.write('<script type="text/javascript" id="GlobalNavContentLoadTag" defer="defer" src="'+sSRC+'"><\/script>')
			var contentloadtag=document.getElementById('GlobalNavContentLoadTag')
			
				contentloadtag.onreadystatechange=function()
				{
					if (this.readyState == 'complete')
					{
							alreadyrunflag = 1
							init();
					}
				}
		}
		
		/**
		* @note		Souble check on the nav bar being set.
		*/
		setTimeout(function ()
		{
			if (!alreadyrunflag)
			{
				init();
			}
		}, 2000);
	
	}) ();