
// globalNav.js
// Written by Matt Paladino
// March 29, 2004
// For Nissan Global Header Study

// init function.  This will go on every page and check for 5.x browser compatibility.
// Since NNA has deprecated 4.x browsers the do not support the "getElementById()" method,
// we will be using this to identify all elements. This next function check for browser 
// compatibility and redirects user if the do not have the proper browser.

var hasDOM = (document.getElementById) ? 1 : 0;
var flashVersion = 6; // Flash version
var hasFlash = flashCheck();
function init() {
	if(!hasDOM) {
		location.href = "http://www.nissanusa.com/global/error/scriptcheck.html";
	}
	
	//Reintroducing the doneLoading boolean to indicate page has loaded fully. 
	doneLoading = true;
}



// Basic preload function that creates image objects

function loadImg(imgObj,imgSrc) {
	if(document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

// This is a basic one line image rollover function.  Quick and dirty
function rollImage(imgObject, imgTarget) {
	eval('document.getElementById(imgTarget).src = ' + imgObject + '.src');
}

// Really basic show and hide layer functions

function showLayer(divId) {
	document.getElementById(divId).style.visibility = "visible";
}
		
function hideLayer(divId) {
	document.getElementById(divId).style.visibility = "hidden";
}


//  show layer function

var menuTimer;
var menuTimeout;
var submenuTimeout;
var currentMenu;
var currentsubMenu;


function menuOn(menuName) {
	var theMenu;

	if (menuTimeout) { clearTimeout(menuTimeout); }	// clear the timeout

	if (currentMenu) {			// hide the current menu
		theMenu = document.getElementById(currentMenu);
		theMenu.style.visibility = "hidden";
	}
	currentMenu = menuName;
	theMenu = document.getElementById(currentMenu);
	theMenu.style.visibility = "visible";				// display menuName
}

function submenuOn(submenuName) {
	var thesubMenu

	if (submenuTimeout) { clearTimeout(submenuTimeout);	} // clear the timeout

	if (currentsubMenu) {			// hide the current menu
		thesubMenu = document.getElementById(currentsubMenu);
		thesubMenu.style.visibility = "hidden";
	}
	currentsubMenu = submenuName;
	thesubMenu = document.getElementById(currentsubMenu);
	theMenu = document.getElementById(currentMenu);
	thesubMenu.style.visibility = "visible";
	theMenu.style.visibility = "visible";				// display menuName
}

// Hides the dropdown menus
// inputs: menuName - name of the menu DIV layer without the Div.  ie. vehicles
// outputs: none
function menuOff(menuName) {

	if (menuTimeout) clearTimeout(menuTimeout)	// clear the current timeout
	menuTimeout = setTimeout('document.getElementById("' + menuName + '").style.visibility = "hidden"', 500);		// set the new timeout
}

function submenuOff(submenuName) {

	if (submenuTimeout) clearTimeout(submenuTimeout)	// clear the current timeout
	submenuTimeout = setTimeout('document.getElementById("' + submenuName + '").style.visibility = "hidden"', 330);		// set the new timeout
}

// Flash check
function flashCheck() {
	flashCanPlay = 0;
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if(plugin) {
		var txt = navigator.plugins["Shockwave Flash"].description.split(" ");
		for(var i=0; i<txt.length; i++) {
			if(isNaN(parseInt(txt[i])))
				continue;
			var pluginVersion = txt[i]; 
		}
		var flashCanPlay = pluginVersion >= flashVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
		for(var i=7; i>0; i--) {
			myFlashVersion = 0;
			try {
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
				myFlashVersion = i;
				break;
			}
			catch(e) {
			}
		}
		if(myFlashVersion >= flashVersion) {
			flashCanPlay = 1;
		}
	}
	return flashCanPlay;
}


// generic popup window function
function openWin(url, windowName, width, height) {
	var windowObject = window.open(url, windowName, "location=no,menubar=no,resizable=no,status=no,scrollbars=yes,titlebar=no,toolbar=no,width=" + width + ",height=" + height);
	windowObject.focus();
}

// generic popup window function
function openPrintWin(url, windowName, width, height) {
	var windowObject = window.open(url, windowName, "location=no,menubar=no,resizable=yes,status=no,scrollbars=yes,titlebar=no,toolbar=yes,width=" + width + ",height=" + height);
	windowObject.focus();
}
//added by Ganapathy function took from old js file

var imgPathNav;
var imgPath;
var BaseHREF;
var PathName;

if (!PathName)
{
	PathName= '/m/static/i/';
}

if (BaseHREF) {
	var imgPathNav = BaseHREF + PathName; 	// Image path location for Global Nav menu images.
	var imgPath = BaseHREF + PathName; 	// Image path location for all other images.
} else {
	var imgPathNav = PathName; 	// Image path location for Global Nav menu images.
	var imgPath = PathName; 		// Image path location for all other images.
}


function linkSwap(imgName, ON) {
	var theImage = eval("document." + imgName);
	theImage.src = imgPath + imgName + ((ON) ? "_on":"") + ".gif"
}

// Swaps the arrow image.
// input: 	imgName - name of the image
//			ON - on or off state
function arrowSwap(linkName, ON, obj, obj2) {
	var theImage = 'document.'

	if (obj && is.ie) {
		theImage += 'all.'
	} else if (obj && is.ns) {
	 	theImage += obj + '.document.'
	}

	if (obj2 && is.ns) {
			theImage += obj2 + '.document.'
		}
	
	theImage += linkName
	
	theImageObj = eval(theImage);
	theImageObj.src = imgPath + "gl_arrow" + ((ON) ? "_on":"") + ".gif";
}
// added by Banesh for aboutNissan Pages Dt: 25-11-2004
// Swaps the 'up' arrow image.
// input: 	imgName - name of the image
//			ON - on or off state
function arrowSwapUp(linkName, ON, obj, obj2) {
	var theImage = 'document.'

	if (obj && is.ie) {
		theImage += 'all.'
	} else if (obj && is.ns) {
	 	theImage += obj + '.document.'
	}

	if (obj2 && is.ns) {
		theImage += obj2 + '.document.'
	}

	theImage += linkName
	theImageObj = eval(theImage);

	theImageObj.src = imgPath + "gl_arrow_up" + ((ON) ? "_on":"") + ".gif";
}


