// Routine testo scorrevole su 30 caselle

// Numero caselle da gestire 
var nc=30;
// Velocità di movimento delle caselle in millisecondi 
var spd=250;
// Lunghezza testo da esporre
var ltxt=0;
// cb   Contatore caselle bianche se lunghezza testo minore di nc (numero caselle)
var cb=0;
//  Contatori
var count=0;
var offs=0;
//  Eventuale percorso di ricerca immagini + eventuale prefisso dei nomi delle caselle
var imagepath="ZZ/Z-Z";

// Caricamento immagini 
if (text.length > 0)
  { 
var preloadimages=new Array()
for (p=32;p<=249;p++)
     {
preloadimages[p]=new Image()
preloadimages[p].src=imagepath+p+".gif"
     }
  }

// Caricamento variabile num. caselle bianche ed eventuale riempimento a nc del testo
 if (text.length < nc  &&  text.length > 0)
    {
     ltxt=text.length;
     cb=(nc-ltxt);
     for (j=(ltxt+1);j<=nc;j++)
          {
           text=text+" ";
          }
     }
 else
     {
       cb=0;
     }

// Funzione di caricamento caselle (nc)  con intervallo di tempo (spd)
function startscroll()
{
if (text.length > 0)
   {  action=window.setInterval("go()",spd);  }
}


// Funzione di caricamento caselle
function go()
{ 
  strd=text.substr(offs,(count+1));
  var str=strd.substr(0,nc);
  
  if (count>(nc-2) && str.length<nc)
    {
    var se=(nc-len);
    while (str.length<nc)
        {
      str=str+" ";
      se+=1;      
        }
    }
  len=str.length;
  var c=0;
  while (c<len)
    {
    r=str.substr(c,1);
    g=r.charCodeAt(0);
    chr=eval('document.c'+((nc+1)-len+c));
    chr.src=preloadimages[g].src;
    c+=1;
    }
 count+=1;
   if (count>=nc)
    {
   offs+=1;
    }
 if (count>(text.length+((nc-1)-cb)))
    {
 count=0;
 offs=0;
    }
}