var SlideshowInstances = new Array()
var Slideshow = Class.create
(
	{
		initialize: function(id,delay)
		{	
			this.element = $(id);
			this.slides = this.element.childElements().length;
			this.current = 0;
			this.interval = null;
			this.delay = (delay) ? delay : 5000;
			this.isPlaying = false;
			
			this.id = SlideshowInstances.length;
			SlideshowInstances[this.id] = this;
		},
		play: function()
		{
			this.interval = setInterval('SlideshowInstances['+this.id+'].advance()',this.delay);
			this.isPlaying = true;
		},
		stop: function()
		{
			clearInterval(this.interval);
			this.isPlaying = false;
		},
		toggle: function()
		{
			if(this.isPlaying) {
				this.stop();
			} else {
				this.play();
			}
		},
		advance: function()
		{
			if(this.slides > 1)
			{	
				Effect.Fade(this.element.childElements()[this.current]);
				this.current++;
				if(this.current > (this.slides-1)){ this.current = 0; }
				Effect.Appear(this.element.childElements()[this.current]);
			}
		}
	}
);
Slideshow.onLoad = function(event)
{
  (new Slideshow('slideshow',6000)).play();
}
Event.observe(window, 'load', function() { Slideshow.onLoad() });