// JavaScript Document


function HeaderIntro(){
	
	var arrayImgs = new Array();	
	arrayImgs[0] = document.getElementById('headerFade_1');
	arrayImgs[1] = document.getElementById('headerFade_2');
	arrayImgs[2] = document.getElementById('headerFade_3');
	
	
	
	var position = 0;
	

	arrayImgs[position].style.zIndex = "10";
	arrayImgs[position].style.opacity = 1;
	arrayImgs[position].style.filter = 'alpha(opacity=100)';
	

	
	// :::::::::::::::::  function fade out   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	function playOpacity(obj){		
		if(Math.floor(obj.style.opacity*100) == 50){	
			callNextImg(obj);	
		}
		
		if(Math.floor(obj.style.opacity*100) > 0){	
			var newValOpacity = (Math.floor(obj.style.opacity*100)-1);			
			obj.style.opacity = newValOpacity/100;
			obj.style.filter = 'alpha(opacity=' + newValOpacity + ')';
			setTimeout(function(){ playOpacity(obj); },30);
		} else {
			//callNextImg(obj);	
		}
	}
	
		
	playOpacity(arrayImgs[position]);
	
	
	
	
	
	
	// :::::::::::::::::  function call next img animation   :::::::::::::::::::::::::::::::::::::::::
	function callNextImg(obj){
		
		obj.style.zIndex = "0";
		var nuovoOggIndice = arrayImgs.indexOf(obj)+1;
		if(nuovoOggIndice > arrayImgs.length-1){
			nuovoOggIndice = 0;
		}

		arrayImgs[nuovoOggIndice].style.zIndex = "10";
		settingUpNextImg(arrayImgs[nuovoOggIndice]);

	}
	
	
	// :::::::::::::::::  function fade in new img   :::::::::::::::::::::::::::::::::::::::::::::::::
	function settingUpNextImg(obj){
		

		
		if(Math.floor(obj.style.opacity*100) < 100){
			var newValOpacity = (Math.floor(obj.style.opacity*100)+1);		
			obj.style.opacity = ((obj.style.opacity*100)+1)/100;
			obj.style.filter = 'alpha(opacity=' + newValOpacity + ')';
			setTimeout(function(){ settingUpNextImg(obj); },30);
		} else {
			var indexObjPrec = arrayImgs.indexOf(obj)-1;
			if(indexObjPrec == -1){
				indexObjPrec = arrayImgs.length-1;
			}
			arrayImgs[indexObjPrec].style.zIndex = "-10";
			setTimeout(function(){ playOpacity(obj); },1500);
		}
	}
	
}



