	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			};
		}
	}
	
	function stripImgName(blah){

	var thisHref = blah.href;
	
	var hrefArray = thisHref.split("/");
	var secondSplit = hrefArray[hrefArray.length-1].split(".");
	var newHref = "../images/gallery/" + secondSplit[0] + ".jpg";
	
	return newHref;
	
	}
	
	function insertAfter(newElement, targetElement){
		
		var parent = targetElement.parentNode;
		if (parent.lastChild == targetElement) {
			parent.appendChild(newElement);
		} else { parent.insertBefore(newElement,targetElement.nextSibling); }
		
	}
	
	function prepareReplacement() {
		
		if (!document.createElement) { return false; }

		if (!document.getElementById || !document.getElementById('gallery-thumbs')) { return false; }

		var replacement = document.createElement('img');
		replacement.setAttribute('id','replacement');
		replacement.setAttribute('src','../images/gallery/018.jpg');
		replacement.setAttribute('alt','');
		replacement.setAttribute('width','447');
		replacement.setAttribute('height','291');

		document.getElementById('photo_frame').appendChild(replacement);

	}
	
	function prepareThumbs() {
		
		if (!document.createElement) { return false; }
		if (!document.getElementById || !document.getElementById('gallery-thumbs')) { return false; }

		var thumbs = document.getElementById('gallery-thumbs');
		var links = thumbs.getElementsByTagName('a');
		for (var i=0;i<links.length;i++) {
			links[i].onclick = function() { 
				return changePic(this);
			};
		}
	}

	function changePic(whichPic) {
		
		if (!document.getElementById('replacement')) { return true; }
	
	
		var source = stripImgName(whichPic);
		var photo_frame = document.getElementById('photo_frame');
		var replacement = document.getElementById('replacement');
		
		if (replacement.style.display != 'none'){
			photo_frame.style.backgroundImage = 'url(' + source + ')';
			Effect.Fade(replacement);
		} else {
			replacement.setAttribute('src',source);
			Effect.Appear(replacement);
		}
		return false;
	}

	addLoadEvent(prepareReplacement);
	addLoadEvent(prepareThumbs);
