animBackgroundHelper = null;

var animBackground = Class.create();
animBackground.prototype = {
	
	initialize : function (element) {
		this.images = $('background').getElementsByTagName('img');
		for (i=0;i<this.images.length;i++) {
			if(i != 0) {
				setOpacity(this.images[i],0);
				this.images[i].style.zIndex = 2;
			}
			else {
				setOpacity(this.images[i],100);
				this.images[i].style.zIndex = 3;
			}
		}
		
		this.actual = 0;
		
		new PeriodicalExecuter(this.changeImage,10); // HIER DIE SEKUNDEN AENDERN FUER DAS WECHSEL INTERVAL
		
		animBackgroundHelper = this;
		
		$('background').style.visibility = 'visible';
	},
	
	changeImage : function () {
		images = animBackgroundHelper.images;
		
		if(animBackgroundHelper.actual == images.length -1) {
			// Letzer
			animBackgroundHelper.images[animBackgroundHelper.actual].style.zIndex = 2;
			animBackgroundHelper.images[0].style.zIndex = 3;
			
			ex9 = new Animator({transition: Animator.makeEaseOut(3),duration: 9000});
			ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual], 'opacity', 1, 0));
			ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[0], 'opacity', 0, 1));
			ex9.play();
			
			animBackgroundHelper.actual = 0;
		}
		else {
			// Weiter
			animBackgroundHelper.images[animBackgroundHelper.actual].style.zIndex = 2;
			animBackgroundHelper.images[animBackgroundHelper.actual + 1].style.zIndex = 3;
			
			ex9 = new Animator({transition: Animator.makeEaseOut(3),duration: 9000});
			ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual], 'opacity', 1, 0));
			ex9.addSubject(new NumericalStyleSubject(animBackgroundHelper.images[animBackgroundHelper.actual + 1], 'opacity', 0, 1));
			ex9.play();
			
			animBackgroundHelper.actual ++;
		}		
	}
	
}

function setOpacity(element,value) {
	element.style.opacity = value/100;
	element.style.filter = 'alpha(opacity=' + value + ')';
}
