addOnload(initOne);
addOnload(initTwo);
addOnload(initThree);

function addOnload(newFunction) {
	var oldOnload = window.onload;
	
	if (typeof oldOnload == "function") {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			newFunction();
		}
	}
	else {
		window.onload = newFunction;
	} 
}


function initOne() {
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].parentNode.tagName == "A") {
			setupRollover(document.images[i]);
		}
	}
}

function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = function() {
		this.src = this.outImage.src;
	}

	thisImage.overImage = new Image();
	thisImage.overImage.src = "images/" + thisImage.id + "_on.jpg";
	thisImage.onmouseover = function() {
		this.src = this.overImage.src;
	}
}



function initTwo() {
	var myPix = new Array("images/header/header1.jpg","images/header/header2.jpg","images/header/header3.jpg", "images/header/header4.jpg", "images/header/header5.jpg", "images/header/header6.jpg", "images/header/header7.jpg", "images/header/header8.jpg", "images/header/header11.jpg", "images/header/header10.jpg", "images/header/header9.jpg", "images/header/header12.jpg", "images/header/header13.jpg", "images/header/header17.jpg","images/header/header18.jpg", "images/header/header19.jpg", "images/header/header20.jpg", "images/header/header21.jpg", "images/header/header22.jpg", "images/header/header22.jpg", "images/header/header23.jpg", "images/header/header24.jpg",  "images/header/header25.jpg");
	var randomNum = Math.floor((Math.random() * myPix.length));
	document.getElementById("myPicture").src = myPix[randomNum];
}

function initThree() {
	var myPix = new Array("images/frontpage/fp1.jpg","images/frontpage/fp2.jpg","images/frontpage/fp3.jpg", "images/frontpage/fp4.jpg");
var thisPic = 0;

function initLinks() {
	document.getElementById("prevLink").onclick = processPrevious;
	document.getElementById("nextLink").onclick = processNext;
}

function processPrevious() {
	if (thisPic == 0) {
		thisPic = myPix.length;
	}
	thisPic--;
	document.getElementById("myPicture").src = myPix[thisPic];
	return false;
}

function processNext() {
	thisPic++;
	if (thisPic == myPix.length) {
		thisPic = 0;
	}
	document.getElementById("myPicture").src = myPix[thisPic];
	return false;
}
}
