addLoadEvent (prepareGallery);

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function prepareGallery() {
	// Check to make sure the browser understands the functions before continuing
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("photoGallery")) return false;
	
	var gallery = document.getElementById("photoGallery");
	var links = gallery.getElementsByTagName("a");
	
	for (var i = 0; i < links.length; i++) {
		links[i].onclick = function() {
			showPhoto(this);
			return false;		
		}
	}
}

function showPhoto(whichPhoto) {
	if (!document.getElementById("placeholder")) return false;
	var source = whichPhoto.getAttribute("href");
	var placeholder = document.getElementById("placeholder");
	placeholder.setAttribute("src", source);
	
	if (!document.getElementById("description")) return false;
	var caption = whichPhoto.getAttribute("title");
	var description = document.getElementById("description");
	description.firstChild.nodeValue = caption;
	
	if (!document.getElementById("photoTitle")) return false;
	var altAttribute = whichPhoto.getAttribute("alt");
	var photoTitle = document.getElementById("photoTitle");
	photoTitle.firstChild.nodeValue = altAttribute;
	
	if (!document.getElementById("hires")) return false;
	sourceHiRes = source.replace("-md", "-hi"); // This is the crazy line.
	hires.setAttribute("href", sourceHiRes);
	
	
}
