var colori=new Array("9b9765", "5eb6c1","eeaf59", "8b5c4d", "a264a1", "8b87bc", "81a342", "a195c3" , "5e83bd" ); var coloreAttuale = colori[0]; if ("9b9765" !="") coloreAttuale = "9b9765"; var prossimoColore = colori[1]; var numColore = 1; var intR = parseInt(coloreAttuale.substring(0,2),16); var nextR = parseInt(prossimoColore.substring(0,2),16); var incrementoR = (nextR -intR)/200; //alert("intR:"+intR+"incremento" +incrementoR+ "destinazione: "+nextR); var intG = parseInt(coloreAttuale.substring(2,4),16); var nextG = parseInt(prossimoColore.substring(2,4),16); var incrementoG = (nextG-intG)/200; var intB = parseInt(coloreAttuale.substring(4,6),16); var nextB = parseInt(prossimoColore.substring(4,6),16); var incrementoB = (nextB-intB)/200; var contatore = 0; var durataPasso = 250; //Pf: 35 (7 secondi) var tempoFisso = 7000; //Pf: 3000 function cambiaColore() { intR = intR + incrementoR; intG = intG + incrementoG; intB = intB + incrementoB; coloreAttuale = parseInt(intR).toString(16) + parseInt(intG).toString(16) + parseInt(intB).toString(16); //alert (nuovoColore); if (contatore ==200){ setNewColor() }else{ setBG(coloreAttuale); contatore++; } if (contatore%30 == 0){ //Aggiornamento del colore ogni 20 cicli maintainColore(); } } function setBG(nuovoColore) { document.body.style.backgroundColor="#"+nuovoColore+""; //alert(nuovoColore); setTimeout("cambiaColore()",durataPasso); } function setNewColor() { coloreAttuale = prossimoColore; if (document.getElementById("coloreAttuale")) document.getElementById("coloreAttuale").innerHTML=coloreAttuale; numColore++; if (numColore >3){ numColore = 0 } prossimoColore = colori [numColore]; //alert(prossimoColore); intR = parseInt(coloreAttuale.substring(0,2),16); nextR = parseInt(prossimoColore.substring(0,2),16); incrementoR = (nextR -intR)/200; intG = parseInt(coloreAttuale.substring(2,4),16); nextG = parseInt(prossimoColore.substring(2,4),16); incrementoG = (nextG-intG)/200; intB = parseInt(coloreAttuale.substring(4,6),16); nextB = parseInt(prossimoColore.substring(4,6),16); incrementoB = (nextB-intB)/200; contatore = 0; setTimeout("cambiaColore()",tempoFisso); } function cambiaVelocita() { durataPasso = document.getElementById("durata").value * 5; } function impostaColore() { if ("9b9765" !="") { //alert("9b9765"); coloreAttuale = "9b9765"; document.body.backgroundColor= coloreAttuale; prossimoColore = colori[1]; numColore = 1; intR = parseInt(coloreAttuale.substring(0,2),16); nextR = parseInt(prossimoColore.substring(0,2),16); incrementoR = (nextR -intR)/200; //alert("intR:"+intR+"incremento" +incrementoR+ "destinazione: "+nextR); intG = parseInt(coloreAttuale.substring(2,4),16); nextG = parseInt(prossimoColore.substring(2,4),16); incrementoG = (nextG-intG)/200; intB = parseInt(coloreAttuale.substring(4,6),16); nextB = parseInt(prossimoColore.substring(4,6),16); incrementoB = (nextB-intB)/200; } cambiaColore(); } window.onload = impostaColore; window.onunload = maintainColore; //AJAX PART //Creazione di richiesta Ajax (verificare validità cross browser) //Permette di eseguire una pagina senza doverla aprire, e di recuperare l'output in un'apposita variabile function createXMLHttpRequest() { try { return new XMLHttpRequest(); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} //alert("XMLHttpRequest not supported"); return null; } function maintainColore() { var xhReq = createXMLHttpRequest(); xhReq.open("GET", "/scripts/mantieniColore.php?colore="+coloreAttuale, false); xhReq.send(null); } function recuperaColore() { var xhReq = createXMLHttpRequest(); xhReq.open("GET", "/scripts/recuperaColore.php?colore="+coloreAttuale, true); xhReq.send(null); }