	var path = "../images/";  //Path to the images folder
	
	//User agent IDs of popular mobile browsers. Taken from http://www.hand-interactive.com/resources/detect-mobile-javascript.htm
	var mobiles = new Array("iphone", "ipod", "android", "blackberry");	
	var usingMobile = false;
	
	var loader = path + "/loader.gif";  //Path to the loader image. Found at http://www.ajaxload.info/
	var loaderAlt = "Loading image rotator. Please wait.";  //Alt text for the loader image
	var loaderID = "loader" //Loader element ID
	var loading = "Loading image files...";  //Loading message that is displayed while preloader is running
	
	var image = "image";  //Element ID of the div that will contain the rotator's current image
	var story = "story";  //Element ID of the div that will contain the rotator's current story
	var exception = "javascript:void(0)";

	var objImage;
	var objStory;

	var oImages = new Image();	
	var source = new Array(path + "1.jpg", path + "2.jpg", path + "3.jpg", path + "4.jpg", path + "t1.gif", path + "t2.gif", path + "t3.gif", path + "t4.gif", path + "bw1.gif", path + "bw2.gif", path + "bw3.gif", path + "bw4.gif");
	var index = 4;  //Begin image caching at index 4.
	
	//Instantiate image objects for main rotator story
	var main0 = new Image();
	var main1 = new Image();
	var main2 = new Image();
	var main3 = new Image();
	
	var mainImages = new Array(main0, main1, main2, main3);
	
	var images = new Array(new Array("", "", "", ""),
												 new Array("", "", "", ""),
												 new Array("", "", "", ""),
												 new Array( "", "", "", ""));
	
	var thumbs = new Array(new Array("upperleft", path + "t1.gif", path + "bw1.gif"),
												 new Array("upperright", path + "t2.gif", path + "bw2.gif"),
												 new Array("lowerleft", path + "t3.gif", path + "bw3.gif"),
												 new Array("lowerright", path + "t4.gif", path + "bw4.gif"));
												
	var current = rand(images.length); //The index of the image that's currently being displayed. Randomized on initial page load.
	
	//Register event listeners
	addListener(window, onPageLoad, "onload", "load");
	addListener(oImages, onImageLoad, "onload", "load");
	addListener(oImages, onImageLoad, "onerror", "error");  //If image is not found, skip it
	for (var i = 0; i < mainImages.length; i++) {
		if (i == current) {
			addListener(mainImages[i], onMainImageLoad, "onload", "load");
			continue;
		}
		addListener(mainImages[i], loadMainImage, "onload", "load");
	}
	
	
	//Functions
	
	//Modified from http://www.hand-interactive.com/resources/detect-mobile-javascript.htm
	function isMobile() {
		for (i in mobiles) {
			if (navigator.userAgent.toLowerCase().search(mobiles[i]) > -1) {	
				return true;
			}
		}
	}
	
	function onPageLoad() {
		objImage = document.getElementById(image);
		objStory = document.getElementById(story);
		
		removeChildren(objStory, "");
		objStory.appendChild(createElement("p", loading));		
		document.getElementById(image).appendChild(createImgElement(loader, loaderAlt, loaderID)); 
		preloader();
	}
	
	function preloader() {
		oImages.src = source[index];
	}
	
	function onImageLoad(evt) {
		index++;
		if (index == source.length) {	
			mainImages[current].src = source[current];
		}
		else {
			preloader(index);
		}
	}
	
	function onMainImageLoad(evt) {
		objImage.removeChild(document.getElementById(loaderID));
		objImage.style.backgroundImage="url(" + source[current] + ")";		
		getStories();
		addListeners();
		getThumbs(current);
	}
	
	function addListeners() {
		for (var i = 0; i < thumbs.length; i++) {
			addListener(document.getElementById(thumbs[i][0]).getElementsByTagName("A")[0], colorThumb, "onmouseover", "mouseover");
			addListener(document.getElementById(thumbs[i][0]).getElementsByTagName("A")[0], greyscaleThumb, "onmouseout", "mouseout");
			addListener(document.getElementById(thumbs[i][0]).getElementsByTagName("A")[0], getSlide, "onclick", "click");
		}
	}	
	
	function getStories() {
		for (var i = 0; i < thumbs.length; i++) {
			for (var n = 0; n < document.getElementById(thumbs[i][0]).childNodes.length; n++) {
				if (document.getElementById(thumbs[i][0]).childNodes[n].nodeName == "H2") {
					try {
						images[i][0] = document.getElementById(thumbs[i][0]).childNodes[n].firstChild.nodeValue;  //Heading data
					}
					catch (error) {
						//Do nothing; the node doesn't exist
					}
				}
				if (document.getElementById(thumbs[i][0]).childNodes[n].nodeName == "P") {
					try {
						images[i][1] = document.getElementById(thumbs[i][0]).childNodes[n].firstChild.nodeValue;  //Paragraph data
					}
					catch (error) {
						//Do nothing; the node doesn't exist
					}
				}
				if (document.getElementById(thumbs[i][0]).childNodes[n].nodeName == "A") {
					if (document.getElementById(thumbs[i][0]).childNodes[n] != exception) {
						try {
							images[i][2] = document.getElementById(thumbs[i][0]).childNodes[n];										//Anchor "href" element
							images[i][3] = document.getElementById(thumbs[i][0]).childNodes[n].firstChild.data;		//Anchor data
						}
						catch (error) {
							//Do nothing; the node doesn't exist
						}
					}
				}
			}	
		}
	}
	
	function getID(obj) {
		for (var i = 0; i < thumbs.length; i++) {
			if (obj.id == thumbs[i][0]) {
				return i;
			}
		}
	}
	
	function getSlide(e) {
		var obj = getEvtParent(e);
		var i = getID(obj);
		if (mainImages[i].height) {
			objImage.style.backgroundImage="url(" + source[i] + ")";
			getThumbs(i);
		}
		else {
			objImage.style.backgroundImage = "none";
			if (document.getElementById(loaderID) == null) {
				objImage.appendChild(createImgElement(loader, loaderAlt, loaderID)); 
			}
			current = i;
			mainImages[i].src = source[i];
		}
	}	
	
	function loadMainImage(evt) {
		objImage.style.backgroundImage="url(" + source[current] + ")";
		objImage.removeChild(document.getElementById(loaderID));
		getThumbs(current);	
	}
	
	function getThumbs(i) {
		current = i;
		var thumb;
		for (var n = 0; n < thumbs.length; n++) {
			if (i == n) {
				thumb = thumbs[n][1];
			}
			else {
				thumb = thumbs[n][2];
			}
			document.getElementById(thumbs[n][0]).style.backgroundImage="url(" + thumb + ")";
		}
		getStory(i);
	}
	
	function getStory(i) {
		if (objStory.hasChildNodes()) {
			removeChildren(objStory, exception);
		}
		appendChildren(objStory, i);
		removeDuplicates(i);
	}
	
	function removeDuplicates(index) {
		for (var i = 0; i < thumbs.length; i++) {
			if (document.getElementById(thumbs[i][0]).childNodes.length == 1) {
				appendChildren(document.getElementById(thumbs[i][0]), i, "hidden");
			}
		}
		removeChildren(document.getElementById(thumbs[index][0]), exception);
	}
		
	function appendChildren(obj, i, cls) {
		var a = createElement("a", images[i][3]);
		a.setAttribute("href", images[i][2].toString());
		if (cls) {
			if (a.getAttribute("className") == null) {  //IE 6 & 7 do not support the "class" attribute
				a.setAttribute("class", cls);
			}
			else {
				a.setAttribute("className", cls);
			}
		}
		obj.appendChild(createElement("h2", images[i][0]));
		obj.appendChild(createElement("p", images[i][1]));
		obj.appendChild(a);
	}
	
	function colorThumb(e) {
		var obj = getEvtParent(e);
		obj.style.backgroundImage="url(" + thumbs[getID(obj)][1] + ")";
	}
	
	function greyscaleThumb(e) {
		var obj = getEvtParent(e);
		var i = getID(obj);
		if (i != current) {
			obj.style.backgroundImage="url(" + thumbs[i][2] + ")";
		}
	}
	
	function getEvtParent(e) {
		if (e.target) {  //Mozilla and WebKit
			obj = e.target.parentNode;
		}
		else {  //IE and Opera
			obj = e.srcElement.parentNode;
		}
		return obj;
	}
	
	function createElement(type, content) {
		var element = document.createElement(type);
		element.appendChild(document.createTextNode(content));
		return element;
	}
	
	function createImgElement(src, alt, id) {
		var element = document.createElement("img");
		element.setAttribute("src", src);
		element.setAttribute("alt", alt);
		element.setAttribute("id", id);
		return element;
	}
	
	function removeChildren(obj, exception) {
		var numChildren = obj.childNodes.length;
		var removalIndex = 0;
		for (var i = 0; i < numChildren; i++) {
			if (obj.childNodes[removalIndex] == exception) {
				removalIndex++;
				continue;
			}
			obj.removeChild(obj.childNodes[removalIndex]);
		}
	}

	function rand(i) {
 		return (Math.floor(Math.random() * i));
	}