var sniAds = new Class({
	Implements: [Events,Options],
	options: {
		curIndex: 0, // current El in elements which is displayed at start time..
		elements: {
		}
	},
	initialize: function(options) {
		this.setOptions(options);
		this.curIndex = this.options.curIndex;
		this.elements = this.options.elements;
		this.container = $(this.options.container);
		this.delay = null;
		this.container.set("tween", {
			"duration": "normal",
			"transition": "sine:in:out",
			"link": "cancel"
		});
		if(this.elements[this.curIndex] && this.elements[1]) { // mind. 2 Elemente müssen vorhanden sein
			this.delay = this.swap.delay((this.elements[this.curIndex].delay * 1000),this);
		}	
	},
	swap: function() {
		$clear(this.delay);
		if(this.elements[this.curIndex + 1]) {
			// increase
			this.swapIt(this.curIndex + 1);
		}
		else {
			// start from scratch
			this.swapIt(0);
		}
	},
	swapIt: function(toIndex) {
		if(!this.elements[this.curIndex].flash) {
			// aktuell != Flash --> animieren
			this.curIndex = toIndex;
			this.container.tween("opacity",0).get("tween").chain(function() {
				this.container.set("html",this.elements[this.curIndex].html);
				if(!this.elements[this.curIndex].flash) {
					this.container.tween("opacity",1).get("tween").chain(function() {
						this.delay = this.swap.delay((this.elements[this.curIndex].delay * 1000),this);
					}.bind(this));
				}
				else {
					this.container.setStyle("opacity",1);					
                    this.delay = this.swap.delay((this.elements[this.curIndex].delay * 1000),this);
				}
			}.bind(this));
		}
		else {
			//  aktuell == Flash --> NICHT animieren
			this.curIndex = toIndex;
			if(!this.elements[this.curIndex].flash) {
				// das was kommt ist != Flash --> animieren
				this.container.setStyle("opacity",0);
				this.container.set("html",this.elements[this.curIndex].html);
				this.container.tween("opacity",1).get("tween").chain(function() {
					this.delay = this.swap.delay((this.elements[this.curIndex].delay * 1000),this);
				}.bind(this));
			}
			else {
				// das was kommt ist == Flash --> NICHT animieren
                this.container.set("html",this.elements[this.curIndex].html);
                this.delay = this.swap.delay((this.elements[this.curIndex].delay * 1000),this);
			}
		}
	}
});

