//The basic operation of this script is to initialize a lot of variables, then create separate
//timing loops for each of the images on the page which change the image. Aside from this is another
//timing loop which changes the intervals of the image timing loops. It also has an array-shuffling
//function (a Knuth shuffle) and a pop-up window function.

var totalImages = 4; //number of image slots on the page

var changeTimeDelay = 10; //interval between changing the image speeds 
changeTimeDelay *= 400;

var currentTimeDelay = 0; 
var changespeed = new Array(); //this array includes all of the possible speeds of image cycling.
changespeed[0] = .25;
changespeed[1] = .5;
changespeed[2] = 1;
changespeed[3] = 4;
changespeed[4] = 8;
changespeed[5] = .25; //you need at least one for every image on the page. 
changespeed[6] = .5; //having duplicates is not bad though -- it allows two images to have the same speed
changespeed[7] = 1;
changespeed[8] = 4;
changespeed[9] = 8;

var pfiles = new Array (); //image filenames
var pcaption = new Array (); //image pop-up captions

//these can be in any order, but the first ones must correspond with the first images on the page (the defaults).
//otherwise, if the user clicks on them before the first cycle it will not correspond correctly.

i = 0; 
pfiles[i]   = "Hansen-FatManbomb.gif";
pcaption[i] = "Detail of a diagram of the &quot;Fat Man&quot; nuclear weapon drawn by Mike Wagnon for Chuck Hansen's <i>U.S. Nuclear Weapons: The Secret History</i> (1988). Wagnon, in explaining to me how he and Hansen created the diagram, explained that the image and other similar ones in the book &quot;advertise an accuracy they do not have.&quot;";
i++;
pfiles[i] = "Sforza-EthnicRegions.gif";
pcaption[i] = "Computer-generated map of &quot;human genetic diversity&quot; by L. Luca Cavalli-Sforza, et al, 1994. It is an ambiguous racial image&mdash;those who want to see its continuous hues as debunking the concept of biological race do, while others see it as basically supporting a 19th-century typological view of race.";
i++;
pfiles[i] = "StocktonStateHospital.jpg";
pcaption[i] = "A postcard of Stockton State Hospital, postmarked 1908, the year that California's first sterilization law came into effect (but still two years before they would start sterilizing at Stockton, which would come to be the second-largest site of sterilization in the state).";
i++;
pfiles[i] = "RAND-Numbers.gif";
pcaption[i] = "Detail of a page from the RAND Corporation's <i>A Million Random Digits and 100,000 Normal Deviates</i> (1955), the last major list of &quot;random&quot; digits created without the use of pseudo-random algorithms. It was created by use of a specialized computer which simulated taking the numbers off of a roulette wheel.";
i++;
pfiles[i] = "GaltonBertillonRecord.jpg";
pcaption[i] = "A Bertillon record of Sir Francis Galton, pioneer in statistics and founder of eugenics, as taken upon his visit to Alphonse Bertillon's anthropometry laboratory in 1893.";
i++;
pfiles[i] = "Hornig-Patent.gif";
pcaption[i] = "Image from &quot;Low-impedance switch&quot; by Donald Hornig, U.S. Patent # 3,956,658, application filed in secret by the U.S. government in 1945, kept in secret until it was declassified and granted in 1976. It describes a firing switch for an implosion-style nuclear weapon.";
i++;
pfiles[i] = "FWHatch.jpg";
pcaption[i] = "Dr. Frederick Winslow Hatch, Jr., Secretary of the California State Lunacy Commission, and later General Superintendent of State Hospitals, who helped to draft California's first compulsory sterilization law in 1909.";
i++;
pfiles[i] = "NYTbombcasingpictures.jpg";
pcaption[i] = "Photographs of the casings of the atomic bombs dropped on Hiroshima and Nagasaki were not declassified until 1960, and were promptly circulated by news agencies the world over. Here is the top of the article run by the <i>New York Times</i> at the time.";
i++;
pfiles[i] = "FetusComparisonChart.jpg";
pcaption[i] = "An detail from an exhibit at the Second International Congress of Eugenics, 1912, comparing the fetuses of &quot;whites and negros.&quot; Much medical research since the end of the Civil War was devoted to comparative anatomy between races, usually with overtly racist overtones.";
i++;
pfiles[i] = "SeaborgPlutonium.gif";
pcaption[i] = "Image from &quot;Method for Producing, Separating, and Purifying Plutonium&quot; by Glenn Seaborg, et al, U.S. patent # 3,190,804, applied for in secret by the U.S. government in 1945, declassified and granted twenty years later. During World War II the patent was the subject of a bitter fight between the inventors, the University of California, and the Office for Scientific Reserach and Development.";
i++;
pfiles[i] = "SovietEncyclopediaBombs.gif";
pcaption[i] = "These drawings from the 1961 <i>Soviet Encyclopedia</i> depict three types of nuclear weapons (a fission bomb, a fusion bomb, a fusion bomb with a U-238 tamper). They bear little resemblance to depictions of bombs in US sources, and depict a hybrid between a &quot;gun-type&quot; and &quot;implosion-type&quot; bomb design, owing to the radically different contexts in which they were developed.";
i++;
pfiles[i] = "Sterilizationform.gif";
pcaption[i] = "A detail from the California standardized sterilization form, showing some of the criteria under which state hospital patients could be sterilized by the late 1940s: mental disease thought to be inherited, &quot;feeble-mindedness,&quot; &quot;perversion,&quot; or &quot;disease of a syphilitic nature.&quot; Whether the operation would be performed consentually or coercively was a matter of selecting one box over another.";
i++;
pfiles[i] = "OppenheimerContactSheet.gif";
pcaption[i] = "Detail from a contact sheet of a photo session with the enigmatic J. Robert Oppenheimer, &quot;father of the atomic bomb,&quot; <s>photographer unknown</s> photographed by Ulli Steltzer. I found this among the papers of his brother in the Bancroft Library; it evokes for me perfectly the idea that every historian of the bomb has their own Oppenheimer. (I eventually tracked down the authorship to Steltzer, an amazing photographer and a personal friend of the Oppenheimers. In reply to my request for a fresh copy&mdash;which she generously provided&mdash;she replied that: &quot;Never, in the 83 years of my life, have I been asked to sell a proof sheet. After all, it was the one chosen 'ideal' image, well printed, that people were after. Or maybe two.  But you are right, it is impossible to squeeze the whole of Oppenheimer into one ideal image.&quot;)";
i++;
pfiles[i] = "SonomaStateHome.jpg";
pcaption[i] = "The main entrance to Sonoma State Home, California's primary facility for the care of the developmentally disabled and mentally retarded. By 1950 some 5,500 patients had been sterilized at Sonoma; almost one out of every three compulsory sterilizations in California took place there.";
i++;
pfiles[i] = "MendocinoAutopsy.jpg";
pcaption[i] = 'Detail from an <a href="collection" target="_blank">autopsy photograph</a> of a patient who had died in 1899 at the age of 93 from <i>dementia senilis</i>: &quot;Growing from the inner table, just anterior to the coronal suture and 2 cm. from the median line on the right, was the tumour the size of a large English walnut, projecting downward into and backward, or perpendicular to the point of attachment to the skull.&quot;';
i++;
pfiles[i] = "HBombCensoredPage.gif";
pcaption[i] = "Detail from a censor-ravaged page from a report by Hans Bethe on the development of the H-bomb. Declassified documents become as much about what is missing as what is there; for the viewer, every DELETED may indicate the greatest of state secrets, or it may indicate the banality of bureaucratic arbitrariness.";
i++;
pfiles[i] = "GaltonRandomDice.jpg";
pcaption[i] = "One of Sir Francis Galton's specially-made dice from 1890, for performing &quot;random number&quot; generation. Though his system would probably have done a fine job for Victorian statisticians, none are known to have adopted it: one was required to roll three dice in order to get one &quot;random number,&quot; which would have made it laborious work by any definition.";
i++;
pfiles[i] = "AtomSuspicion.gif";
pcaption[i] = 'Detail from a 1947 cartoon from the <i>Washington Post</i> about &quot;<a href="atom" target="_blank">How to Live With Atom</a>&quot;: <i>Now our halo is starting to wilt. It is beginning to dawn on us that we are walking in a world of fear and suspicion. Our Atom Bomb is not helping matters any.</i>';
i++;
pfiles[i] = "Darwin.jpg";
pcaption[i] = 'A very troubled looking Charles Darwin, age 51, around the time he was forced into the publication of <i>On the Origin of Species</i>.';
i++;
pfiles[i] = "Rapatronic.jpg";
pcaption[i] = 'A high-speed Rapatronic photograph of the first microseconds of a thermonuclear explosion. Under the scrutiny of a high speed lens what initially appears to be a homogenous blast is seen instead to be variable, textured, and with an almost organic appearance.';
i++;
pfiles[i] = "BradburyGadget.jpg";
pcaption[i] = 'Physicist Norris Bradbury and engineer Boyce McDaniel stand on the &quot;Trinity&quot; shot tower in front of the nearly-assembled prototype of the first atomic bomb. The faux smugness on their faces, as they lean on the rails of a precariously high tower, next to an un-tested ad hoc contraption which would be an impressive amount of explosives even without a nuclear core, makes for a fascinating photograph.<br>(<a href="http://atomlandonmars.com" target="_blank">More like this.</a>)';
i++;
pfiles[i] = "KodakFilmFogged.jpg";
pcaption[i] = 'Film fogged by contaminated water from the first nuclear test, 1945. Sent to General Groves from Kodak Eastman, "Show to Dr. Opp," written on the envelope.';
i++;
pfiles[i] = "DixieDancer.jpg";
pcaption[i] = 'A Las Vegas showgirl doing a kick at the Nevada Test Site, with the mushroom cloud from the Upshot-Knothole DIXIE shot behind her, April 1953.<br>(<a href="http://atomlandonmars.com" target="_blank">More like this.</a>)';
i++;
pfiles[i] = "GreenglassDiagram.jpg";
pcaption[i] = 'David Greenglass\'s "sketch of the very atomic bomb itself," revealing the secret of plutonium implosion publicly for the first time during the trial of Julius and Ethel Rosenberg.<br>(<a href="http://atomlandonmars.com" target="_blank">More like this.</a>)';

var intervalIDs = new Array();
var Pix = new Array (new Array ());
var howMany = pfiles.length;
var PicCurrentNum = new Array();
var PicCurrent = new Array();
var emptyArray = new Array(new Array()); //these arrays are just because javascript has some "issues" with multi-dimensional array handlings.
var blankArray = new Array();

for(a=0;a<howMany;a++) {
	blankArray[a] = a;
};
for(i=0;i<totalImages;i++) {
	emptyArray[i] = blankArray;
};

for(i=0;i<totalImages;i++) { //initialize image cycling arrays
	Pix[i] = arrayshuffle(emptyArray[i]);
	PicCurrentNum[i]=-1;
	PicCurrent[i]= new Image();
	PicCurrent[i].src = "imagecycle/" + pfiles[Pix[i][0]];
};

function startPix() { //initialize the slideshow (this is launched by the "onload" in the <body> tag)
	changespeed = arrayshuffle(changespeed);
	for (i=0;i<totalImages;i++) {
		thisDelay = changespeed[i];
		thisDelay *= 400;
		intervalIDs[i] = setInterval("slideshow(" + i + ")", thisDelay); //set a new image interval, save the interval ID so we can clear it later
	};
	setInterval("changedelays()", changeTimeDelay); //this is the main interval which changes the image intervals
}

function changedelays() { //changes the slideshow delay intervals
	var ii;
	changespeed = arrayshuffle(changespeed);
	for (ii=0;ii<totalImages;ii++) {	
		thisDelay = changespeed[ii];
		thisDelay *= 400;
		clearInterval(intervalIDs[ii]); //clear the old interval
		intervalIDs[ii] = setInterval("slideshow("+ii+")", thisDelay); //create a new one
	};
}

function slideshow(x) { //main image changing function
	PicCurrentNum[x]++;
	if (PicCurrentNum[x] == howMany) {
		PicCurrentNum[x] = 0;
	};
	PicCurrent[x].src = "imagecycle/" + pfiles[Pix[x][PicCurrentNum[x]]];
	document["ChangingPix[" + x + "]"].src = PicCurrent[x].src;
}

function arrayshuffle(shuffarray) { //array shuffler -- reorders the contents of an array randomly
	var thisarray = new Array();
	var cc; var xx; var bb;
	for(cc=0;cc<shuffarray.length;cc++) { //this is because javascript's multidimensional array handling has "issues" otherwise
		thisarray[cc] = shuffarray[cc];
	};	
	xx = thisarray.length-1;
	for(bb=0;bb<=xx;bb++){
		Temp = thisarray[bb];
		RandomElem = Math.floor(Math.random() * (xx+1));
		thisarray[bb]=thisarray[RandomElem];
		thisarray[RandomElem] = Temp;
	};
	return thisarray;
};

function imgdetail(i) { //image pop-up caption function
	var winHeight = 360;
	var winWidth = 500;
	var leftVal = (screen.width-winWidth) / 2;
	var topVal = (screen.height-winHeight) / 2;
	var imgnum = Pix[i][PicCurrentNum[i]];
	if(imgnum==undefined) { imgnum = i; };
	
	var imgwindow = window.open('','popupimage','height='+winHeight+',width='+winWidth+',left=' + leftVal + ',top=' + topVal+',menubar=no,status=no');
	imgwindow.document.clear();
	imgwindow.document.write('<html><head><title>Image </title></head>\n');
	imgwindow.document.write('<body bgcolor="#1E1E1E" link="AAAADD" vlink="#2962a3" alink="#2962a3">');
	imgwindow.document.write('<center><br>\n');
	imgwindow.document.write('<table width="80%"><tr><td align="center">');
	imgwindow.document.write('<img src="imagecycle/'+pfiles[imgnum]+'" border="1" height="200" width="300">\n');
	imgwindow.document.write('</td></tr><tr><td align="center">\n');
	imgwindow.document.write('<font face="Arial" size="-1" color="#DDDDDD">');
	imgwindow.document.write(pcaption[imgnum]);
	imgwindow.document.write('</font>\n');
	imgwindow.document.write('</td></tr></table>\n');
	imgwindow.document.write('</body></html>');
	imgwindow.document.close();
	
};