//var init
var picarrayAnim = new Array();
var pickey = 0;
var mainchange = 1;
var intervalCounter = 0;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//INIT
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

window.addEvent('domready',function(){

	
	$$('a').each(function(navi){
		if(navi.href.indexOf("mailto")  == -1 && navi.get("class").indexOf('noreplace') == -1){
			//navi.href = navi.href+'&theme='+theme
		}
	})
	
	$$('table').each(function(tbl){
						
		if(tbl.getParents()[0].get('class')== 'text'){
			
			tbl.getChildren('tbody')[0].getChildren('tr')[0].getChildren('td').each(function(td,key){
				
				tbl.getChildren('tbody')[0].getChildren('tr')[0].getChildren('td')[0].setStyle('height', 453)
											
				if(key%2 == 0){
					td.setStyle('background-color', '#91827d');
				}
			})						
		}
	})
	
	//Mootools mit Array Shuffle Funktion erweitern
	Array.implement({
		shuffle: function() {
			for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
			return this;
		}
	});
	
	new FX().initfade();					
});

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FX CLASS // EFFEKTE, POPUPS, SCROLLBARS, ALLG. STEUER- UND EFFEKTFUNKTIONEN
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var FX = new Class({
	
	//Bildwechsel initialisieren
	initfade: function(){
		
		//Bilder generieren
		pic1 = new Element('img', {
			'id' : 'pic1'
			,'src' : root+'images/0.gif'
			,'height':119
			,'width':337
			,'styles': {
				'position' : 'absolute'
				,'z-index' : 1
				
			}
		}).injectInside($('claim'));
	
		pic2 = new Element('img', {
			'id' : 'pic2'
			,'src' : root+'images/0.gif'
			,'height':119
			,'width':337
			,'styles': {
				'position' : 'absolute'
				,'z-index' : 2
			}
		}).injectInside($('claim'));
		
		
		
			
		//picarrayAnim generieren
		for(var i=1; i<=4; i++){
			
			if(theme == 'is'){
				picarrayAnim.push(root+'images/claims/is'+i+'.jpg');
			}else{
				picarrayAnim.push(root+'images/claims/cc'+i+'.jpg');
			}
			
		}
		
		picarrayAnim.shuffle();
		
		this.firstFade = false;
		
		//preload & start ani
		var preImages = new Asset.images(picarrayAnim, {
			onComplete: function(){
				this.fadeit();
				
				
			}.bind(this)	
		},this)
		
		
	},
	
	
	//Bilder überblenden
	fadeit: function(){

		//Dauer des Bildwechsels, Wiederholungsrate und fps 
		this.s_duration = 1500;
		this.s_periodical = 5000;
		this.s_fps = 30;
		
		if (picarrayAnim.length > 1) {
					
			if ((picarrayAnim.length - 1) > pickey) {
	    		pickey++;
	   		}else{
	    		pickey = 0;
	   		}
			
			if (mainchange == 1) {
				
				$('pic2').set('opacity', 0);
				$('pic2').src = picarrayAnim[pickey];
				
				var myFx1 = new Fx.Tween('pic1', {
					duration: this.s_duration
					,fps: this.s_fps
				}).start('opacity', '1', '0');
				
				var myFx2 = new Fx.Tween('pic2', {
					duration: this.s_duration
					,fps: this.s_fps
				}).start('opacity', '0', '1');
				
				mainchange = 2;
			}
			else {
				
				$('pic1').set('opacity', 0);
				$('pic1').src = picarrayAnim[pickey];
				
				var myFx3 = new Fx.Tween('pic2', {
					duration: this.s_duration
					,fps: this.s_fps
				}).start('opacity', '1', '0');
				
				var myFx4 = new Fx.Tween('pic1', {
					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{
			$('pic2').set('opacity', 1);
			$('pic2').src = picarrayAnim[0];
		}
	}
});
