/**
 * Create a slideshow using the subelements of the passed element
 */
var Slideshow = new Class({
	initialize: function (element, timeout) {
		this.element = $(element);
		this.elements = $ES('div', element);
		this.count = this.current = this.elements.length;
		this.timeout = timeout;
		this.trigger.delay(this.timeout, this);
	},
	trigger: function() {
		this.elements.each(
			function (el) {
				el.removeClass('hidden');
			}
		);

		if (this.current == 1) {
			this.current = this.count;
			var fx = new Fx.Styles(this.elements[this.current - 1], {duration: this.timeout / 2, wait:true});
			fx.start({
				'opacity':'1'
			});
		} else {
			// Set previous invisible
			if (this.current > 1)
			{
				this.elements[this.current - 2].setStyle('opacity', '1');
			}
			var fx = new Fx.Styles(this.elements[this.current - 1], {duration: this.timeout / 2, wait:true});
			fx.start({
				'opacity':'0'
			});
			this.current--;
		}
		this.trigger.delay(this.timeout, this);
	}
});