
// Sniff for the two major browsers
	var ie  = (document.all)? true:false
	var ns6 = ((document.getElementById)&&(!ie))? true:false

// Sniff for Mac, used for IE Mac browsers
	var mac = (navigator.userAgent.toUpperCase().indexOf("MAC") > -1)? true:false

// Used to test if a value is 'undefined'.  What 'undefined' represents is different for each
// browser, but any variable that has not been defined a value IS 'undefined' in all browsers.
// So, we'll test against this variable to see if another is 'undefined'.
	var undef;

	var bgXcoord = 0;

	var HideText = "";

// var is declared in universal nav offsite code, used to define full path.
// we don't want to hose the value, so we'll check if it has one.
	if (T1navPath == undef) {
		var T1navPath = "";
	}

	var PreloadComplete = false;
	var HomePreloadComplete = false;

	var MouseOverColor = "#C4C4C4";
	var MouseOffColor = "#DADAD5";

// Global Variables, used to set which model page we're on
	var gVCmodel =  "index";
	var gModelName = "";
	var gLegacyAbbrev = "";
	var gBrochurePDAAbbrev = "";
	var gPageName = "";


// These links are considered absolute links at this point.
	var topNavMenu = new Array();

	topNavMenu["Services0"] = new Array("&nbsp; Spare Parts", "../../services/index.htm#spare_parts");
	topNavMenu["Services1"] = new Array("&nbsp; Detroit Diesel", "../../services/index.htm#ddc");
	topNavMenu["Services2"] = new Array("&nbsp; Allison Transmission", "../../services/index.htm#atd");
	topNavMenu["Services3"] = new Array("&nbsp; Woodward Governors", "../../services/index.htm#woodward_governors");
	topNavMenu["Services4"] = new Array("&nbsp; Generators", "../../services/index.htm#generators");
	topNavMenu["Services5"] = new Array("&nbsp; Compressors", "../../services/index.htm#compressors");
	topNavMenu["Services6"] = new Array("&nbsp; General Repairs", "../../services/index.htm#gen_repair");


	topNavMenu["Products0"] = new Array("&nbsp; Allison", "../agencies/allison/index.htm");
	topNavMenu["Products1"] = new Array("&nbsp; SDMO", "../agencies/sdmo/index.htm");
	topNavMenu["Products2"] = new Array("&nbsp; Boge", "../agencies/boge/index.htm");
	topNavMenu["Products3"] = new Array("&nbsp; Compair", "../agencies/compair/index.htm");
	topNavMenu["Products4"] = new Array("&nbsp; Crown", "../agencies/crown/index.htm");
	topNavMenu["Products5"] = new Array("&nbsp; Rhino", "../agencies/everdigm/index.htm");
	topNavMenu["Products6"] = new Array("&nbsp; Detroit Diesel", "../agencies/ddc/index.htm");
	topNavMenu["Products7"] = new Array("&nbsp; Domnick Hunter", "../agencies/domnick/index.htm");
	topNavMenu["Products8"] = new Array("&nbsp; Esco", "../agencies/esco/index.htm");
	topNavMenu["Products9"] = new Array("&nbsp; HAMM", "../agencies/hamm/index.htm");
	topNavMenu["Products10"] = new Array("&nbsp; Terex Pegson", "../agencies/terex/index.htm");
	topNavMenu["Products11"] = new Array("&nbsp; Isuzu", "../agencies/isuzu/index.htm");
	topNavMenu["Products12"] = new Array("&nbsp; SKF", "../agencies/skf/index.htm");
	topNavMenu["Products13"] = new Array("&nbsp; Volvo", "../agencies/volvo/index.htm");
	topNavMenu["Products14"] = new Array("&nbsp; WoodWard", "../agencies/woodward/index.htm");


	topNavMenu["Hire0"] = new Array("&nbsp; Generators", "../../hire/index.htm#generators");
	topNavMenu["Hire1"] = new Array("&nbsp; Compressors", "../../hire/index.htm#compressors");
	

//	topNavMenu["Financial0"] = new Array("Leasing", "/financial/leasing/index.html");
//	topNavMenu["Financial1"] = new Array("Financing", "/financial/financing/index.html");
//	topNavMenu["Financial2"] = new Array("My LFS Account", "https://www.lexusfinancialofsc.com/my_lfs/login/login.jsp");
//	topNavMenu["Financial3"] = new Array("Trade-In Value", "/financial/trade_in.html");
//	topNavMenu["Financial4"] = new Array("Financial Glossary", "/financial/financial_glossary.html");
//	topNavMenu["Financial5"] = new Array("Online Credit Application", "http://www.lexusfinancial.com/oca/lfs/step1.jsp");
//	topNavMenu["Financial6"] = new Array("Payment Estimator", "http://www.lexusfinancial.com/estimator/lfs/pe_zip.jsp");
//	topNavMenu["Financial7"] = new Array("Which Lexus Fits My Budget?", "http://www.lexusfinancial.com/rev_estim/lfs/index.jsp");

//	topNavMenu["Owners0"] = new Array("Welcome", "/owner/");
//	topNavMenu["Owners1"] = new Array("My Profile", "/owner/");
//	topNavMenu["Owners2"] = new Array("My Garage", "/owner/");
//	topNavMenu["Owners3"] = new Array("<I>Lexus</I> Magazine", "/owner/");
//	topNavMenu["Owners4"] = new Array("Virtual Tour", "https://auth.owners.lexus.com/pub-share/html/virtual_tour.html");

//	topNavMenu["About0"] = new Array("News", "/about/news/index.html");
//	topNavMenu["About1"] = new Array("Press Releases", "/about/press_releases/index.html");
//	topNavMenu["About2"] = new Array("Awards & Accolades", "/about/awards/index.html");
//	topNavMenu["About3"] = new Array("Events", "/about/events/index.html");
//	topNavMenu["About4"] = new Array("Corporate Information", "/about/corporate/index.html");
//	topNavMenu["About5"] = new Array("Lexus History", "/about/history/index.html");

//	topNavMenu["Home0"] = new Array("Search", "/home/search.html");
//	topNavMenu["Home1"] = new Array("Contact Lexus", "/home/contact_lexus.html");
//	topNavMenu["Home2"] = new Array("International Links", "/home/international_links.html");
//	topNavMenu["Home3"] = new Array("Privacy Policy", "/home/privacy_policy.html");


	var topNavContents = new Array();
	topNavContents["Services"] = "";
	topNavContents["Products"] = "";
	topNavContents["Hire"] = "";
//	topNavContents["Financial"] = "";
//	topNavContents["Owners"] = "";
	topNavContents["About"] = "";
	topNavContents["Home"] = "";


//	var topNavBYLCode = new Array();
//	topNavBYLCode["ls"] = "9100";	// LS 430
//	topNavBYLCode["gs"] = "93";	// GS Generic
//	topNavBYLCode["es"] = "9000";	// ES 300
//	topNavBYLCode["is"] = "95";	// IS 300 Generic
//	topNavBYLCode["is_5speed"] = "9501";	// IS 300 5-Speed
//	topNavBYLCode["is_eshift"] = "9500";	// IS 300 E-Shift
//	topNavBYLCode["is_sportcross"] = "9520";	// IS 300 SportCross
//	topNavBYLCode["sc"] = "9270";	// SC 430
//	topNavBYLCode["lx"] = "9620";	// LX 470
//	topNavBYLCode["gx"] = "9700";	// GX 470
//	topNavBYLCode["rx"] = "94";	// RX 300 Generic


// Layer Build functions.  The IF verifies that, if a layer doesn't exist
// the function will return null instead of a JavaScript error.
	function refLayer(layerName) {
		var LAYref;
		if (ie) {
			if (document.all[layerName]) {
				document.all[layerName].layerWidth = function() { return this.clientWidth; };
				LAYref = document.all[layerName];
				HideText = "hidden";
			} else {
				LAYref = null;
			}
		} else {
		    // default to NS6+
			if (document.getElementById(layerName)) {
				HTMLElement.prototype.layerWidth = function() { return this.offsetWidth; };
				LAYref = document.getElementById(layerName);
					HideText = "hidden";
			} else {
				LAYref = null;
			}
		}
			return LAYref;
	}


// Functions to determine browser window width/height
	function getInsideWindowWidth() {
		if (ie) {
			return document.body.clientWidth
		} else {
			return window.innerWidth
		}
	}

	function getInsideWindowHeight() {
		if (ie) {
			return document.body.clientHeight
		} else {
			return window.innerHeight
		}
	}


// Calculate Offsets from current item.
	function eventXoffset(nsEvt) {
		if (ie) {
			return document.body.scrollLeft - document.body.clientLeft + event.clientX - event.offsetX;
		} else {
			return nsEvt.pageX - nsEvt.layerX
		}
	}

	function eventYoffset(nsEvt) {
		if (ie) {
			return document.body.scrollTop - document.body.clientTop + event.clientY - event.offsetY;
		} else {
			return nsEvt.pageY - nsEvt.layerY
		}
	}


// Create the objects
	function menuInit() {
		LAYtopNavMenu = refLayer("topNavDIV");
		LAYarrowHL = refLayer("arrowHL");
		PreloadComplete = true;
	}


//****************************************
//** Top Nav DHTML Menu Functions START **
//****************************************

	var NotInMenuNow = true;

	function topNavBuild(menuName) {
		var i, menuHTML, linkURL;
// Build Menu Contents.  Should only be done once.
		i = 0;
		menuHTML = "";

		while (topNavMenu[menuName + i]) {
		//	menuHTML += '<DIV CLASS="menuSpacer" STYLE="width:52px; height:1px;"></DIV>\n';

// If this is a JavaScript command, just use it instead of trying a document.location.href.
			if (topNavMenu[menuName + i][1].toLowerCase().indexOf("javascript:") == 0) {
				linkURL = topNavMenu[menuName + i][1].substr(11);
			} else if (topNavMenu[menuName + i][1].toLowerCase().indexOf("http") == 0) {
				linkURL = "top.location.href='"+topNavMenu[menuName+i][1]+"'";
			} else {
				linkURL = "top.location.href='"+T1navPath+topNavMenu[menuName+i][1]+"'";
			}

			menuHTML += '<DIV CLASS="menuItem" onClick="'+linkURL+'" onMouseOver="changeBGcolor(this, MouseOverColor)" onMouseOut="changeBGcolor(this, MouseOffColor)"><NOBR>'+topNavMenu[menuName + i][0]+'</NOBR></DIV>\n';
			i++;
		}

		return menuHTML;
	}



// Top Nav Dropdown functions
// Check PreloadComplete on these just in case
	function showTopNavDD() {
		if (PreloadComplete) {
			NotInMenuNow = false;
			LAYtopNavMenu.style.visibility = "inherit";
		}
	}

	function hideTopNavDD(FirstTry) {
		if (PreloadComplete) {
			if (FirstTry) {
				NotInMenuNow = true;
				setTimeout("hideTopNavDD(false)", 80);
			} else if (NotInMenuNow) {
				LAYtopNavMenu.style.visibility = "hidden";
			}
		}
	}


	function revealTopNavDD(menuName, xCoord, evt) {
		var MenuEdge, MDxCoord, MDyCoord;

		if (PreloadComplete) {
		    //** Hide menu and move it off the page.  This resolves menu flicker. **
			NotInMenuNow = true;
			hideTopNavDD(false);
			LAYtopNavMenu.style.left = -200;
			LAYtopNavMenu.style.top = -200;

// If we haven't viewed this menu before, write out its contents and store in array.
			if (topNavContents[menuName] == "") {
				topNavContents[menuName] = topNavBuild(menuName);
			}

			LAYtopNavMenu.innerHTML = topNavContents[menuName];

// Calculate right edge of menu.  If it's past the edge of the centered table, align it so it is.
			MDxCoord = eventXoffset(evt);
			MDyCoord = eventYoffset(evt);

			LeftPageStart = (getInsideWindowWidth()-776)/2;
			MenuEdge = MDxCoord + xCoord + LAYtopNavMenu.layerWidth() - LeftPageStart;

			if (MenuEdge > 776) {
// The right edge of the menu is beyond the designed-for
// 778 pixel page width.  Adjust MDxCoord appropriately.
				MDxCoord -= (MenuEdge-768);
			}

		    //** Set left & top coordinates. **
			LAYtopNavMenu.style.left = MDxCoord + xCoord;
			LAYtopNavMenu.style.top = MDyCoord + 18;

			showTopNavDD();
		}
	}


	function changeBGcolor(LAYer, hexColor) {
		if (PreloadComplete) {
			LAYer.style.backgroundColor = hexColor;
		}
	}


	function gotoBYL() {
		if (topNavBYLCode[gModelName]) {
			top.location.href=T1navPath+"/lexusConfigApp/index.jsp?modelName="+gLegacyAbbrev+"&modelCode="+topNavBYLCode[gModelName];
		} else {
			top.location.href=T1navPath+"/lexusConfigApp/index.jsp";
		}
	}


	function gotoVC() {
		if (gVCmodel != "") {
			top.location.href=T1navPath+"/models/comparison/"+gVCmodel+".html";
		} else {
			top.location.href=T1navPath+"/models/comparison/index.html";
		}
	}

	function gotoBrochurePDA() {
		var BaseURL=T1navPath+"/lexus/jsp/pub/models/brochures_pda/index.jsp";

		if (gModelName != "") {
			top.location.href=BaseURL+"?modelName="+gModelName;
		} else {
			top.location.href=BaseURL;
		}
	}

	function gotoOrderBrochure(WeShouldReturnTheURL) {
	//	document.location.href = T1navPath+"/lexus/SendDocumentRequest?documentType=B"+ordBrochureURL;
	//	var BaseURL = "https://secure.lexus.com/lexus/jsp/pub-ssl/models/orderbrochure/orderbrochure.jsp";
		var FullURL = "";

		if (gModelName != "") {
			FullURL=BaseURL+"?modelName="+gLegacyAbbrev+"&modelCode="+topNavBYLCode[gModelName];
		} else {
			FullURL=BaseURL+"?modelName=none&modelCode=none";
		}

		if (WeShouldReturnTheURL) {
			return FullURL;
		} else {
			top.location.href=FullURL;
		}
	}

	curISmodel = "";
	function gotoISModel(isModelName) {
	    //** Only used within IS model directory, to switch between models. **
		if (gPageName != "") {
			top.location.href=T1navPath+isModelName+"_"+gPageName+".html";
		} else {
			top.location.href=T1navPath+isModelName+".html";
		}
	}


	function setGlobals(modelName, pageName) {
// These two vars are effectively the same, but they are used differently.
// For readability purposes, please keep both of them.
		gVCmodel =  modelName
		gModelName = modelName;
		gPageName = pageName;

		if (modelName == "is_5speed") {
			gLegacyAbbrev = "IS5";
			gBrochurePDAAbbrev = "is";
		} else if (modelName == "is_eshift") {
			gLegacyAbbrev = "ISE";
			gBrochurePDAAbbrev = "is";
		} else if (modelName == "is_sportcross") {
			gLegacyAbbrev = "ISSC";
			gBrochurePDAAbbrev = "is";
		} else {
			gLegacyAbbrev = modelName.toUpperCase();
			gBrochurePDAAbbrev = modelName;
		}
	}


//**************************************
//** Top Nav DHTML Menu Functions END **
//**************************************

//**************************************
//** Nav DHTML Arrows Functions START **
//**************************************

	var ArrowHLURL = "";
	var ArrowHLmodel = "";

	function moveArrowHL(AHxOffset, AHyOffset, evt) {
		var AHxCoord, AHyCoord;

		if (PreloadComplete) {
			AHxCoord = eventXoffset(evt);
			AHyCoord = eventYoffset(evt);

			if (ie) {
				AHyCoord = AHyCoord - 1;
			}

			LAYarrowHL.style.left = AHxCoord + AHxOffset;
			LAYarrowHL.style.top = AHyCoord + AHyOffset;

			showArrowHL();
		}
	}

	function showArrowHL() {
		if (PreloadComplete) {
			LAYarrowHL.style.visibility = "inherit";
		}
	}

	function hideArrowHL() {
		if (PreloadComplete) {
			LAYarrowHL.style.visibility = "hidden";
		}
	}

	function clickArrowHL() {
		if (ArrowHLURL != "") {
			top.location.href = ArrowHLURL;
		}
	}


//************************************
//** Nav DHTML Arrows Functions END **
//************************************

//*****************************************
//** Nav Rollover Arrows Functions START **
//*****************************************

	plArrowHL = new Image();
	plArrowHL.src = "/assets/common/arrow_highlight.gif";
	plArrowGR = new Image();
	plArrowGR.src = "/assets/common/arrow_gray.gif";

	plArrowUpHL = new Image();
	plArrowUpHL.src = "/assets/common/arrow_up_highlight.gif";
	plArrowUpGR = new Image();
	plArrowUpGR.src = "/assets/common/arrow_up_gray.gif";


	function arrowHL(imgName) {
		document.images[imgName].src = plArrowHL.src;
	}

	function arrowGR(imgName) {
		document.images[imgName].src = plArrowGR.src;
	}

	function arrowUpHL(imgName) {
		document.images[imgName].src = plArrowUpHL.src;
	}

	function arrowUpGR(imgName) {
		document.images[imgName].src = plArrowUpGR.src;
	}

//***************************************
//** Nav Rollover Arrows Functions END **
//***************************************

//**************************
//** Misc Functions START **
//**************************

	function newCursor(imgName, curName) {
		if (PreloadComplete) {
			document.images[imgName].style.cursor = curName;
		}
	}

	//****************************************************
	//** Popup function Fixes IE making popup windows   **
	//** 20px higher than specified when menubar is on  **
	//** Parameters can be passed in as necessary 	    **
	//** returns a reference to the	window if needed    **
	//****************************************************
	
	function popup(popupurl,winName,w,h,params) {
	    // Build parameter list manually.  This lets us override individual defaults as needed.
		var paramList = "";
		if (params == undef) {
			params = "";
		}
		params = params.toLowerCase();
		if (params.indexOf("menubar=no") != -1) {
			paramList = paramList + ",menubar=no";
		} else {
		    // default
			paramList = paramList + ",menubar=yes";
		    // IE adds to the height with a menubar; subtract to keep height the same.
			if (ie) {
				h = h - 20;
			}
		}
		if ((params.indexOf("scrollbars=no") != -1) || (params.indexOf("scrollbar=no") != -1)) {
			paramList = paramList + ",scrollbars=no";
		} else {
		    // default
			paramList = paramList + ",scrollbars=yes";
		    // IE needs extra space to allow for the phantom scrollbar, or we'll get horizontal scrollbars too.
		    // Sniff for IE 5.x.  If so, only increase the popup by 13px.  IE 6.x needs 4px more.
			if (ie) {
				if ((parseInt(navigator.appVersion) == 4) && (navigator.userAgent.toLowerCase().indexOf("msie 5.") !=-1)) {
					w = w + 13;
				} else {
					w = w + 17;
				}
			} else {
				w = w+15;
			}
		}
		if (params.indexOf("resizable=yes") != -1) {
			paramList = paramList + ",resizable=yes";
		} else {
		    // default
			paramList = paramList + ",resizable=no";
		}
		if ((params.indexOf("toolbar=yes") != -1) || (params.indexOf("toolbars=yes") != -1)) {
			paramList = paramList + ",toolbar=yes";
		} else {
		    // default
			paramList = paramList + ",toolbar=no";
		}
//alert(paramList);
		return window.open(popupurl,winName,"top=35,left=130,width=" + w + ",height=" + h + paramList);
	}

//************************
//** Misc Functions END **
//************************
