/* --------------------------------------------------------------------------------------------------------
AUTHOR:			Ryan Marincovich
DATE CREATED:	2008.07.22
File Purpose:	Versare Website Family Common Javascript File
-------------------------------------------------------------------------------------------------------- */


// OVERLAY FUNCTIONS ----------------------------------------------
var isOverlayLoaded = false;

// build overlay objects (run onload)
function buildOverlay() {
	mainOverlayObj = eval(doc + '"mainOverlay"' + sty);
	overlayBGObj = eval(doc + '"overlayBG"' + sty);
	overlayGalleryObj = eval(doc + '"photoGallery"' + sty);
	overlayVideoPlayerObj = eval(doc + '"videoPlayer"' + sty);
	overlayViewerWindowObj = document.getElementById('mainOverlay');
	overlayViewerBodyObj = document.getElementById('bodyContainer');
	windowHeight = overlayViewerWindowObj.offsetHeight;
	contentHeight = overlayViewerBodyObj.offsetHeight;
	overlayBGObj.height = Math.max(windowHeight, contentHeight) + "px";
	// set var to note objects are built and ready
	isOverlayLoaded = true;
}
// END OVERLAY FUNCTIONS ------------------------------------------

// MAIN NAVIGATION FUNCTIONS/DATA ------------------------------------------

function navOn(which) {
	showNav(which);
	return true;
}
function navOff(which) {
	hideNav(which);
	return true;
}

// function to roll a nav button on
function navStayOn(which) {
	changeImages("nav_"+which,"nav_"+which+"_roll");
	return true;
}
// function to roll a nav button off
function navStayOff(which, state) {
	changeImages("nav_"+which,"nav_"+which+"_"+state);
	return true;
}

// UTILITY FUNCTIONS/DATA --------------------------------------------------

// sets cursor focus on the field given by param (formID.fieldID)
function formFocus(strFormAndFieldIDs) {
	if (isPageLoaded) {
		eval("document.forms." + strFormAndFieldIDs + ".focus();");
	} else {
		setTimeout("formFocus('" + strFormAndFieldIDs + "')", 100);
	}
}

// vars for dropdown menus
var navTimer = null;
var currNav = null;
var navHideDelay = 500;
var isNavLoaded = false;

// build dropdown objects (run onload)
function buildNav() {
	aboutDropNavObj = eval(doc + '"aboutDropNav"' + sty);
	product_linesDropNavObj = eval(doc + '"product_linesDropNav"' + sty);
	customer_serviceDropNavObj = eval(doc + '"customer_serviceDropNav"' + sty);
	contactDropNavObj = eval(doc + '"contactDropNav"' + sty);
	isNavLoaded = true;
}

// shows a dropdown menu, hides any other dropdown that is currently showing
function showNav(which) {
	if (isNavLoaded) {
		clearTimeout(navTimer);
		navTimer = null;
		if ((currNav != null) && (currNav != which)) {
			eval(currNav + "DropNavObj.visibility = 'hidden'");
		}
		if ((which == "about") || (which == "product_lines") || (which == "customer_service") || (which == "contact")) {
			currNav = which;
			eval(currNav + "DropNavObj.visibility = 'visible'");
		}
	}
}
// hides a dropdown menu on a time delay
function hideNav(which) {
	if (isNavLoaded) {
		clearTimeout(navTimer);
		navTimer = null;
		if ((which == "about") || (which == "product_lines") || (which == "customer_service") || (which == "contact")) {
			navTimer = setTimeout(which + "DropNavObj.visibility = 'hidden'", navHideDelay);
		}
	}
}

// swap one or more images
function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			var argArray = arguments[i].split('.');
			var objName;
			if ((document.layers && argArray.length > 1) || argArray.length <= 1) {
				objName = eval("document." + arguments[i]);
			} else {
				objName = eval("document." + argArray[argArray.length - 1]);
			}
			objName.src = eval(changeImages.arguments[i+1] + ".src");
		}
	}
}

// dhtml layer variables for cross-browser compatability
if (document.layers) {	// Netscape 4
	doc = "document[";
	conDoc = "document";
	sty = "]";
	htm = ".document";
	cls = "].className";
} else if (document.getElementById) {	// NS 6 or IE 5 and up (W3C compliant browsers).
	doc = "document.getElementById(";
	conDoc = "document.getElementById(";
	sty = ").style";
	htm = ".document";
	cls = ").className";
} else if (document.all) {	// IE 4
	doc = "document.all[";
	conDoc = "document.all[";
	sty = "].style";
	htm = "";
	cls = "].className";
}