// JavaScript random image display with links, alt and title attributes
// Roland Jaeckel, 4/7/2004
// Image definition:
// image name pipe (|) URL pipe (|) alt/title attribute
// define number of random images - if images are arranged in descending order
// setting the number to less than the number of icons will make the first n icons static
var numImages = 8;
var ranImage = new Array;
ranImage[0] = 'bioinfo|http://bioinfo.bu.edu|Bioinformatics at Boston Univeristy';
ranImage[1] = 'bme|http://www.bu.edu/dbin/bme/|Department of Biomedical Engineering';
ranImage[2] = 'asor|http://www.asor.org|American Schools of Oriental Research';
ranImage[3] = 'biosquare|http://www.biosquare.org|Bio Square';
ranImage[4] = 'building|http://building.bu.edu|BU Student Village';
ranImage[5] = 'cogneuro|http://www-cogneuro.bu.edu|Laboratory of Cognitive Neurobiology';
ranImage[6] = 'dentalschool|http://dentalschool.bu.edu/|Goldman School of Dental Medicine';
ranImage[7] = 'ece|http://www.bu.edu/dbin/ece/web/|Department of Electrical and Computer Engineering';
ranImage[8] = 'electrostatics|http://www.electrostatics.org/|Electrostatics Society of America';
ranImage[9] = 'favoritepoem|http://www.favoritepoem.org/|Favorite Poem Project';
ranImage[10] = 'fhcmi|http://www.fhcmi.org/|Fraunhofer Center for Manufacturing Innovation';
ranImage[11] = 'icshm|http://icshm.bu.edu/|International Conference of the Science of Hard Materials';
ranImage[12] = 'ikoncopy|http://www.bu.edu/ikoncopy/|Boston University Imagexpress';
ranImage[13] = 'linux|http://linux.bu.edu/|Linux at BU';
ranImage[14] = 'met|http://www.bu.edu/met/|Metropolitan College';
ranImage[15] = 'literary|http://www.bu.edu/literary/|Association of Literary Scholars and Critics';
ranImage[16] = 'mfg|http://mfg.bu.edu/|Department of Maufacturing Engineering';
ranImage[17] = 'partisanreview|http://www.partisanreview.org/|Partisan Review';
ranImage[18] = 'photonics|http://www.thephotonicscenter.com/|The Photonics Center at BU';
ranImage[19] = 'voting|http://www.kidsvotingmass.org/|Kids Voting Massachusetts';

// shuffle with Fisher Yates algorithm
fisherYates(ranImage);
var i = 0;

// read source from sp00 image
var path=new String(document.images['sp00'].src);

// get the path to the graphics folder
path = path.substring(0,path.lastIndexOf("/")+1);
while (i<numImages){
	// split info on pipe
	var tempArray = ranImage[i].split("|")
	// set image
	document.images['sp0'+i].src = path+tempArray[0]+'.gif'; 
	// set link and get it as object by id
	thisLink = document.getElementById('sp10'+i);
	thisLink.href = tempArray[1];
	// set alt attribute and title attribute
	document.images['sp0'+i].setAttribute('alt',tempArray[2]);
	document.images['sp0'+i].setAttribute('title',tempArray[2]);
	i++;
}		


// Fisher-Yates randomize shuffle
function fisherYates ( myArray ) {
  var i = myArray.length;
  while ( i-- ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}