$(document).ready(function() {	

    $(".gallery a").fancybox({
      'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
                'overlayOpacity' : 0.6,
                'overlayColor' : '#020E19',
                'titlePosition' : 'over'
    });
    $(".gallery a").attr("rel","group");
	
	$("#contenu a img").parent().fancybox({
      'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
                'overlayOpacity' : 0.6,
                'overlayColor' : '#020E19',
                'titlePosition' : 'over'
    });
		
    $("#footer h3").addClass('menuferme');    
    $("#footer").css({bottom: -30});
    $("#footer h3").toggle(
                   function()
                   {
                      $("#footer").animate({bottom: 0},400);
					  $("#footer h3").removeClass('menuferme').addClass('menuouvert');    
                   },
                   function()
                   {
                       $("#footer").animate({bottom: -30},400);
					   $("#footer h3").removeClass('menuouvert').addClass('menuferme');
                   });
		
		
		var position = 0;	
		var nombreDeSlides = $(".diapo").length;
		for (j=1; j<nombreDeSlides+1; j++)	{ $("#diapoAccueil").append("<a href=\"#\"  rel=\""+j+"\">" +j+"</a>")};	
		$("#diapoAccueil>a").wrapAll("<div class=\"paging\"></div>");
		
		$("#slider li").prepend("<p class=\"descrPhoto\"><\/p>");
		$("#slider li").each(function() { 
		var linkText = $(this).find("img").attr("alt"); 
		$(this).find("p").show().html(linkText);
		}); 
	
	function cacher() {		
		$(".actif img").fadeOut(1500);	
		$('.actif p.descrPhoto').animate({marginTop:"0px"}, 500);
		$(".diapo").eq(position).removeClass("actif");
		}
	
	function afficher() { 
		$(".diapo").eq(position).addClass("actif");		
		$(".actif img").fadeIn(500);		
		$('.actif p.descrPhoto').animate({marginTop:"-40px"}, 1000);
		}
	
		
	$('.diapo img').hide();	
	$(".paging").show();
	$(".paging a:first").addClass("active");
	afficher();
	
	
rotate = function(){
    $(".paging a").removeClass('active'); 
    $active.addClass('active');	
	position = $(".active").attr("rel")-1;						
	afficher();
   
}; 


rotateSwitch = function(){
    play = setInterval(function(){
		cacher();
        $active = $('.paging a.active').next(); 
        if ( $active.length === 0) { 
            $active = $('.paging a:first'); 
        }		
        rotate(); 	
    }, 3000); 
};

rotateSwitch(); 
	
$(".paging a").click(function() {
    $active = $(this);    
	cacher();
    clearInterval(play); 
    rotate();
    rotateSwitch(); 
    return false; 
});
	
      });
