
/**
 * Change introduction image
 */
function changeImage(){
	if(imageArray!=null){
		try {
			/* Lookup DOM Wrapper and Image Data */
			var nodeCount = imageArray.length;
			var lookupId = "introductionWrapper";
			var wrapper = document.getElementById(lookupId);
			if(wrapper!=null){
				/* Create Image and append in DOM */
				var image = document.createElement("IMG");
				wrapper.appendChild(image);
				/* Set Image Details (at random) */
				var random = Math.floor(Math.random()* nodeCount);
				var imageDetails = imageArray[random];
				image.src = imageDetails["Path"];
				image.title = imageDetails["AltText"];	
				image.alt = imageDetails["AltText"];
				/* Width issues */
				var maxWidth = 591;
				image.width = imageDetails["Width"];
				if(image.width > maxWidth && imageDetails["IsPreview"] == 'true'){
					image.className = "SectionImageTooWide";
					image.width = 589;
					var errorDiv = document.createElement("DIV");
					wrapper.appendChild(errorDiv);
					errorDiv.className = "TemplateError";
					errorDiv.innerHTML = "Image too wide. Current width is " + imageDetails["Width"] + "px, whereas maximum width for this location is 591px. Please re-size and upload again.";
				}
				/* Render Caption */
				if(imageDetails["Caption"]!="") {
					var caption = document.createElement("P");
					wrapper.appendChild(caption);
					caption.className = "ImageCaption";
					caption.innerHTML= imageDetails["Caption"];
				}
			}
		} catch (err) {/* Catch and Supress */};
	}
}

/*
* Preload images
*/

function preLoad() {
	if (imageArray!=null) {
		try {
			/* Create new array of img nodes and populate with available paths */
			var preload = new Array();
			for (i=0;i<imageArray.length;i++) {
				preload[i] = document.createElement("IMG");
				preload[i].src = imageArray[i]["Path"];
			}
		} catch (err) {/* Catch and Supress */};
	}
}