
var fileType = ".jpg";												// your nav images type
var outId = 1;														// out state
var overId = 2;														// over state
//var downId;															// down state
var downId = 3;													// down state - uncomment this if you have a third button state

arrImages = ["home","about","contact","contractors","careers","login","services","news"];					// these are your site top folders structure, plus home for the home images
//alert(arrImages)
function navSetter () {
	var pressedId = downId == undefined ? overId : downId;			// check for third state
	var suffix = pressedId + fileType;								// the file fuffix
	var tmp = top.location.toString();
	var t = tmp.replace(/http:\/\//g,"").toLowerCase();			// replace http://
	baseUrlIndex = t.indexOf(baseUrl) + baseUrl.length;
	var u = t.slice(baseUrlIndex);								// the url excluding the baseUrl
	var subfolderEnd = u.indexOf("/");								// the index of the first /
	if (subfolderEnd == -1) subfolderEnd = "";						// make nothing if not found
	var folder = u.slice(0, subfolderEnd);							// the parent folder
	folder.length == 0 ? folder = "home" : null;
	
	if (validImage(folder)) document.images["nav_"+folder].src = baseUrl + "images/nav_"+folder+"_" + suffix;
	
	preloadImages();
};

/*
	check for a valid image
*/
function validImage (folderStr) {
	for (var i=0;i<arrImages.length;i++) {if (folderStr.toLowerCase() == arrImages[i].toLowerCase()) return true;};
	return false;
};

/*
	preload over state images in arrImages
*/
function preloadImages () {
	var str = "";
	for (var i=0;i<arrImages.length;i++) {str += baseUrl + " 'images/nav_"+arrImages[i]+"_"+overId+fileType+"', ";};
	MM_preloadImages(str);
};