﻿
var indice = -1;


var tempo;

function carregarImagem(url, link) {
    //alert(indice);
    var img = new Image();
    $('#slideCarregamento')
    .children(0).fadeOut()
    .empty();
    

    $(".lnkSlides").removeClass("lnkSlideshover");
    $("#lnkSlide" + indice).addClass("lnkSlideshover");

    
     $(img)
    .load(function() {
        $(this).hide();
        $('#slideCarregamento')
        .empty()
        .append(this);

        $(this).fadeIn();

                
      
        tempo = setTimeout(function() {
            avancar();
        }, 5000);
    })

  .attr('src', url)
  .click(function() {window.location = link });
  
  

}
function avancar() {
    
    indice++;
       
    if (indice == imagens.length) {
        indice = 0;
    }

    carregarImagem(imagens[indice], links[indice]);
}
function voltar() {
    indice--;
    if (indice < 0) {
        indice = imagens.length -1;
    }
    carregarImagem(imagens[indice], links[indice]);
}
function irPara(i) {
    clearTimeout(tempo);
    indice = i;
    if (indice < 0) {
        indice = imagens.length - 1;
    }
    if (indice == imagens.length) {
        indice = 0;
    }

    carregarImagem(imagens[indice], links[indice]);
}


$(function() {

    avancar();





});

