/**
 * @author Adrien
 */

 
 jQuery(document).ready(function() {
    var cpt = $('#liste li').length;
	var show = 3;
	var current = 0;
	var stop = cpt - show;
	
	/* Cache les miniatures après show */
	$('#liste li').each(
		function(i)
		{
			if (i >= show) 
			{
				$(this).hide();
			}
		}
	);
	
	$('#liste a').click(
		function(e){
			e.preventDefault();
			var src = $(this).attr("href");
			var texte = "Galerie photo: "+$(this).attr("rel");
			
			$('#box img').fadeOut();
			$('#box').empty();
			$('#box').append('<img src="'+src+'" style="display:none"/>');
			$('#box img').fadeIn("slow");
			
			
			$('#galerie').fadeOut(function(){$('#galerie').text(texte)}).fadeIn();
		}
	);
	
	$('#next').click(
		function()
		{
			current++;
			if(cpt > show && current <= stop)
			{
				$('#liste li').eq(current + 2).slideDown('slow');
				$('#liste li').eq(current - 1).slideUp('slow');
			}
			if(current == stop + 1) {
				current--;
			}
		}
	);
	
	$('#prev').click(
		function()
		{
			current--;
			if (current >= 0 && cpt > show) {
				$('#liste li').eq(current + show).slideUp('slow');
				$('#liste li').eq(current).slideDown('slow');
			}
			if(current == -1) {
				current++;
			}
		}
	);
	
});
