var Gallery = Class.create();
Gallery.prototype = {
	initialize: function(element) {
		this.options = Object.extend({
			milliseconds: 5000
		}, arguments[1] || {});
		this.element = $(element);
		this.images = new Array();
		this.loop = 0;
	},
	add: function(url) {
		this.images.push(url);
	},
	start: function() {
		this._startTimeForNext();
	},
	_showNext: function() {		
		this._fade({
			afterFinish: function() {
				this.loop++;
				this._appear({
					afterFinish: this._startTimeForNext.bind(this)
				});
			}.bind(this)
		});
	},
	_startTimeForNext: function() {
		setTimeout(this._showNext.bind(this), this.options.milliseconds);
	},
	_fade: function() {
		var options = arguments[0] || {};
		new Effect.Fade(this.element, options);
		//this.element.hide();
		//if(options.afterFinish) options.afterFinish();
	},
	_appear: function() {
		var options = arguments[0] || {};
		this.element.src = this.images[this.loop % this.images.length];
		new Effect.Appear(this.element, options);
		//this.element.show();
		//if(options.afterFinish) options.afterFinish();
	}
};    