// Menu rollovers 

function preLoadImages () {
	var list = new Array (
		"mm-X_f2.gif",
		"mm-Y_f2.gif"
	);

	if (document.images) {
		noImages = list.length;
		preloadedImages = new Array (noImages);
		for (x = 0; x < noImages; x++) {
			preloadedImages[x] = new Image;
			preloadedImages[x].src = '/images/' + list[x];
		}
	}
}

function swapImage(imageName, newImage) {
    if (document.images) {
      document.images[imageName].src = newImage;
  }
}

preLoadImages();




	function getPathPositions(url) {
		var pos = 0;
		positions = new Array();
		pathParts = url.split("/");
		count = pathParts.length;
		for (x = 0; x < count; x++) {
			pos = pos + pathParts[x].length + 1;
			positions[x] = pos;
		}
		return positions;
	}


	function urlsMatch(url, testUrl, level, positions) {
		if (testUrl.substr(0,1) == "/") {
			testUrl = testUrl.substr( 1 );
		}
		if(level == 0) {
			return (url.substr(1) == testUrl);
		} else {
			return (url.substr(1, positions[level]-1) == testUrl.substr(0, positions[level]-1))
		}
	}


// set highlight styles for menus

function linkHighlight() {
	var positions = getPathPositions(location.pathname);
	var count = document.links.length;
	for (i = 0; i < count; i++) {
		thisLink = document.links[i];
		if (urlsMatch(location.pathname, thisLink.pathname, 0, positions) && thisLink.className == "nav2") {
			thisLink.style.color = "#fff";
			thisLink.style.backgroundColor = "#006300";
			continue;
		} 
		if (urlsMatch(location.pathname, thisLink.pathname, 0, positions) && thisLink.className == "nav3") {
			thisLink.style.color = "#ffff00";
			thisLink.style.backgroundColor = "#006300";
			continue;
		}
	}
}

// Open page in new window

function newWindow(object) {
	window.open(object.href, "");
	return false;
}

// Adds the background image to the pagetext div
function makeBGimage() {
	var divtag = document.getElementById( "pagetext" );
	var children = divtag.childNodes;
	var i=0;
	var pagetitle = "";
	while (i<children.length) {
		if (children[i].nodeName == "H1") {
			pagetitle = children[i].innerHTML;
		}
		i++;
	}
	pagetitle = pagetitle.replace( /[^A-Za-z]/mg, "" ).toLowerCase();
	filename = "bg_" + pagetitle + ".gif";
	newstyle = 'url("/images/bg_images/' + filename + '") no-repeat top right';
	document.getElementById("content").style.background = newstyle;
}
