var nbreImagesFonds = 0;
var fondEnCours = -1;
var timeOut;

function changeFonds(repeat) {

  // incrémentation
  fondEnCours++;
  if(fondEnCours ==  nbreImagesFonds)
  {
    document.location = 'index.php?pg=a-la-une';
    clearTimeout(timeOut);
  }

	// on cache tous les fonds
	$('.image_fond').hide();
	$('.lien_fond').hide();

  // on montre le fond en cours
  $('#image_fond_' + fondEnCours).fadeIn();
  $('#lien_fond_' + fondEnCours).fadeIn();

  if(repeat)
    timeOut = setTimeout('changeFonds('+ repeat + ');', 5000);
}

$(window).load(function() {

	nbreImagesFonds = $('.image_fond').length;

  // Page Home
  if(($('#kpz-une_fonds-acces_direct').length == 1) && ($('#kpz-une_fonds-liens').length > 0))
    $('#kpz-une_fonds-liens').show();

  if(nbreImagesFonds > 0)
    changeFonds((nbreImagesFonds > 1));
});

