$(document).ready(function(){
	numberofimages = 5; // this tells the slideshow how many images to cycle through before returning to 1.jpg
	switchtime = 7500; // this says how long (1000 = 1 second) to stay on each image
	fadetime = 2500; // this says how long (1000 = 1 second) the fade transition will last
	
	// do not change these values - they must be set to this for the gallery to function correctly.
	currentimage = 1; nextimage = 2; imageshowing = 1; imagehidden = 2;
					
	$("#container").everyTime(switchtime,function() {										
		$("img." + imagehidden).fadeIn(fadetime);
		$("img." + imageshowing).fadeOut(fadetime, reset);
	});

	function reset() {
		// this code switches the values of imageshowing and imagehidden, so the correct images are faded in and out next time
		var temp = imagehidden;
		imagehidden = imageshowing;
		imageshowing = temp;
		
		// this code calculates and sets the next image onto the image that is currently hidden
			// this code has moved to here, because before we were calculating directly before displaying the image
			// which in some cases (ie6) meant there was a flicker as the image was fading in before it had been loaded
		currentimage = nextimage;
		nextimage++;
		if (nextimage > numberofimages) {nextimage = 1}

		$("." + imagehidden + "").attr("src","/files/bgs/gallery/" + nextimage + ".jpg");
	}	

	
});