window.onload = rolloverInit;

function rolloverInit() {
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].parentNode.tagName == "A") {
			if(document.images[i].className == 'roll') {
				setupRollover(document.images[i]);
			} else if (document.images[i].className == 'bookcovers') {
				setupBookcovers(document.images[i]);
			}
		}
	}

}

function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;

	thisImage.overImage = new Image();
	thisImage.overImage.src = "imgs/" + thisImage.id;
	thisImage.onmouseover = rollOver;
}

function setupBookcovers(thisImage) {
	thisImage.clickImage = new Image();
	thisImage.clickImage.src = "imgs/" + thisImage.id;
	thisImage.onclick = onBookClick;
}


function rollOut() {
	this.src = this.outImage.src;
}

function rollOver() {
	this.src = this.overImage.src;
}

function onBookClick() {
	document.getElementById('book').src = this.clickImage.src;
}