//________global functions________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
var pictures_max = 0;
var pictures_counter = 0;
var pictures_timer;

$(document).ready(function(){ 
	
	
	pictures_counter = 0;
	pictures_max = $("div[name=visuel]").length -1;	
	if (pictures_max>=1)
		setTimeout("pictures_tick();", 5000);	
	else {
		if ($("#visuel_navigation")) $("#visuel_navigation").hide();
	}
	
	if ($("#visuel_navigation_previous")) {
		$("#visuel_navigation_previous").click(function() {
			goto_previous_picture();
		});
	}

	if ($("#visuel_navigation_next")) {
		$("#visuel_navigation_next").click(function() {
			goto_next_picture();
		});
	}
});

function pictures_tick(increment_value) {

	if (typeof(increment_value)=="undefined") increment_value = 1;
	
	pictures_counter+=increment_value;
	if (pictures_counter>pictures_max) pictures_counter = 0;
	if (pictures_counter<0) pictures_counter = pictures_max;
	
	$("div[name=visuel]").fadeOut("slow");
	$("#visuel_"+pictures_counter).fadeIn("slow");
	
	clearTimeout(pictures_timer);
	pictures_timer = setTimeout("pictures_tick();", 5000);			
}

function goto_next_picture() {
	
	clearTimeout(pictures_timer);

	pictures_tick(1);
}

function goto_previous_picture() {

	clearTimeout(pictures_timer);

	pictures_tick(-1);
}
