var stop=1;
var t;
var j = 0;
var p = Pic.length;
var resto=p % qtd;
var y="";
var pagina=0;
var pg_anterior = document.getElementById("pag_anterior");
var pg_posterior = document.getElementById("pag_posterior");
if (p<qtd) 
 {
   pg_anterior.innerHTML="&nbsp;";
   pg_posterior.innerHTML="&nbsp;";
 }
if (resto > 0)
  {
    var totpag=((p - resto) / qtd ) + 1;
  }
  else
  {
    var totpag=(p / qtd );
  }

y=""
var x=document.getElementById("paginas");
for (i = 1; i <= totpag; i++){
    y=y+"<a href='javascript:trocapagina("+i+")'>"+i+"</a>&nbsp;";
}
x.innerHTML=y;

x=document.getElementById("totaisdefoto");

x.innerHTML="/"+p;
x=document.getElementById("numerofoto");
x.innerHTML="1";

// ---- Thumbs
var preLoad = new Array();

function Thumb(pag,cria){
  pagina=pag;
  var y="";
  var x=document.getElementById("imagemthumb");
  var loop=qtd;
  if (pag==totpag) { loop=resto; }
  if (loop==0) loop=qtd;
  //alert("thumb "+loop+"   "+pagina)
  for (i = 0; i < loop; i++){
   var item=i+ ( (pag -1 ) * qtd );
   preLoad[item] = new Image();
   preLoad[item].src = Pic[item];
   y=y+"<a href=# onmouseover='troca("+i+")'><img id='img"+i+"' src='"+preLoad[item].src+"' alt='"+Alt[i]+"' width='62' height='48' style='border:1px solid #000000' /></a>&nbsp;";
  }
  if (cria==1) x.innerHTML=y;
}
Thumb(1,1);
//

x=document.getElementById("altfoto");
x.innerHTML=Alt[j];

function Slide(){
 if (stop<2) {
   if (stop==0){
    stop=1;
    document.images.bt_slideshow.src = "images/bt_slideshow.gif";
   } else
   { stop=0;
    document.images.bt_slideshow.src = "images/bt_slideshow_pause.gif";
    Show();
   }
 }
}


function Show(){
 if (stop == 0) {   
   // Thumb Carega
   var calc1= (j + 1) % qtd;
   var dif=0;
   if ( calc1>0 )
   { dif= (qtd - calc1 ) + j + 1;  }
   else 
   { dif=j + 1; }
   var pag=dif / qtd;
   if (pagina != pag) Thumb(pag,1);
   //
   if (document.all){
      document.images.img.style.filter="blendTrans(duration=2)"
      document.images.img.style.filter="blendTrans(duration=duracao)"
      document.images.img.filters.blendTrans.Apply()      
   }
   x=document.getElementById("numerofoto")
   foto=j+1
   x.innerHTML=foto;
   document.images.img.src = preLoad[j].src
   x=document.getElementById("altfoto");
   x.innerHTML=Alt[j];
   
   if (document.all){
      document.images.img.filters.blendTrans.Play()
   }
   j = j + 1
   if (j > (p-1)) j=0;
   t = setTimeout('Show()', tempo)
 }
}

function trocapagina(pg)
{
  var calc1=pagina + 1
  if (pg > calc1)
   {
    
    for (z = calc1; z <= pg; z++)
     {
     Thumb(z,0);
     }
   }
  Thumb(pg,1);
  j= ((pg -1) * qtd );
  calc1=( (j + 1) % pg) -1;
  if (calc1<0) calc1=0;
  troca(calc1);
}


function troca(foto){
   j=foto + ( (pagina - 1) * qtd ) ;
   var calc1= (j + 1) % qtd;
   var dif=0;
   if ( calc1>0 )
     { dif= (qtd - calc1 ) + j + 1;  }
      else 
     { dif=j + 1; }
   var pag=dif / qtd;
   if (pagina != pag) Thumb(pag,1);
   //
   
   x=document.getElementById("numerofoto")
   x.innerHTML=j+1;
   x=document.getElementById("altfoto");
   x.innerHTML=Alt[j];
   //check = document.getElementById("checkslide");
   document.images.bt_slideshow.src = "images/bt_slideshow.gif";
   //check.checked=false;     
   if (stop==2) {
     stop=1;
     imagem = document.getElementById("imagemprincipal");
     imagem.innerHTML="<img src='"+Pic[j]+"' name='img' id='img' width='375' height='277' style='border:1px solid #000000' />"
   } else
   {
     stop=1;
     if (document.all){
        document.images.img.style.filter="blendTrans(duration=2)"
        document.images.img.style.filter="blendTrans(duration=duracao)"
        document.images.img.filters.blendTrans.Apply()      
     }
     document.images.img.src = preLoad[j].src
     if (document.all){
       document.images.img.filters.blendTrans.Play()
     }
   }
}

function esquerda()
{
 j--;
 if (j<0) j=p-1;
 calc1=j - ((pagina - 1) * qtd ) 
 if (calc1<0) calc1=-1;
 troca(calc1);
}
function direita()
{
 j++;
 if (j==p)  {
  j=0
  }
 calc1=j - ((pagina - 1) * qtd ) 
 troca(calc1);   
}
function pganterior()
{
 j=j-qtd;
 if (j<0) j=p-1;
 calc1=j - ((pagina - 1) * qtd ) 
 if (calc1<0) {
   calc1=-1;
   }
 troca(calc1);
}
function pgproxima()
{
 j=j+qtd;
 if (j>=p)  {
  j=0
  }
 calc1=j - ((pagina - 1) * qtd ) 
 troca(calc1);   
}


