var SlideShow = new Class({
	initialize: function(id, pause) {
		// Save the id of the slideshow div and the pause interval.
		this.divId = id;
		this.interval = pause.toInt();
		
		// Setup the images array.
		this.images = new Array();
		$$('div#' + id + ' > img').each(function(item, index) {
			this.images.include(item);
			item.set('tween', {duration: 'long'})
			item.fade('hide');
		}, this);
		
		// Initialize the slide counter.
		this.nextImage = 0;
		
		// Start the show! (Skip the interval the first time.)
		this.slide();
		this.timer = this.slide.periodical(this.interval, this);
	},
	slide: function()
	{
		// First make sure we're within the bounds of the images array.
		this.nextImage = this.nextImage < this.images.length ? this.nextImage : 0;
		
		// Check to see if there is an image currently being displayed (fade out if so).
		if (this.currentImage)
			this.currentImage.fade('out');
		
		// Fade the next image in.
		this.images[this.nextImage].fade('in');
		
		// Remember to save the current image for next time.
		this.currentImage = this.images[this.nextImage];
		
		// Finally, increase the slide counter.
		this.nextImage++;
	},
	stop: function()
	{
		clearInterval(this.timer);
	}
});

window.addEvent('domready', function() {
	myShow = new SlideShow('slideshow', 5000);
});
