
function preload(){
  var t=""
  for(var i=0;i<preloadDeQuantas;i++)
    t+="<img src='"+imagens[(atual+i+1)%imagens.length][0]+"' />"
  $("#preloader").html(t)
}

function mostra(){
  $("#nextimg")[0].src=$("#foto img")[0].src
  $("#nextimg").show()
  $("#foto img")[0].src=imagens[atual][0]
  $("#nextimg").fadeOut('slow')
  $("#legenda_foto").html(imagens[atual][1])
  $("#placar .esquerda").html(atual+1)
  preload()
}

function next(){
  atual=(atual+1)%imagens.length
  resetTrans()
  mostra()
  return false
}


function previous(){
  if(--atual==-1)atual=imagens.length-1
  resetTrans()
  mostra()
  return false
}

window.theTransition=0
function resetTrans(){
  clearInterval(window.theTransition)
  window.theTransition=setInterval("if($('#botao')[0].value=='Pause')next()",5000)
}

$(function(){
  $("#placar .direita").html(imagens.length)
  $("#foto").append("<div id='preloader'></div>")
  $("#foto img").after("<img src='"+imagens[atual][0]+"' id='nextimg' />")
  preload()
  $("#botao").click(function(){
    this.value=this.value=="Pause"?"Play":"Pause"
  })
  $("#foto").hover(
    function(){this.className=""},
    function(){this.className="hide"}
  ).addClass("hide")
  $("#vidro").addClass("show")
  $("#seta_esquerda").click(previous)
  $("#seta_direita").click(next)
  resetTrans()
});
