var i = 1;
var nb_slide = 6;

function slideSwitchNext() {
    var $active = $('#slideshow div.active');

    if ( $active.length == 0 ) $active = $('#slideshow div:first');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow div:first');
		if($active.hasClass('active') && $next.hasClass('active')){
		}
		else{
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 200, function() {
            $active.removeClass('active last-active');
        });
    }
    
    if ($('#point_'+(i+1)).length) {
			$('#point_'+(i+1)).attr('src', 'images/point_on.png');
			$('#point_'+(i)).attr('src', 'images/point_off.png');
			i = i+1;
    }
    else{
			$('#point_'+(i)).attr('src', 'images/point_off.png');
			$('#point_'+(1)).attr('src', 'images/point_on.png');
			i = 1;
    }
    

    
}

function slideSwitchPrev() {
    var $active = $('#slideshow div.active');

    if ($active.length == 0){
			$active = $('#slideshow div:last');
		}

    // use this to pull the images in the order they appear in the markup
    if($active.prev('DIV').length){
			var $next = $active.prev();
    }
    else{
		  var $next = $('#slideshow div:last');
    }
    if($active.hasClass('active') && $next.hasClass('active')){
		}
		else{
			$active.addClass('last-active');
			$next.css({opacity: 0.0})
					.addClass('active')
					.animate({opacity: 1.0}, 200, function() {
							$active.removeClass('active last-active');
					});
		}
		if ($('#point_'+(i-1)).length) {
			$('#point_'+(i-1)).attr('src', 'images/point_on.png');
			$('#point_'+(i)).attr('src', 'images/point_off.png');
			i = i-1;
    }
    else{
			$('#point_'+(i)).attr('src', 'images/point_off.png');
			$('#point_'+(nb_slide)).attr('src', 'images/point_on.png');
			i = nb_slide;
    }
}

$(document).ready(function(){
	
	// Défilement des ancres en douceur
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target
			|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body')
				.animate({scrollTop: targetOffset}, 1000);
			 return false;
			}
		}
	});
	
	// Slide-Show
	$('.slide_next').click(function(ev){
		ev.preventDefault(ev);
		slideSwitchNext();
	});
	$('.slide_prev').click(function(ev){
		ev.preventDefault(ev);
		slideSwitchPrev();
	});
	
});



