var ImageFaderOO = new Class({
	Implements: [Options, Events, Object],
	options:{
		images : ["1", "2", "3","4", "5","6","7", "8", "9", "10", "11", "12", "13", "14"],
		container : 'slideshow',
		dir : 'homepage_slideshow'
	},
	initialize: function(options){
		this.setOptions(options);
		this.last_image = 0;
		this.image_array = new Array();


		this.insertImages();
		this.switchImage.periodical(6000, this)
		//console.log(this.options.images)
	},
	insertImages : function () {
		this.options.images.each(function (image){
			var myImage = new Element('img', {'src':'webroot/img/'+this.options.dir+'/'+image+'.jpg', 'class':'slide'}).setStyle('opacity',0)
			$(this.options.container).adopt(myImage);
			this.image_array.push(myImage);
			//console.log(this.image_array)
		}.bind(this))
	},
	switchImage : function () {
		//console.log(this.options.images.length);
		if(this.last_image+1>=this.options.images.length){
			this.current_image = 0;
		}else{
			this.current_image = this.last_image+1;
		}
		this.showImage();
		this.hidePreviousImage.delay(500,this)
	},
	showImage : function () {
		this.image_array[this.current_image].tween('opacity',1)
	},
	hidePreviousImage : function () {
		this.image_array[this.last_image].tween('opacity',0)
		this.last_image = this.current_image
	}
})
