// JavaScript Document



function HeaderIntro(){
	
	var arrayImgs = new Array();	
	arrayImgs[0] = document.getElementById('headerIntro_1');
	arrayImgs[1] = document.getElementById('headerIntro_2');
	arrayImgs[2] = document.getElementById('headerIntro_3');
	
	var arrayTxtImgs = new Array();	
	arrayTxtImgs[0] = "Tranquilli c'è Alpeninox";
	arrayTxtImgs[1] = "Tranquilli c'è Alpeninox";
	arrayTxtImgs[2] = "Tranquilli c'è Alpeninox";
	
	var arrayLinksTxt = new Array();
	arrayLinksTxt[0] = "http://www.alpeninox.it";
	arrayLinksTxt[1] = "http://www.alpeninox.it";
	arrayLinksTxt[2] = "http://www.alpeninox.it";
	
	//oggettoText = window.document.getElementById('objText');
	/*
	var position = 0;
	var cookiePosition = getCookie("FadeImg");
	
	if(typeof(cookiePosition) != "undefined"){
		position = parseInt(cookiePosition);
		
		for(var Y=0; Y<position; Y++){
				arrayImgs[Y].style.backgroundPosition = "0px 0px";
				arrayImgs[Y].style.opacity = 0;
				arrayImgs[Y].style.filter = 'alpha(opacity=0)';
				arrayImgs[Y].style.zIndex = "-10";
		}
	}
	
	arrayImgs[position].style.zIndex = "10";
	arrayImgs[position].style.opacity = 1;
	arrayImgs[position].style.filter = 'alpha(opacity=100)';*/
	//document.getElementById('contentTextHeader').innerHTML = arrayTxtImgs[position];
	//var urlLink = arrayLinksTxt[position];
	//document.getElementById('objText').onclick = function() { window.location.assign(urlLink); };

	
	
	
	// :::::::::::::::::  function fade out   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	function playOpacity(obj){	
	
	
	//alert (obj);
	
		if(Math.floor(obj.style.opacity*100) == 50){	
		callNextImg(obj);	
		//	hiddenTxt();
		}
		
		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); },20);
		} else {
			//callNextImg(obj);	
		}
	}
	
	// :::::::::::::::::  function move img   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	/*function moveDown(obj){
		
		
		var stringaSfondo = obj.style.backgroundPosition;
		var posSfondo = stringaSfondo.split(" ");
			
		if(parseInt(posSfondo[1]) == -30){
			playOpacity(obj);
		}
		
		if(parseInt(posSfondo[1]) < 0){
			var posNuova = parseInt(posSfondo[1])+1+"px";
			obj.style.backgroundPosition = "0px "+posNuova;
			setTimeout(function(){ moveDown(obj); },50);
		}
	}*/
		
	//moveDown(arrayImgs[position]);
	playOpacity(arrayImgs[0]);
	
	
	
	
	
	// :::::::::::::::::  function call next img animation   :::::::::::::::::::::::::::::::::::::::::
	function callNextImg(obj){
		
		obj.style.zIndex = "0";
		var nuovoOggIndice = arrayImgs.indexOf(obj)+1;
		if(nuovoOggIndice > 2){
			nuovoOggIndice = 0;
		}
		
		//setCookie("FadeImg",nuovoOggIndice,30);

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

	}
	
	
	// :::::::::::::::::  function fade in new img   :::::::::::::::::::::::::::::::::::::::::::::::::
	function settingUpNextImg(obj){
		
		if(Math.floor(obj.style.opacity*100) == 10){
			//playOpacity(obj);
		}
		
		/*if(Math.floor(obj.style.opacity*100) == 70){
			document.getElementById('contentTextHeader').innerHTML = arrayTxtImgs[arrayImgs.indexOf(obj)];
			var urlLink = arrayLinksTxt[arrayImgs.indexOf(obj)];
			document.getElementById('objText').onclick = function() { window.location.assign(urlLink); };
			//document.getElementById('contentTextHeader').innerHTML = '<a class="linkFade" href="'+arrayLinksTxt[arrayImgs.indexOf(obj)]+'">'+arrayTxtImgs[arrayImgs.indexOf(obj)]+'</a>';
			showTxt();
		}*/
		
		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); },10);
		} else {
			var indexObjPrec = arrayImgs.indexOf(obj)-1;
			if(indexObjPrec == -1){
				indexObjPrec = 2;
			}
			arrayImgs[indexObjPrec].style.zIndex = "-10";
			arrayImgs[indexObjPrec].style.backgroundPosition = "0px 0px";
			setTimeout(function(){ playOpacity(obj); },3000);
			}
	}
	
}

/*
	function hiddenTxt(){
		if(oggettoText.offsetLeft < 1036){
			oggettoText.style.left = oggettoText.offsetLeft+25+"px";
			//oggettoText.style.width = oggettoText.offsetWidth-25+"px";
			setTimeout(hiddenTxt, 1);
		} 
	}
	
	function showTxt(){
		if(oggettoText.offsetLeft > 682){
			oggettoText.style.left = oggettoText.offsetLeft-25+"px";
			//oggettoText.style.width = oggettoText.offsetWidth+25+"px";
			setTimeout(showTxt, 1);
		}
	}
*/
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// :::::::::::::::::   END JS OBJECT   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



// ::::::::::::::::::   implementazione indexOf sugli array per IE      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Array.prototype.indexOf = function(obj){
	for(var i=0; i<this.length; i++){
		if(this[i]==obj){
			return i;
		}
	}
	return -1;
}


// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// ::::::::::::::::   funzioni gestione dei cookie    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function setCookie(c_name,value,durataCookie){
	var exdate=new Date();
	var adesso = new Date();
	//exdate.setDate(exdate.getDate() + exdays);
	exdate.setTime(adesso.getTime() + (parseInt(durataCookie) * 60000));
	var c_value=escape(value) + ((durataCookie==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}


function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
	  	x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	 	y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	 	x=x.replace(/^\s+|\s+$/g,"");
	 	if (x==c_name){
			return unescape(y);
		}
	}
}



