// *******************************************************************
// Random Book Loader Script
// by Lesa Bellevie (http://www.magdalene.org)
// copyright, 2006

// You may reuse this script as long as it retains the copyright info
// above. This script randomly generates four books from an array,
// displaying an image for each, and linking to Amazon.com with the
// appropriate ISBN information. Checking is included to eliminate
// duplicates in the random picks.

// To add a new book to the rotation, first add it to a new line in
// the array below. Then update the randomPicks() function and the
// randomPickOne() function. Instructions below.

// In the array below, simply create a new line with the next number
// in the series list. Then add the path to the book image (height
// should equal 93 pixels), and then the ISBN. These two things
// need to be separated by a comma. Upload the picture to the 
// images/ads directory.

// This script is for the front page ONLY. The sidebar random load script
// is contained in sidebar include files.

// Last updated: 05/24/06
// *******************************************************************


function pickArrays() {

myBooks = new Array();
myBooks[0] = "images/ads/brock_sm.jpg,0674009665";
myBooks[1] = "images/ads/george_sm.jpg,0142002798";
myBooks[2] = "images/ads/king_sm.jpg,0944344585";
myBooks[3] = "images/ads/starbird1_sm.jpg,1879181037";
myBooks[4] = "images/ads/starbird2_sm.jpg,187918155X";
myBooks[5] = "images/ads/starbird3_sm.jpg,1591430127";
myBooks[6] = "images/ads/starbird4_sm.jpg,1591430542";
myBooks[7] = "images/ads/burstein_sm.jpg,1593150229";
myBooks[8] = "images/ads/kinstler_sm.jpg,0062504975";
myBooks[9] = "images/ads/cunningham1_sm.jpg,158177060X";
myBooks[10] = "images/ads/brown_sm.jpg,0385504209";
myBooks[11] = "images/ads/longfellow_sm.jpg,0975925539";
myBooks[12] = "images/ads/deboer1_sm.jpg,1563382121";
myBooks[13] = "images/ads/jansen_sm.jpg,0691089876";
myBooks[14] = "images/ads/robinson_sm.jpg,0060669357";
myBooks[15] = "images/ads/pagels_sm.jpg,0679724532";
myBooks[16] = "images/ads/good_sm.jpg,0253345332";
myBooks[17] = "images/ads/jones_sm.jpg,1589830431";
myBooks[18] = "images/ads/haskins_sm.jpg,1573225096";
myBooks[19] = "images/ads/leloup_sm.jpg,0892819111";
myBooks[20] = "images/ads/ricci_sm.jpg,0800627180";
myBooks[21] = "images/ads/maisch_sm.jpg,0814624715";
myBooks[22] = "images/ads/schaberg_sm.jpg,0826413838";
myBooks[23] = "images/ads/apost-capp_sm.jpg,1585166456";
myBooks[24] = "images/ads/deboer2_sm.jpg,0826480012";
myBooks[25] = "images/ads/cig_sm.jpg,1592573452";
myBooks[26] = "images/ads/cig_sm.jpg,1592573452";
myBooks[27] = "images/ads/ehrman_sm.jpg,0195300130";
myBooks[28] = "images/ads/cunningham2_sm.jpg,0976684306";

randomImages = new Array();
randomImages[0] = "";
randomImages[1] = "";
randomImages[2] = "";
randomImages[3] = "";

randomISBNs = new Array();
randomISBNs[0] = "";
randomISBNs[1] = "";
randomISBNs[2] = "";
randomISBNs[3] = "";


//for (i=0; randomISBNs[3] == ""; i++) {

	randomPicks();

//}

loadResults();

}


function dupCheck() {

for (i=0; i <= 3; i++) {

	if (randomImages[0] == randomImages[i] && i != 0) {
		randomPickOne(0);
	}

	if (randomImages[1] == randomImages[i] && i != 1) {
		randomPickOne(1);
	}

	if (randomImages[2] == randomImages[i] && i != 2) {
		randomPickOne(2);
	}

	if (randomImages[3] == randomImages[i] && i != 3) {
		randomPickOne(3);
	}

}

}

// *******************************************************************
// To add a new book to the rotation, first add it to the array above, 
// and then increment the Math.random method below with the new number 
// of items in the array.
// *******************************************************************

function randomPicks() {

currentIndx = 0;

arrayString = "";

for (x=0; x <= 3; x++) {

	currentIndx=Math.round(Math.random()*28);

	arrayString = myBooks[currentIndx];
	tempArray = arrayString.split(",");

	randomImages[x] = tempArray[0];
	randomISBNs[x] = tempArray[1];

}

dupCheck();

}

// *******************************************************************
// To add a new book to the rotation, first add it to the array above, 
// and then increment the Math.random method below with the new number 
// of items in the array.
// *******************************************************************

function randomPickOne(i) {

currentIndx = 0;

currentIndx=Math.round(Math.random()*28);

arrayString = myBooks[currentIndx];
tempArray = arrayString.split(",");

randomImages[i] = tempArray[0];
randomISBNs[i] = tempArray[1];

}


function loadResults() {

document.all.myImage1.src = randomImages[0];
document.all.myImage2.src = randomImages[1];
document.all.myImage3.src = randomImages[2];
document.all.myImage4.src = randomImages[3];

document.all.myISBN1.href = "http://www.amazon.com/exec/obidos/ASIN/" + randomISBNs[0] + "/magdaleorgbookli/?v=glance&s=books";
document.all.myISBN2.href = "http://www.amazon.com/exec/obidos/ASIN/" + randomISBNs[1] + "/magdaleorgbookli/?v=glance&s=books";
document.all.myISBN3.href = "http://www.amazon.com/exec/obidos/ASIN/" + randomISBNs[2] + "/magdaleorgbookli/?v=glance&s=books";
document.all.myISBN4.href = "http://www.amazon.com/exec/obidos/ASIN/" + randomISBNs[3] + "/magdaleorgbookli/?v=glance&s=books";

}