// JavaScript Document
/**************************************************************************************
stati XMLHttpRequest
0 	Represents an "uninitialized" state in which an XMLHttpRequest object has been created, but not initialized.
1 	Represents a "sent" state in which code has called the XMLHttpRequest open() method and the XMLHttpRequest is ready to send a request to the server.
2 	Represents a "sent" state in which a request has been sent to the server with the send() method, but a response has not yet been received.
3 	Represents a "receiving" state in which the HTTP response headers have been received, but message body has not yet been completely received.
4 	Represents a "loaded" state in which the response has been completely received.

**************************************************************************************/

function getXmlHttpObject(){
	//crea l'oggetto XMLHttpRequest utilizzando il comando giusto in base al browser
	//sintassi => nomeOggetto = GetXmlHttpObject();
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
/* walter
faeSpeed = 1500;
fadeWait = 2000;
fullAlphaTime = 5000;
*/

faeSpeed = 2000;
fadeWait = 4000;
fullAlphaTime = 5000;

function cambiaSfondo1(){ 
	if (xmlHttp.readyState==4){ //4: finished.
		//funzioni per readyState 4
		//changeOpac(0, "livello1Intro");
		document.getElementById("livello1Intro").innerHTML=xmlHttp.responseText;
		setTimeout('opacity("livello2Intro", 100, 0, faeSpeed)', fadeWait);
		setTimeout('opacity("livello1Intro", 0, 100, faeSpeed)', fadeWait);
		setTimeout('loadSfondoIntroLevel2()', fullAlphaTime);
	}
}

function cambiaSfondo2(){ 
	if (xmlHttp2.readyState==4){ //4: finished.
		//funzioni per readyState 4
		//changeOpac(0, "livello2Intro");
		document.getElementById("livello2Intro").innerHTML=xmlHttp2.responseText;
		setTimeout('opacity("livello1Intro", 100, 0, faeSpeed)', fadeWait);
		setTimeout('opacity("livello2Intro", 0, 100, faeSpeed)', fadeWait);
		setTimeout('loadSfondoIntroLevel1()', fullAlphaTime);
	}
}
function traceTest(messaggio){
	document.getElementById("testIntro").innerHTML = messaggio;	
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


function loadSfondoIntroLevel1(){
	//codice per caricare la pagina dal nome del menu
	xmlHttp = getXmlHttpObject();
	xmlHttp.onreadystatechange=cambiaSfondo1;
	pagina="getSfondoIntro.php?sid="+Math.random();
	xmlHttp.open("GET",pagina,true);
	xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	xmlHttp.send(null);
}

function loadSfondoIntroLevel2(){
	//codice per caricare la pagina dal nome del menu
	xmlHttp2 = getXmlHttpObject();
	xmlHttp2.onreadystatechange=cambiaSfondo2;
	pagina="getSfondoIntro.php?sid="+Math.random();
	xmlHttp2.open("GET",pagina,true);
	xmlHttp2.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	xmlHttp2.send(null);
}

/*
function startFading(){
	opacity("livello2Intro", 0, 100, faeSpeed);
	setTimeout('loadSfondoIntroLevel1()', 9000);
}
*/
/* walter
function startFading(){
	loadSfondoIntroLevel1();
	setTimeout('opacity("controlloEntra", 0, 100, 2500)', 9000);
	setTimeout('opacity("controlloEnter", 0, 100, 2500)', 9000);
}
*/
function startFading(){
	loadSfondoIntroLevel1();
	setTimeout('opacity("controlloEntra", 0, 100, 2500)', 6000);
	setTimeout('opacity("controlloEnter", 0, 100, 2500)', 6000);
}