/**
 * $Id: slideshow.js 42 2009-04-26 05:36:39Z iworktoomuch $
 */
PRO.SlideshowInstances = new Array()
PRO.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 = PRO.SlideshowInstances.length;
			PRO.SlideshowInstances[this.id] = this;
		},
		play: function()
		{
			this.interval = setInterval('PRO.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)
			{	
				this.element.childElements()[this.current].fade();
				this.current++;
				if(this.current > (this.slides-1)){ this.current = 0; }
				this.element.childElements()[this.current].appear();
			}
		}
	}
);
PRO.Slideshow.onLoad = function(event)
{
  (new PRO.Slideshow('slideshow',5000)).play();
}
Event.observe(window, 'load', function() { PRO.Slideshow.onLoad() });