// Need to change absolute links to point to correct server on different environments
// Normal (relative):	itl.gm.ca 							preprod.gm.ca						gm.ca
// Apps (absolute)	:	apps.itl.gm.ca	apps.itl.gm.ca	apps.gm.ca
// absolute.js will differ than normal js, since the preprod servers don't have any common strings
var mainServer;
var mainSecureServer;
var devPath = ''; // path for Contact Us
var thisLoc = location.toString();
var configDomain = '';
if (thisLoc.indexOf('itl.') != -1) { // we are on ITL
	mainServer = 'http://apps.itl.gm.ca';
	mainSecureServer = 'https://apps.itl.gm.ca';
	devPath = 'dev/';						// "Contact Us" link changes on development servers
	configDomain = 'http%3A%2F%2Fconfigurator%2Eautodata%2Epreprod%2Egm%2Eca';	
	PEDomain = 'http://paymentestimator.autodata.preprod.gm.ca';	
} else if (thisLoc.indexOf('preprod.') != -1) { // we are on PREPROD
	mainServer = 'http://apps.preprod.gm.ca';
	mainSecureServer = 'https://apps.preprod.gm.ca';
	devPath = 'dev/';						// "Contact Us" link changes on development servers
	configDomain = 'http%3A%2F%2Fconfigurator%2Eautodata%2Epreprod%2Egm%2Eca';	
	PEDomain = 'http://paymentestimator.autodata.preprod.gm.ca';		
} else if (thisLoc.indexOf('localhost') != -1) { // we are on LOCALHOST
	mainServer = 'http://apps.preprod.gm.ca';
	mainSecureServer = 'https://apps.itl.gm.ca';
	devPath = 'dev/';	
	configDomain = 'http%3A%2F%2Fconfigurator%2Eautodata%2Epreprod%2Egm%2Eca';	
	PEDomain = 'http://paymentestimator.autodata.preprod.gm.ca';		
} else { // default to LIVE
	mainServer = 'http://apps.gm.ca';
	mainSecureServer = 'https://apps.gm.ca';
	configDomain = 'http%3A%2F%2Fconfigurator%2Eautodata%2Egm%2Eca';		
	PEDomain = 'http://paymentestimator.autodata.gm.ca';	
}
//alert('testing: \nmainServer: '+mainServer+'\nthisLoc: '+thisLoc);

var linkTarget = '_top';
// TO UPDATE A DROP DOWN MENU, ADD ITEM TO APPROPRIATE ARRAY IN DESIRED POSITION
//*******************
// TOP NAV BAR ARRAY
//*******************
// makeObjArray is (href value, display text)
var navArray = new Array(8);
initNavArray();
function initNavArray() {
  navArray[0] = new makeObjArray("/gm/english/home","GM Canada Home");
  //Google Appliance URL will need to be updated for launch
  navArray[1] = new makeObjArray("/gm/english/vehicles","Vehicles");
  navArray[2] = new makeObjArray("/gm/english/tools","Shopping Tools");
  navArray[3] = new makeObjArray("/gm/english/finance","Finance");  
  navArray[4] = new makeObjArray("/gm/english/maintenance","Parts &#x26; Services");  
  navArray[5] = new makeObjArray("/gm/english/about","About Us");  
  navArray[6] = new makeObjArray(mainServer + "/app/GMCanada/DealerLocatorSearch.do?nav=0&cta=blank&lang=en","Dealers");
  navArray[7] = new makeObjArray("/gm/english/owners/gm-owners/overview","Owners");   
  }
// objectify the navArray  
function makeObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 }
 
//*************************
// GM CANADA HOME SUB MENU ARRAY
//*************************
var homeNavArray = new Array(6);
inithomeNavArray();
function inithomeNavArray() {
  homeNavArray[0] = new makeHomeObjArray("/gm/english/vehicles/buick/","Buick");
  homeNavArray[1] = new makeHomeObjArray("/gm/english/vehicles/cadillac/","Cadillac");
  homeNavArray[2] = new makeHomeObjArray("/gm/english/vehicles/chevrolet/","Chevrolet");
  homeNavArray[3] = new makeHomeObjArray("/gm/english/vehicles/gmc/","GMC");  
  homeNavArray[4] = new makeHomeObjArray("/gm/english/vehicles/hummer/","HUMMER");  
  homeNavArray[5] = new makeHomeObjArray("/gm/english/vehicles/pontiac/","Pontiac");  
  } 
function makeHomeObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 
 
 
//*************************
// VEHICLES SUB MENU ARRAY
//*************************
var vehNavArray = new Array(10);
initVehNavArray();
function initVehNavArray() {
  vehNavArray[0] = new makeVehObjArray("/gm/english/showrooms/?adv=72465","Vehicle Showroom");
  vehNavArray[1] = new makeVehObjArray("/gm/english/showrooms/cars?adv=72467","Cars");
  vehNavArray[2] = new makeVehObjArray("/gm/english/showrooms/vans?adv=72469","Vans");
  vehNavArray[3] = new makeVehObjArray("/gm/english/showrooms/suv?adv=72471","Crossover/SUVs");
  vehNavArray[4] = new makeVehObjArray("/gm/english/showrooms/trucks?adv=72473","Trucks");  
  vehNavArray[5] = new makeVehObjArray("/gm/english/vehicles/commercial/index","Commercial Trucks");  
  vehNavArray[6] = new makeVehObjArray("/gm/english/shopping/first-new-car/overview","First New Car");
  vehNavArray[7] = new makeVehObjArray("/gm/english/trailering-guide/all-vehicles/home/overview","Trailering Guide");   
  vehNavArray[8] = new makeVehObjArray("/gm/english/shopping/used/overview","Used Vehicles");  
  vehNavArray[9] = new makeVehObjArray("/gm/english/services/fleet/overview","Fleet");    
  } 
function makeVehObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 

//*******************************
// SHOPPING TOOLS SUB MENU ARRAY
//*******************************
//Sirine - Added Current Offers
var shopNavArray = new Array();
initShopNavArray();
function initShopNavArray() {
  shopNavArray[0] = new makeShopObjArray(mainServer+"/app/GMCanada/offersearch/OfferSearch.do?lang=en","Current Offers");
  shopNavArray[1] = new makeShopObjArray(mainServer+"/app/mygm/GetUserInfo.do?request=access,lastsavedconfig&amp;goto=" + configDomain + "%2FGMCanada%2FmodelSelect%2Ehtml%3Flang%3Den","Build &#38; Price");
  shopNavArray[2] = new makeShopObjArray("/gm/english/payment-estimator/selectMakeModel","Estimate Payments");
  shopNavArray[3] = new makeShopObjArray("/gm/english/hostredirect?host=http://gmcanada.autodatadirect.com/compare/main.asp&amp;lang=en&amp;year=2010","Compare Vehicles");
  shopNavArray[4] = new makeShopObjArray(mainServer+"/app/GMCanada/NewVehicleLocatorCriteria.do?lang=en&nav=0&cta=blank","Locate a Vehicle");  
  shopNavArray[5] = new makeShopObjArray(mainServer+"/app/GMCanada/DealerLocatorSearch.do?nav=0&cta=blank&lang=en","Locate a Dealer");
  shopNavArray[6] = new makeShopObjArray("/gm/english/hostredirect?host=https://apps.gm.ca/app/GMCanada/RequestAQuote.do&amp;lang=en&raqSource=scheduleTestDrive&scheduleSubSource=new&year=2010","Schedule a Test Drive");
  shopNavArray[7] = new makeShopObjArray("/gm/english/hostredirect?host=https://apps.gm.ca/app/GMCanada/RequestAQuote.do&amp;lang=en&raqSource=new&year=2010","Request a Quote");
  shopNavArray[8] = new makeShopObjArray("/gm/english/services/insurance/quote","Insurance Quote");
  //shopNavArray[8] = new makeShopObjArray("/gm/english/services/gmac/apply","Credit Application");
  }
function makeShopObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 
 
 

//************************
// FINANCE SUB MENU ARRAY
//************************
var finNavArray = new Array(4);
initFinNavArray();

function initFinNavArray() {
	//Sirine July 18/06 - Payment Estimator link, goes to Autodata carrying a list of parameters
	try  {
		var returnToName=escape(sectionDisplayTitle);
	}
	catch(err) {
		var returnToName = "Previous%20Page";
	}

	var estimatorLink= PEDomain + "/GMCanadaPaymentEstimator/paymentEstimatorContainer.html?lang=en&model=&package=&brand=&year=&returnToName="+returnToName+"&returnToURL="+escape(document.location.href);

  finNavArray[0] = new makeFinObjArray("/gm/english/services/gmac/overview","Financing");
  //finNavArray[1] = new makeFinObjArray("/gm/english/services/gmac/apply","Credit Application"); 
  //finNavArray[1] = new makeFinObjArray("/gm/english/services/gmac/commercial/credit-line","Commercial Credit Line");  
  finNavArray[1] = new makeFinObjArray("/gm/english/services/gmac/appraise-trade-in","Appraise Trade-In Value");
  finNavArray[2] = new makeFinObjArray("/gm/english/services/gm-card/overview","GM Card"); 
  finNavArray[3] = new makeFinObjArray("/gm/english/services/insurance/quote","Insurance");    
}

function makeFinObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 
//**********************************
// PARTS AND SERVICE SUB MENU ARRAY
//**********************************
var partNavArray = new Array(6);
initPartNavArray();
function initPartNavArray() {
  partNavArray[0] = new makePartObjArray("/gm/english/services/vehicle-service/overview","Vehicle Service");
  partNavArray[1] = new makePartObjArray("/gm/english/services/warranty/overview","Warranty &#38; Protection");
  partNavArray[2] = new makePartObjArray("/gm/english/shopping/parts/overview","Parts");
  partNavArray[3] = new makePartObjArray("/gm/english/shopping/accessories/overview","Accessories");  
  partNavArray[4] = new makePartObjArray("/gm/english/shopping/accessories/onstar","OnStar");
  partNavArray[5] = new makePartObjArray("/gm/english/shopping/xm-radio/overview","XM Radio");  
  }
function makePartObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 
 
//*********************
// ABOUT SUB MENU ARRAY
//*********************
var aboutNavArray = new Array(5);
initAboutNavArray();
function initAboutNavArray() {
  aboutNavArray[0] = new makeAboutObjArray("/inm/gmcanada/english/about/index.html","Our Company");
  //aboutNavArray[1] = new makeAboutObjArray("/gm/english/corporate/reinvention/overview","Our Mission");
  aboutNavArray[1] = new makeAboutObjArray("/inm/gmcanada/english/about/News/news.html","News and Events");
  aboutNavArray[2] = new makeAboutObjArray("/gm/english/corporate/olympics/overview","The Olympic Games");
  //aboutNavArray[4] = new makeAboutObjArray("/gm/english/corporate/green-by-design/overview","Green By Design");
  aboutNavArray[3] = new makeAboutObjArray("/inm/gmcanada/english/about/Careers/careers.html","Career Centre");  
  aboutNavArray[4] = new makeAboutObjArray("https://contactus.gm.ca/"+devPath+"english/email_us.aspx","Contact Us");
  }
function makeAboutObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 
 
 
//*********************
// MY GM SUB MENU ARRAY
//*********************
//First, the 2 main link labels
var myNavArray = new Array(2);
initMyNavArray();
function initMyNavArray() {
  myNavArray[0] = new makeMyObjArray(mainSecureServer+"/app/mygm/Logon.do?lang=en","My GM Canada");
  //Google Appliance URL will need to be updated for launch
  myNavArray[1] = new makeMyObjArray("/gm/english/corporate/help/overview","Help"); 
  }
// objectify the navArray  
function makeMyObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 }
  
 
// Second, the subNav for MyGM
var myGmSubNavArray = new Array(4);
initMyGmSubNavArray();
function initMyGmSubNavArray() {
  myGmSubNavArray[0] = new makeMyGmSubNavObjArray(mainSecureServer+"/app/mygm/MyShowroom.do?lang=en&cta=myshowroom","My Showroom");
  myGmSubNavArray[1] = new makeMyGmSubNavObjArray(mainSecureServer+"/app/mygm/MyDealers.do?lang=en&cta=mydealers&ComponentName=buycentre","My Dealers");
  myGmSubNavArray[2] = new makeMyGmSubNavObjArray(mainSecureServer+"/app/mygm/MyDriveway.do?nav=mygm&lang=en","My Driveway");
  myGmSubNavArray[3] = new makeMyGmSubNavObjArray(mainSecureServer+"/app/mygm/ManageProfile.do?lang=en","My Preferences");
  }
function makeMyGmSubNavObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 

//SIRINE - Added Help links 
var HelpSubNavArray = new Array(4);
initHelpSubNavArray();
function initHelpSubNavArray() {
  HelpSubNavArray[0] = new makeMyGmSubNavObjArray("/servlet/advsearch?client=english_pref_search&proxystylesheet=english_pref_search&output=xml_no_dtd&site=english_pref_search&proxycustom=%3CHOME/%3E","Search");
  HelpSubNavArray[1] = new makeMyGmSubNavObjArray("/gm/english/corporate/help/faq","FAQs");
  //HelpSubNavArray[2] = new makeMyGmSubNavObjArray("/english/about/help/using/index.html","Using the Site");
  HelpSubNavArray[2] = new makeMyGmSubNavObjArray("/gm/english/corporate/help/privacy/overview","Privacy Policy");
  HelpSubNavArray[3] = new makeMyGmSubNavObjArray("/gm/english/corporate/help/legal","Legal");
  }
    
function makeMyGmSubNavObjArray(topLocations,topTitles) {
  this.hrefLocation = topLocations;
  this.title = topTitles;
  return this;
 } 


// start writing out the nav beginning with a div container 
var topNavList = '';
// and now write in the list menus
topNavList += '<ul id="nav">';
	topNavList += '<li id="nav1" style="cursor:hand" onclick="top.location.href=\''+ navArray[0].hrefLocation +'\'"><a href="' + navArray[0].hrefLocation + '" target="'+linkTarget+'"><span>' + navArray[0].title + '</span></a>';
		topNavList += '<ul>';
			for(i=0;i<homeNavArray.length;i++) {
				if(i==0){
					topNavList += '<li class="topMenu"><a href="' + homeNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + homeNavArray[i].title + '</a></li>';
				}			
				if(i!==0){			
					topNavList += '<li><a href="' + homeNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + homeNavArray[i].title + '</a></li>';
				}				
			}
			topNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>'; 
		topNavList += '</ul>';	
	topNavList += '</li>';
	topNavList += '<li id="nav2" style="cursor:hand" onclick="top.location.href=\''+ navArray[1].hrefLocation +'\'"><a href="' + navArray[1].hrefLocation + '" target="'+linkTarget+'"><span>' + navArray[1].title + '</span></a>';
		topNavList += '<ul>';
			for(i=0;i<vehNavArray.length;i++) {
				if(i==0){
					topNavList += '<li class="topMenu"><a href="' + vehNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + vehNavArray[i].title + '</a></li>';
				}			
				if(i!==0){			
					topNavList += '<li><a href="' + vehNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + vehNavArray[i].title + '</a></li>';
				}			
			}
			topNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>';
		topNavList += '</ul>';	
	topNavList += '</li>';
	topNavList += '<li id="nav3" style="cursor:hand" onclick="top.location.href=\''+ navArray[2].hrefLocation +'\'"><a href="' + navArray[2].hrefLocation + '" target="'+linkTarget+'" ><span>' + navArray[2].title + '</span></a>';
		topNavList += '<ul>';
			for(i=0;i<shopNavArray.length;i++) {
				if(i==0){
					topNavList += '<li class="topMenu"><a href="' + shopNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + shopNavArray[i].title + '</a></li>';
				}			
				if(i!==0){			
					topNavList += '<li><a href="' + shopNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + shopNavArray[i].title + '</a></li>';
				}
			}		
			topNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>';
		topNavList += '</ul>';	
	topNavList += '</li>';	
	topNavList += '<li id="nav4" style="cursor:hand" onclick="top.location.href=\''+ navArray[3].hrefLocation +'\'"><a href="' + navArray[3].hrefLocation + '" target="'+linkTarget+'"><span>' + navArray[3].title + '</span></a>';
		topNavList += '<ul>';
			for(i=0;i<finNavArray.length;i++) {
				if(i==0){
					topNavList += '<li class="topMenu"><a href="' + finNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + finNavArray[i].title + '</a></li>';
				}			
				if(i!==0){			
					topNavList += '<li><a href="' + finNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + finNavArray[i].title + '</a></li>';
				}
			}	
			topNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>'; 
		topNavList += '</ul>';	
	topNavList += '</li>';	
	topNavList += '<li id="nav5" style="cursor:hand" onclick="top.location.href=\''+ navArray[4].hrefLocation +'\'"><a href="' + navArray[4].hrefLocation + '" target="'+linkTarget+'"><span>' + navArray[4].title + '</span></a>';
		topNavList += '<ul>';
			for(i=0;i<partNavArray.length;i++) {
				if(i==0){
					topNavList += '<li class="topMenu"><a href="' + partNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + partNavArray[i].title + '</a></li>';				
				}			
				if(i!==0){			
					topNavList += '<li><a href="' + partNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + partNavArray[i].title + '</a></li>';
				}
			} 
			topNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>'; 			
		topNavList += '</ul>';	
	topNavList += '</li>';
	topNavList += '<li id="nav6" style="cursor:hand" onclick="top.location.href=\''+ navArray[5].hrefLocation +'\'"><a href="' + navArray[5].hrefLocation + '" target="'+linkTarget+'"><span>' + navArray[5].title + '</span></a>';
		topNavList += '<ul>';
			for(i=0;i<aboutNavArray.length;i++) {
				if(i==0){
					topNavList += '<li class="topMenu"><a href="' + aboutNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + aboutNavArray[i].title + '</a></li>';
				}
				if(i!==0){
					topNavList += '<li><a href="' + aboutNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + aboutNavArray[i].title + '</a></li>';
				}
			}
			topNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>'; 
		topNavList += '</ul>';	
	topNavList += '</li>';
	topNavList += '<li style="cursor:hand" id="nav7" onclick="top.location.href=\''+ navArray[6].hrefLocation +'\'"><a href="' + navArray[6].hrefLocation + '" target="'+linkTarget+'"><span>' + navArray[6].title + '</span></a></li>';
	topNavList += '<li style="cursor:hand" id="nav8" onclick="top.location.href=\''+ navArray[7].hrefLocation +'\'"><a href="' + navArray[7].hrefLocation + '" target="'+linkTarget+'"><span>' + navArray[7].title + '</span></a></li>';
topNavList += '</ul>';

//alert(topNavList);
document.write(topNavList);





//Sirine
var myGmNavList = '';
// and now write in the list menus
myGmNavList += '<ul id="navicons">';
	myGmNavList += '<li id="icon1" style="cursor:hand" onclick="top.location.href=\''+ myNavArray[0].hrefLocation +'\'"><a href="' + myNavArray[0].hrefLocation + '" target="'+linkTarget+'"><span>' + myNavArray[0].title + '</span></a>';
		myGmNavList += '<ul>';
			for(i=0;i<myGmSubNavArray.length;i++) {
				if(i==0){
					myGmNavList += '<li class="topMenu"><a href="' + myGmSubNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + myGmSubNavArray[i].title + '</a></li>';
				}			
				if(i!==0){			
					myGmNavList += '<li><a href="' + myGmSubNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + myGmSubNavArray[i].title + '</a></li>';
				}				
			}
			myGmNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>'; 
		myGmNavList += '</ul>';	
	myGmNavList += '</li>';
	myGmNavList += '<li id="icon2" style="cursor:hand" onclick="top.location.href=\''+ myNavArray[1].hrefLocation +'\'"><a href="' + myNavArray[1].hrefLocation + '" target="'+linkTarget+'"><span>' + myNavArray[1].title + '</span></a>';
		myGmNavList += '<ul>';
					for(i=0;i<HelpSubNavArray.length;i++) {
						if(i==0){
							myGmNavList += '<li class="topMenu"><a href="' + HelpSubNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + HelpSubNavArray[i].title + '</a></li>';
						}			
						if(i!==0){			
							myGmNavList += '<li><a href="' + HelpSubNavArray[i].hrefLocation + '" target="'+linkTarget+'">' + HelpSubNavArray[i].title + '</a></li>';
						}				
					}
					myGmNavList += '<li class="botMenu" id="botMenu"><a href="#"></a></li>'; 
				myGmNavList += '</ul>';	
			myGmNavList += '</li>';
myGmNavList += '</ul>';

//alert(myGmNavList);
document.write(myGmNavList);


//*******************
// TOP NAV JS INCLUDE
//*******************
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	var sfElsR = document.getElementById("navicons").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	for (var i=0; i<sfElsR.length; i++) {
		sfElsR[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfElsR[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function change(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}