var Slideshow = {
	// url that lists all the image paths
	url: "/slideshow.php",
	
	// id of the slideshow div tag
	id:  "slideshow",
	
	// give the slideshow/image dimensions for better pre-loading
	width:  750,
	height: 250,
	
	// slide show cycle speen in seconds
	cycleSpeed: 5,
	
	// define some vars for use later on, leave these alone
	count:   0,
	aFiles:  new Array(),
	aImages: new Array(),

	startup: function() {
		new Ajax.Request(Slideshow.url, {
			method: 'get',
			onSuccess: function(data) {
			
				// create image holder div
				$(Slideshow.id).innerHTML = '';
				Slideshow.div = new Element("div");
				$(Slideshow.id).insert(Slideshow.div);
			
				// get file list into array
				Slideshow.aFiles = $w(data.responseText);
				
				// preload each image
				Slideshow.aFiles.each(function(imgsrc, index) {
					img = new Image(Slideshow.width, Slideshow.height);
					img.src = imgsrc;
					Slideshow.aImages[index] = img;
					
					if(index == 0) {
						// show first image before pre-loading the rest
						$(Slideshow.div).appendChild(Slideshow.aImages[Slideshow.count]);
					}
				});
				
				// start the slide show
				new PeriodicalExecuter(Slideshow.cycle, Slideshow.cycleSpeed);
			}
		});
	},
	
	cycle: function() {
		new Effect.Fade(Slideshow.div, {
			duration: 1, 
			fps: 50, 
			afterFinish: function() {
				Slideshow.count++;
				if(Slideshow.count > Slideshow.aImages.length-1) Slideshow.count = 0;
				
				// swap out the image with the next one
				$(Slideshow.div).innerHTML = '';
				$(Slideshow.div).appendChild(Slideshow.aImages[Slideshow.count]);
				
				new Effect.Appear(Slideshow.div, {
					duration: 1,
					fps: 50,
					queue:'end'
				});
			}
		});
	}
}

window.onload = Slideshow.startup;