/* */
		
var Slideshow = new Class({
	Implements: [Events, Options, Chain],
	options: {
		'current_position': 1, 
		'timeout': 4000, 
		'duration': 500,
		'opacity': 1
	},
	transitions: {},
	initialize: function(list, options){
		this.setOptions(options);
		this.list = $$(list);
		this.itemPrefix = list + 'item';
		
		// AlleItems initialisieren
		var self = this; 
		this.list.each(function(item, i){
			var _index = item.id = self.itemPrefix + (i+1) ;
			item.setStyle('z-index', ((i+1) == self.options.current_position) ? 1 : 0);
			item.setStyle('visibility', ((i+1) == self.options.current_position) ? 'visible' : 'hidden');
			self.transitions[_index] = new Fx.Tween(_index, {property: 'opacity', duration: self.options.duration, wait: true, link: 'chain'});
		});
		
		this.change.periodical(this.options.timeout, this);
	},
	
	position: function(slideshowElement, position){
	
		// console.log('Show Item ' + this.itemPrefix + ' ' + slideshowElement + '-' + position);
		this.transitions[slideshowElement].start(position);
	},
	
	change: function(){
		
		var listLength = this.list.length;
		var nextPosition = (this.options.current_position == listLength) ? 1 : (this.options.current_position + 1);
		var previousPosition = (this.options.current_position == 1) ? listLength : (this.options.current_position - 1);

		var currentPosition = this.options.current_position;

		$( this.itemPrefix + previousPosition).setStyle('opacity', 0);
		
		this.position(this.itemPrefix + currentPosition, [1,0]);
		this.position.delay(1000, this, [this.itemPrefix + nextPosition, [0,1]]);

		this.options.current_position++;
		if (this.options.current_position > listLength) this.options.current_position = 1;
	}
	
});


