var browser = -1;
if (document.all) browser = 0; //MSIE
else if (document.layers) browser = 1; //NN 4.x
else if (document.getElementById) browser = 2; // N6
var globArray = new Array();
var globIndex= 0;
function Testo(riferimento,testo,oTags,cTags,colori,speed){
this.riferimento = riferimento;
this.testo = testo;
this.oTags = oTags;
this.cTags = cTags;
this.colori = colori;
this.speed = speed;
this.contatore = 0; }
function Colore(rosso,verde,blu) {
this.rosso = rosso;
this.verde = verde;
this.blu = blu; }
function triplettaEsadecimale(colore) {
r = colore.rosso.toString(16);
v = colore.verde.toString(16);
b = colore.blu.toString(16);
if(r.length==1) r = "0" + r;
if(v.length==1) v = "0" + v;
if(b.length==1) b = "0" + b;
return r + v + b; }
function sfumaDue(coloreInizio,coloreFine,theArray,inizio,fine) {
p = fine - inizio;
dRosso = (coloreFine.rosso - coloreInizio.rosso) / p;
dVerde = (coloreFine.verde - coloreInizio.verde) / p;
dBlu   = (coloreFine.blu     - coloreInizio.blu) / p;
theArray[inizio] = triplettaEsadecimale(coloreInizio);
for(c=inizio+1;c<fine;c++) {
tRosso = coloreInizio.rosso + ((c - inizio) * dRosso);
tVerde = coloreInizio.verde + ((c - inizio) * dVerde);
tBlu   = coloreInizio.blu   + ((c - inizio) * dBlu);
tRosso = Math.floor(tRosso);
tVerde = Math.floor(tVerde);
tBlu   = Math.floor(tBlu);
if (tRosso<0) tRosso = 0;
if (tVerde<0) tVerde = 0;
if (tBlu<0)   tBlu   = 0;
if (tRosso>255) tRosso = 255;
if (tVerde>255) tVerde = 255;
if (tBlu>255)   tBlu   = 255;
theArray[c] = triplettaEsadecimale(new Colore(tRosso,tVerde,tBlu));
}
}
function calcolaSfumatura(stringa,steps){
aux = stringa.split(";");
coloriChiave = new Array();
for (i=0;i<aux.length;i++){
temp = aux[i].split(",");
coloriChiave[i]= new Colore(parseInt(temp[0]),parseInt(temp[1]),parseInt(temp[2])); }
sfumArray = new Array();
d = Math.floor(steps / coloriChiave.length);
cont = 0;
for (i=0;i<coloriChiave.length;i++) {
f =(i!=coloriChiave.length-1) ? i + 1 : 0;
termine = (i!=coloriChiave.length-1) ? cont + d : steps;
sfumaDue(coloriChiave[i],coloriChiave[f],sfumArray,cont,termine);
cont = termine;
}
return sfumArray;
}
function anima(id) {
temp = globArray[id].oTags;
for(i=0;i<globArray[id].testo.length;i++){
col =globArray[id].contatore + i;
if (col>=globArray[id].colori.length) col %= globArray[id].colori.length;
temp += '<font color="#' + globArray[id].colori[col] + '">' + globArray[id].testo.charAt(i) + '</font>';
}
temp += globArray[id].cTags;
if (globArray[id].contatore!=globArray[id].colori.length) globArray[id].contatore++;
else
globArray[id].contatore = 0;
if (browser!=1) globArray[id].riferimento.innerHTML = temp;
else {
globArray[id].riferimento.document.open();
globArray[id].riferimento.document.write(temp);
globArray[id].riferimento.document.close();
}
setTimeout("anima(" + id + ")",globArray[id].speed);
}
function iniziaAnimazione() {
for(i=0;i<globArray.length;i++)
setTimeout("anima(" + i + ")",globArray[i].speed);
}
function aggiungiTestoSfumatoAnimato(stringa,sfumatura,t1,t2,attributi,steps,speed) {
tag = (browser==1) ? 'layer' : 'div';
if(attributi!='')
document.write('<' + tag + ' id="tsa' + globIndex + '" + ' + attributi + '></' + tag + '>');
else
document.write('<' + tag + ' id="tsa' + globIndex + '" ></' + tag + '>');
rif =null;
if (browser==0) rif = eval("document.all.tsa" + globIndex);
else if (browser==1) rif = eval("document.layers.tsa" + globIndex);
if (browser==2) rif = document.getElementById("tsa" + globIndex);
if(rif!=null) {
globArray[globIndex] = new Testo(rif,stringa,t1,t2,calcolaSfumatura(sfumatura,steps),speed);
globIndex++;
}
}