// Written by Rafael 10-15-03

// variables that may need to be updated
var delay = 10000; // this is the pause in between picture changes, counted in milliseconds
var number_pictures = 59; // if you add more pictures to the array, update this
var number_pictures_displayed = 4; // this is the number of pictures that are actually displayed
var picture_path = '/images/slideshow/'; // path to picture folder from root

// create array of pictures that we can use
var picture = new Array(number_pictures);
picture[0] = 'a-bomb.jpg';
picture[1] = 'abortion.jpg';
picture[2] = 'adams.jpg';
picture[3] = 'arafat.jpg';
picture[4] = 'arlington2.jpg';
picture[5] = 'beakers.jpg';
picture[6] = 'boys_with_bread.jpg';
picture[7] = 'buddha.jpg';
picture[8] = 'capitol_ok.jpg';
picture[9] = 'wtc.jpg';
picture[10] = 'castro.jpg';
picture[11] = 'che.jpg';
picture[12] = 'child1.jpg';
picture[13] = 'child2.jpg';
picture[14] = 'china_flag.jpg';
picture[15] = 'dalailama.jpg';
picture[16] = 'dna.jpg';
picture[17] = 'dome_of_the_rock.jpg';
picture[18] = 'fighter1.jpg';
picture[19] = 'furismurder.jpg';
picture[20] = 'ghandi1.JPG';
picture[21] = 'handcuffs.jpg';
picture[22] = 'hueys.jpg';
picture[23] = 'woman.jpg';
picture[24] = 'jetfighter.jpg';
picture[25] = 'kofi.jpg';
picture[26] = 'mandela1.jpg';
picture[27] = 'marijuana.jpg';
picture[28] = 'mlk.jpg';
picture[29] = 'Muslimwomen1.jpg';
picture[30] = 'navyhelicopter.jpg';
picture[31] = 'navyships.jpg';
picture[32] = 'oil1.JPG';
picture[33] = 'Petriedish.jpg';
picture[34] = 'pills.jpg';
picture[35] = 'pope1.jpg';
picture[36] = 'powerplant1.jpg';
picture[37] = 'putin.jpg';
picture[38] = 'rainbowflag.jpg';
picture[39] = 'redcross1.jpg';
picture[40] = 'riot1.jpg';
picture[41] = 'riotpolice.jpg';
picture[42] = 'rosa_parks.jpg';
picture[43] = 'scales.jpg';
picture[44] = 'scientist.jpg';
picture[45] = 'sharon.jpg';
picture[46] = 'skeletons.jpg';
picture[47] = 'soldier1.JPG';
picture[48] = 'starwarsprotest1.jpg';
picture[49] = 'st_basils_cathedral.jpg';
picture[50] = 'supreme_court.jpg';
picture[51] = 'tienanmen.jpg';
picture[52] = 'un_crest.JPG';
picture[53] = 'unhcr_truck.jpg';
picture[54] = 'vietcong.jpg';
picture[55] = 'vietnamgi.jpg';
picture[56] = 'vietnamprotest.jpg';
picture[57] = 'columns_ok.jpg';
picture[58] = 'drilling_platform.jpg';
// if you add more pictures to the array, update number_pictures variable
// and keep in mind that you're starting at 0 (if the last number in the array is a 10, the number_pictures should be 11)
// and keep in mind that unix is case sensitive (.JPG is NOT the same as .jpg)

// variables
var display_id = new Array(number_pictures_displayed);
var last_picture = number_pictures - 1;
var is_dupe;

// pick initial pictures
for(i=0;i<number_pictures_displayed;i++) {
	is_dupe = true;
	while(is_dupe) {
		is_dupe = false;
		// pick random picture
		display_id[i] = Math.round(Math.random( ) * last_picture);
		// compare to existing ones
		for(j=i-1;j>=0;j--) {
			if(display_id[j] == display_id[i]) {
				is_dupe = true;
			}
		}
	}
}
	
// function that updates the images and calls itself again after the specified delay
function rotate_em( )
{
	// randomly pick a new image from the array and keep picking until it's one we don't have already
	var display_id_new;
	is_dupe = true;
	while(is_dupe) {
		is_dupe = false;
		// pick randomly
		display_id_new = Math.round(Math.random( ) * last_picture);
		// compare the one we just picked to the existing ones
		for(i=0;i<number_pictures_displayed;i++) {
			if(display_id_new == display_id[i]) {
				is_dupe = true;
			}
		}
	}
		
	// randomly pick which displayed image we'll update
	var random_img_id = Math.round(Math.random( ) * (number_pictures_displayed - 1));

	// update array
	display_id[random_img_id] = display_id_new;
	
	// update site
	var tag = document.getElementById("img_id_" + random_img_id);
	tag.src = picture_path + picture[display_id_new];
	setTimeout("rotate_em( )",delay)
}

// output initial images and call the rotate_em( ) function
for(i=0;i<number_pictures_displayed;i++) {
	document.write('<img src="' + picture_path + picture[display_id[i]] + '" id="img_id_' + i + '">');
}
rotate_em( );
