/* slides.js  
 Script to display random images from the 'slides' folder

 0.1 Nov 2009 Demian Dixon - Initial Version.  3 images
 0.2 Jul 2010 Demian Dixon - changed to a single image, border now css controlled. 
 0.3 Aug 2010 Demian Dixon - removed reference to multiple images to fix IE6 problem
*/

var delay=6000;   //set image refresh delay in milliseconds
var numimages=15;  //number of images to use
var height=330;   //height of image
var width=510;    //width of image

var curindexa=0;
var randomimages = [];  //randomimages array is a list of filenames that reference our images

for (i=1; i<numimages+1; i++) 
	{
	randomimages[i-1] = "slides/" + i + ".jpg" //As we are adding strings the 'i' variable is changed to a string
	}
                                                   
// We don't need to preload images as there are too many
/* var preload=new Array();
for (n=0;n<randomimages.length;n++) 
	{
	preload[n]=new Image();
	preload[n].src=randomimages[n];
	} 
*/

// The <IMG NAME=> tag is used to reference the image for use in scripts. ie. so we can rotate it
// Initialise the first image and display

document.write('<img name="defaultimagea" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]
	+'"  height='+height+' width='+width+' alt="PhotoGallery">');

/* Get the next random image number (tempindexa), if it's the same image number as we are already showing then 
return the image number - 1 unless we are on image number 0 in which case return image 1. */

function rotateimage() 
	{
	if (curindexa==(tempindexa=Math.floor(Math.random()*(randomimages.length))))
		{
		//Conditional - set curindexa to either '1' (if curindexa is 0) or curindexa - 1
		curindexa = (curindexa == 0) ? 1 : curindexa-1; 
		}
	else
                {
		curindexa=tempindexa;
		}
	document.images.defaultimagea.src=randomimages[curindexa];  //Update the image with the next one
	}

setInterval("rotateimage()",delay);

