var curr_no = 1;
var timer_no = 1;
var rotate_timer = "";
var max_no = $(".fotoslide-slide").length;
//
function showItem(no){
	if(curr_no!=no){
		if(no > max_no){
			showItem(1);
		} else if(no < 1){
			showItem(max_no);
		} else{
			/* Afbeelding animaties */
			var currentIMG = $("#fotoslide-slide-"+curr_no);
			var nextIMG = $("#fotoslide-slide-"+no);
			nextIMG.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
			currentIMG.animate({opacity: 0.0}, 1000).removeClass('show');
			// Knop aan / uit zetten
			$("#fs"+curr_no).removeClass("aan");
			$("#fs"+no).addClass("aan");
			//
			curr_no = no;
			timer_no = no;
		}
	}
}
//
function RotateFotoslide(){
	/* Start de Fotoslide */
	showItem(timer_no);
	timer_no++;
	if(timer_no>max_no){
		timer_no=1;
	}
	rotate_timer = setTimeout("RotateFotoslide()", 5000);
}
//
$(function(){
	/* CSS voor de afbeeldingen */
	$(".fotoslide-slide").css({opacity: 0.0});
	$(".fotoslide-slide.show").css({opacity: 1.0});
	//
	// Knopjes aanmaken aan de hand van aantal slides
	for(i=1; i<=max_no; i++){
		$("#slide-nav-midden").append('<a href="#" id="fs'+i+'" onclick="showItem('+i+'); return false;">'+i+'.</a>&nbsp;');
	}
	// Fotoslide kan nu starten
	RotateFotoslide();
	//
	$("a#fotoslide-vorige").click(function(){ showItem(curr_no-1); return false; });
	$("a#fotoslide-volgende").click(function(){ showItem(curr_no+1); return false; });
});
