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