/******************************************************************
 * Browser/OS Sniffer
 *****************************************************************/

// Read in HTTP_USER_AGENT from browser
var agt = navigator.userAgent.toLowerCase();

// Assign OS Variables
var is_mac = (agt.indexOf("mac") != -1);
var is_win = (agt.indexOf("win") != -1);
var is_ie = (navigator.userAgent.toUpperCase().indexOf("MSIE") > -1)? true:false
var is_ff = (navigator.userAgent.toUpperCase().indexOf("FIREFOX") > -1)? true:false

// 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

// Sniff for AOL, used in certain cases where AOL won't pop open a window the size we want it
var aol = (navigator.userAgent.toUpperCase().indexOf("AOL") > -1)? true:false

/******************************************************************
 * Functions from old menu_dhtml.js
 *****************************************************************/
// 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 PreloadComplete = false;
var HomePreloadComplete = false;

// 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) {
	var T1navPath = "";
}

var topNavBYLCode = new Array();
topNavBYLCode["ls"] = "9100";	// LS 430

topNavBYLCode["gs_gateway"] = "93";	// GS Generic
topNavBYLCode["gs"] = "9399";	// GS Generic
topNavBYLCode["gs_hybrid"] = "9344";	// GS Generic


topNavBYLCode["es"] = "9000";	// ES 300
topNavBYLCode["is"] = "95";	// IS 300 Generic
topNavBYLCode["sc"] = "9270";	// SC 430
topNavBYLCode["lx"] = "9620";	// LX 470
topNavBYLCode["gx"] = "9700";	// GX 470
topNavBYLCode["rx_gateway"] = "94";	// RX Generic
topNavBYLCode["rx"] = "9499";	// RX 330 FWD/AWD
topNavBYLCode["rx_hybrid"] = "9444";	// RX Hybrid 400

// 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]) {
			LAYref = document.all[layerName];
			HideText = "hidden";
		} else {
			LAYref = null;
		}
	} else {
	    // default to NS6+
		if (document.getElementById(layerName)) {
			LAYref = document.getElementById(layerName);
			HideText = "hidden";
		} else {
			LAYref = null;
		}
	}
	return LAYref;
}

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 == "rx_gateway") {
		top.location.href=T1navPath+"/models/comparison/rx.html";
	}else if (gVCmodel == "gs_gateway") {
		top.location.href=T1navPath+"/models/comparison/gs.html";
	} else if ((gVCmodel != "") && (gVCmodel != "hybrid")) {
		top.location.href=T1navPath+"/models/comparison/"+gVCmodel+".html";
	} else {
		top.location.href=T1navPath+"/models/comparison/index.html";
	}
}

function gotoContactDealer() {
	top.location.href=T1navPath+"/lexus/jsp/pub/dealers/contact/dealer_contact.jsp";
}

// Detect Current Model section and prepopulate hidden values in Brochure page
function gotoBrochures() {
	var BaseURL=T1navPath+"/lexus/jsp/pub/models/brochures/index.jsp";

	if (gModelName != "") {
		top.location.href=BaseURL+"?modelName="+gModelName;
	} else {
		top.location.href=BaseURL;
	}
}

// Backup function just in case it's being called from an unknown script/page
function gotoBrochurePDA() {
	gotoBrochures();
}

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 != "") {
		if(gModelName == "rx_hybrid") {
			FullURL=BaseURL+"?modelName=RX Hy&modelCode="+topNavBYLCode[gModelName];
		}else if(gModelName == "gs_hybrid") {
			FullURL=BaseURL+"?modelName=GS Hy&modelCode="+topNavBYLCode[gModelName];
		} else {
			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 != "") {
		seIdx = gPageName.lastIndexOf("_se");
		if ((seIdx != -1) && (seIdx == gPageName.length-3) && (isModelName == "sportcross")) {
		  // We're on a Special Edition page, but we're jumping to a Sportcross page.
		  // Go to the normal page.
			top.location.href=T1navPath+isModelName+"_"+gPageName.substring(0,seIdx)+".html";
		} else {
			top.location.href=T1navPath+isModelName+"_"+gPageName+".html";
		}
	} else {
		top.location.href=T1navPath+isModelName+".html";
	}
}
*/
function lexusMagazine() {
	magPath = 'http://www.lexus.com/magazine/webEntry.html';
	popup(magPath, 'lexusMagazine', 700, 450, 'menubar=no, scrollbars=no');
	top.location.href=T1navPath+"/owner/";
}

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;
	gLegacyAbbrev = modelName.toUpperCase();
	gBrochurePDAAbbrev = modelName;
}
/******************************************************************
 * END Functions from old menu_dhtml.js
 *****************************************************************/

//********************************
//** Query String Parsing START **
//********************************

	// This loads all variables in a querystring into an associative array named qsVars
	// I.e., qsVars[variable_name] == variable_value when querystring is ?variable_name=variable_value&...
	var qsVars = new Array();

	var queryString = location.search;

	if (queryString != "") {
 		// -- get rid of ? at start --
  		var qsdata = queryString.slice(1,queryString.length);
		var qsvalues = qsdata.split("&");
		for (i=0; i < qsvalues.length; i++) {
			var qsvaluepair = qsvalues[i].split("=");
			//alert(qsvaluepair[0]);
			//alert(qsvaluepair[1]);
			qsVars[qsvaluepair[0]] = qsvaluepair[1];
		}
	}

//********************************
//** Query String Parsing END **
//********************************

//****************************
//** Flash Sniffing START ****
//****************************

// Check for Flash, set vars if T/F
var Flash4 = false;
var Flash5 = false;
var Flash6 = false;
var FlashEnabled = false;
// Default is False, so we only need to set it as True.
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
	// Check for Flash in Netscape
	var nsFlash = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
	if (nsFlash) {
		var FlashVer = parseInt(nsFlash.description.substring(nsFlash.description.indexOf(".")-1));
		if (FlashVer >= 6) {
			Flash6 = true;
		} else if (FlashVer == 5) {
			Flash5 = true;
		} else if (FlashVer == 4) {
			Flash4 = true;
		}
	}
} else if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	var f4Inst;
	var f5Inst;
	var f6Inst;

	eval('try { f4Inst = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.4"); f5Inst = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.5"); f6Inst = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); } catch (e) { }');

	if (f6Inst != null) {
		Flash6 = true;
	} else if (f5Inst != null) {
		Flash5 = true;
	} else if (f4Inst != null) {
		Flash4 = true;
	}

	f4Inst = null;
	f5Inst = null;
	f6Inst = null;
}

if (qsVars['flash'] == 'disabled') {
	Flash4 = false;
	Flash5 = false;
	Flash6 = false;
	alert('Flash has been disabled for testing purposes.');
	// FlashEnabled default is false
} else if (Flash5 || Flash6) {
	FlashEnabled = true;
}


//**************************
//** Flash Sniffing 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();
	
	// Centering the Popup
	if (params.indexOf("centered=yes") != -1)
		{
			t = Math.round((screen.height - h) / 2);
			l = Math.round((screen.width - w) / 2);
		}
	else
		{
			t = 35;
			l = 130;
		}

	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 && !mac) {
			h = h - 20;
		}
	}
	
	if(aol) // aol anti-spyware tools deduct from our viewable area
		{
		h = h + 45;
		}
	

	// For Mozilla Popups that don't need extra sapce
	if ((params.indexOf("scrollbars=no") != -1) || (params.indexOf("scrollbar=no") != -1)) {
		paramList = paramList + ",scrollbars=no";
	} else if (params.indexOf("mozscroll=auto") != -1 && !is_ie) {
		w = w;
	} else {
	    // default
		paramList = paramList + ",scrollbars=yes";
	    // IE needs extra space to allow for the phantom scrollbar, or we'll get horizontal scrollbars too.
	    // IE 6.x needs 4px more than IE 5.x, but IE 5.x's width needs vary a lot.  So, we'll set all
	    // IE browsers to use the wider IE 6.x size.
		if (ie && !aol)
		{
			w = w + 17;
		}
		else if(is_ff)
		{
			w = w + 19;
		}
		else
		{
			if(aol)
				w = w + 21;
			else
				w = w + 16;
		}
	}
	
	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";
	}
	
	if ((params.indexOf("location=yes") != -1) || (params.indexOf("location=yes") != -1)) {
		paramList = paramList + ",location=yes";
	} else {
	    // default
		paramList = paramList + ",location=no";
	}
	
	if ((params.indexOf("status=yes") != -1)) {
		paramList = paramList + ",status=yes";
	} else {
	    // default
		paramList = paramList + ",status=no";
	}
	
	if ((params.indexOf("top=") != -1) || (params.indexOf("left=") != -1)) {
		paramArray = params.split(",");
		for (i=0; i<paramArray.length; i++) {
			if (paramArray[i].indexOf("top=") != -1) {
				pEles = paramArray[i].split("=");
				t = pEles[1];
			}
			if (paramArray[i].indexOf("left=") != -1) {
				pEles = paramArray[i].split("=");
				l = pEles[1];
			}
		}
	}
	// Override window name
	if (winName == "grad") {
	winName = "gradprogram";
	} else if (winName == "gradprog") {
	winName = "gradprogram";
	}
	
	//alert(paramList);
	return window.open(popupurl,winName,"top=" + t + ",left=" + l + ",width=" + w + ",height=" + h + paramList);
}

// Primary Popup 525x470
function popupPrimary(url,popupName,params) {
	// If Parameters are Empty
	var paramList = "";
	if (params == undef) {
		params = "";
	}

	popup(url,popupName,525,470,params);
}

// Secondary Popup 525x230
function popupSecondary(url,popupName,params) {
	// If Parameters are Empty
	var paramList = "";
	if (params == undef) {
		params = "";
	}

	popup(url,popupName,525,230,params);
}

//************************
//** Misc Functions END **
//************************

//************************
//	Standards Compliant Rollover Script
//	Author : Daniel Nolan
//	http://www.bleedingego.co.uk/webdev.php
//************************
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_ovr'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_ovr'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}

			// Added to relieve bug in Mozilla, when layer dissapears and mouse never goes "out", is stuck in hover state
			aImages[i].onclick = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_ovr'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
	LAYarrowHL = refLayer("arrowHL");
	PreloadComplete = true;
}

//*****************************************
//** Nav Rollover Arrows Functions START **
//** Needed for Events tertiary nav      **
//*****************************************

	plArrowHL = new Image();
	plArrowHL.src = "assets/common/arrow_highlight.gif";
	plArrowGR = new Image();
	plArrowGR.src = "assets/common/arrow_gray.gif";

	function arrowHL(imgName) {
		if (document.images[imgName]) {
			document.images[imgName].src = plArrowHL.src;
		}
	}

	function arrowGR(imgName) {
		if (document.images[imgName]) {
			document.images[imgName].src = plArrowGR.src;
		}
	}

// Parent Child Window Hook
function oFocus() {
	self.focus();
}

//***************************************
//** Nav Rollover Arrows Functions END **
//***************************************

// must run to declare default values
setGlobals('','')