// Array Containing Preloaded Images
var imageArray = new Array();

// Create newImage elements and insert into imageArray
function preloadImages(imageList) {
	var listSplit = imageList.split(",");
	var splitLen  = listSplit.length;
	var i         = 0;
	var width     = "";
	var height    = "";

	if(arguments.length >= 2 && isNaN(arguments[1]) == false) {
		width = arguments[1];
	}

	if(arguments.length >= 3 && isNaN(arguments[2]) == false) {
		height = arguments[2];
	}

	for(i; i < splitLen; i++) {
		if(width != '' && height != '') {
			imageArray[i] = new Image(width,height);
		} else {
			imageArray[i] = new Image();
		}

		imageArray[i].src = "/" + listSplit[i];
	}
}

// Changes Image SRC in Mini Gallery
function miniGallery(direction) {
	var currentNum = parseInt(document.getElementById("galleryImageCurrent").innerHTML);
	var totalNum   = parseInt(document.getElementById("galleryImageTotal").innerHTML);
	var row        = (currentNum - 1) + direction;
	var newImage   = "/images/" + defaultImage;
	var swapBG     = true;
	var showRow    = true;

	if (arguments.length > 1) {
		swapBG = arguments[1];
	}

	// if the gallery is not empty - cycle thru the images
	if (totalNum > 0) {
		if (row >= totalNum) {
			row = 0;
		} else if (row < 0) {
			row = totalNum - 1;
		}

		newImage = imageArray[row].src;
		row      = row + 1;
	} else {
		// if there are no images in the gallery - don't break the script - just show spacer.gif
		row = 0;
	}

	// Displaying imageNum of totalNum if showRow is true.
	document.getElementById("galleryImageCurrent").innerHTML = row;

	if(swapBG == true) {
		// swap image background
		document.getElementById('imageTD').style.backgroundImage = 'url(' + newImage + ')';
	} else {
		// swap image src
		document.getElementById('galleryImage').src = newImage;
	}
}
