var wnSlideshow = new Class({
	Implements: [Options, Events],
	options: {
		slideshowElement: 'li',
		effectSpeed: 1000,
		imageChangeSpeed: 4000
	},
	initialize: function(wrapper, options){
		this.setOptions(options);
		this.childs = $$(wrapper+' '+this.options.slideshowElement);
		this.childsCount = this.childs.length;
		this.hideItems();
		this.rotate();
		this.currentIndex = 0;
	},
	hideItems: function(){
		var counter = this.childsCount;
		this.childs.each(function(el, i){
			el.setStyles({
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				'zIndex': counter,
				'opacity': 1
			});
			counter--;
		}, this);
	},
	rotate: function() {
		var show = function() {
			if(this.currentIndex == this.childsCount) {
				this.hideItems();
				this.currentIndex = 0;
			} else if(this.currentIndex == this.childsCount-1) {
				this.childs[0].setStyles({
					'opacity': '1',
					'zIndex': 0
				});
			}
			var effect = new Fx.Tween(this.childs[this.currentIndex], {
				property: 'opacity',
				duration: this.options.effectSpeed,
				onComplete: function() {
			
				}
			});
			effect.start(1,0);
			this.currentIndex++;
		}.bind(this);
		this.interval = show.periodical(this.options.imageChangeSpeed);
	}
});

window.addEvent('domready', function(){
	new wnSlideshow('#slideshow');
});
