animBackgroundHelper = null;

var animBackground = Class.create();
animBackground.prototype = {
	
	initialize : function (element)
	{
		this.images = $('backgroundnew').getElementsByTagName('img');
		for (i=0;i<this.images.length;i++)
		{
			if(i != 0)
			{
				setOpacity(this.images[i],0);
				this.images[i].style.zIndex = 2;
				this.images[i].style.display = "block";
			}
			else
			{
				setOpacity(this.images[i],100);
				this.images[i].style.zIndex = 3;
			}
		}
		
		this.actual = 0;
		
		new PeriodicalExecuter(this.changeImage,6); // HIER DIE SEKUNDEN AENDERN FUER DAS WECHSEL INTERVAL
		
		animBackgroundHelper = this;
	},
	
	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: 3000});
			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: 3000});
			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 + ')';
}
