$(document).ready(function(){ 
	
	var interval;
	var interval2;
	var countFirst = 0;
	var biblio_sizeFirst = $("#listThumb ul li ").size();
	var idTest = $("#listThumb li a.active").attr('href');
	var totalThumbStart = $('#biblioReference #' + idTest+ ' ul li').size();
	if(totalThumbStart > 1){
	interval2 = setInterval(function toto(){
		var id = $("#listThumb li a.active").attr('href');
		var biblio_size = $('#biblioReference #' + id ).size();
	
		if( countFirst < (totalThumbStart-1) ) {
						countFirst = countFirst +1;
					} else {
						countFirst = 0;
					}
		$('#Reference').fadeOut(1000, 
								function() {
									$('#Reference').empty();
									var items = $('#biblioReference #' + id + ' ul li:eq('+countFirst+')').children().clone();
									$('#Reference').append(items);
									$('#Reference').fadeIn(1000);		   
								}
								)
		}, 8000	);
	
	}
	
		
						   
	$('#listThumb li a').click(function(event) {
		$("#listThumb li a.active").removeClass("active");

		$(this).addClass("active");
		clearInterval(interval2);
		clearInterval(interval);
		var id = $(this).attr('href');
		var count = 0;
		var biblio_size = $('#biblioReference #' + id).size();
		if(biblio_size) {
			$('#Reference').empty();
			var items = $('#biblioReference #' + id + ' ul li:eq('+count+')').children().clone();
			var nbItems = $('#biblioReference #' + id + ' ul li').size();
			$('#Reference').append(items);
			if(nbItems > 1){
			interval = setInterval(
				function() {
					if( count < (nbItems-1) ) {
						count = count +1;
					} else {
						count = 0;
					}
					$('#Reference').fadeOut(1000, function() {
						$('#Reference').empty();
						var items = $('#biblioReference #' + id + ' ul li:eq('+count+')').children().clone();
						$('#Reference').append(items);
						$('#Reference').fadeIn(1000);
					}
				);
			}
		
					, 8000
				);
				 }
		//	$(document).everyTime(1000, function(){
				//alert("test");
				//$('#Reference').empty();
				//var items = $('#biblioReference #' + id + '').children().clone();
				//$('#Reference').append(items);
				return false;
											
		//	}); 
		}
		
		return false;
	});
	
});



