var picarray = new Array();
var pickey = 0;
var mainchange = 1;
var fadeDuration = 3500;
var fadePeriode= 7000;
window.addEvent('domready', function() {
	new wascosa();
});
var wascosa = new Class({
	options:{
		
	}
	,initialize: function(options){
		if ($defined($('closer'))) {
			$('closer').addEvents({
				'click': function(e){
					$('fadeContainer').setStyles({
						'background':'url('+root+'images/Intro_1.jpg)'
					});
					(function(){
						new imageFader();
					}).delay(fadeDuration, this);
				}
			});
		}
	}
})
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ANIMATION CLASS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var imageFader = new Class({
	//Bildwechsel initialisieren
	initialize: function(){
		//Bilder generieren
		pic1 = new Element('img', {
			'id' : 'fade1'
			,'src' : root+'images/0.gif'
			,'styles': {
				'position' : 'absolute'
				,'z-index' : 600
				,'border':0
				
			}
		}).injectInside($('fadeContainer'));
		pic2 = new Element('img', {
			'id' : 'fade2'
			,'src' : root+'images/0.gif'
			,'styles': {
				'position' : 'absolute'
				,'z-index' : 601
				,'border':0
			}
		}).injectInside($('fadeContainer'));
		//Bilddimensionen abfragen
		pWidth = 580;
		pHeight = 265;
		$('fade1').setStyles({
			'height' : pHeight
			,'width': pWidth
		});
		$('fade2').setStyles({
			'height' : pHeight
			,'width' : pWidth
		});
		//picarray generieren
		for(var i=1; i<=4; i++){
			picarray.push(root+'images/Intro_'+i+'.jpg');
		}
		this.firstFade = false;
		this.fadeit();
	},
	//Bilder überblenden
	fadeit: function(){
		//Dauer des Bildwechsels, Wiederholungsrate und fps 
		this.s_duration = 2500;
		this.s_periodical = fadePeriode;
		this.s_fps = 60;
		if (picarray.length > 1) {	
			if ((picarray.length - 1) > pickey) {
				pickey++;
			}else{
				pickey = 0;
			}
			if (mainchange == 1) {
				$('fade2').set('opacity', 0);
				$('fade2').src = picarray[pickey];
				var myFx1 = new Fx.Tween('fade1', {
					duration: this.s_duration
					,fps: this.s_fps
				}).start('opacity', '1', '0');
				var myFx2 = new Fx.Tween('fade2', {
					duration: this.s_duration
					,fps: this.s_fps
				}).start('opacity', '0', '1');
				mainchange = 2;
			}
			else {
				$('fade1').set('opacity', 0);
				$('fade1').src = picarray[pickey];
				var myFx3 = new Fx.Tween('fade2', {
					duration: this.s_duration
					,fps: this.s_fps
				}).start('opacity', '1', '0');
				var myFx4 = new Fx.Tween('fade1', {
					duration: this.s_duration
					,fps: this.s_fps
				}).start('opacity', '0', '1');
				mainchange = 1;
			}
			if(this.firstFade == false){
				this.firstFade = true;
				intervalID = this.fadeit.periodical(this.s_periodical);
			}
		}else{
			$('fade2').set('opacity', 1);
			$('fade2').src = picarray[0];
		}
	}
});
