function init()
{
	if (document.images) {
		var preloadImgArray = new Array();
		// loop through images array
		for (var i = 0; i < document.images.length; i++) {
			var imgSrc = document.images[i].src;
			// find images with "_off." in the name
			if (imgSrc.match("_off.")) {
				// replace "_off." with "_on."
				var imgSrcOn = imgSrc.replace(/_off./, "_on.");
				var imgInArray = false;
				// loop to aviod pre-loading multiples of the same image
				for (var j = 0; j < preloadImgArray.length; j++) {
					if (preloadImgArray[j] == imgSrcOn) {
						imgInArray = true;
						break;
					}
				}
				// append to array
				if (!imgInArray) {
					preloadImgArray.push(imgSrcOn);
				}
			}
		}
		var preload_images = new Array();
		for (var k = 0; k < preloadImgArray.length; k++) {
			preload_images[k] = new Preload(preloadImgArray[k]);
		}
	}
}

function swapImageGallery(set, imageNum)
{
	var imgPath = '../images/photogallery/set_' + set + '/S' + set + '_MM' + imageNum + '.jpg';
	
	swapImg('medium', imgPath, '');
}

function launchImageGalleryWin(set, imageNum)
{
	var URL = 'popup.php?category=image_gallery&setID=' + set + '&image=' + imageNum;
}

function swapImg(imgName, imgPath, msg) // rollover script
{
	if (document.images) {
		if ((document.layers) && (!validateArg(document.images[imgName]))) {
			var obj = parseLayers(document, imgName, 'images');
			obj.src = imgPath;
		}
		else {
			if (document.images[imgName]) {
				document.images[imgName].src = imgPath;
			}
		}
		window.status = msg;
	}
}

function handleSelectOnChange(selectObj, URL)
{
	var selectOptionValue = selectObj.options[selectObj.selectedIndex].value;
	
	if (selectObj.options[selectObj.selectedIndex].value != 0)
	{
    	var loc = URL + "&" + selectObj.name + "=" + selectOptionValue;
        parent.location = loc;
	}               
    else {
    	selectObj.selectedIndex = 0;
	}
	return false;
}

function Preload() // preload script
{ 
	this.length = arguments.length;
	for (var i = 0; i < this.length; i++) {
		this[i + 1] = new Image();
		this[i + 1].src = arguments[i];
	}
}