// JavaScript Document

$(document).ready(function(){
	compteur = 1;
	delai = 5000;
	nbImages = $('#actualites li').length;
	active = 1;
	init();
});

function init(){
	var diaporama = $('#actu_0'+compteur).html();
	$('#newsticker').html(diaporama);
	$('#precedent').click(function(){
		efface('moins');
	});
	$('#suivant').click(function(){
		efface('plus');
	});

	lanceBoucle();
}

function lanceBoucle(){
	boucle = setTimeout(transition, delai);
}

function transition(){
	efface('plus');
	lanceBoucle();
}
	
function efface(type){
	switch(type){
		case 'moins':
			$('#newsticker').fadeOut(500, precedent);
			break;
			
		case 'plus':
			$('#newsticker').fadeOut(500, suivant);
			break;
	}
}

	
function suivant(){
	if(compteur >= nbImages){
		compteur = 1;
	}else{
		compteur++;
	}
	var diaporama = $('#actu_0'+compteur).html();
	$('#newsticker').html(diaporama).fadeIn(500);
	
}

function precedent(){
	if(compteur <= 1){
		compteur = nbImages;
	}else{
		compteur--;
	}
	var diaporama = $('#actu_0'+compteur).html();
	$('#newsticker').html(diaporama).fadeIn(500);
	}
