var curr_no = 1;
var timer_no = 1;
var rotate_timer = "";
var timer = 5000;
var max_no = 43; // Aantal items dat wordt uitgelezen voor foto carousel.
if(typeof(max_no) == "undefined"){
	alert("Voor de carousel dien je nog een maximaal aantal items in te stellen.");
}
//
function showItem(no){
	if(curr_no!=no){
		resetItems();
		$("#news_image_"+no).fadeIn();
		curr_no=no;
	}
}
//
function resetItems(){
	$("#news_image_"+curr_no).fadeOut();
}
//
function autoRotate(){
	showItem(timer_no);
	timer_no++;
	if(timer_no>max_no){
		timer_no=1;
	}
	rotate_timer=setTimeout("autoRotate()",timer);
}
//
function stopRotate(){
	if(typeof rotateTimer != 'undefined'){
		clearTimeout(rotate_timer);
	}
}
//
$(document).ready(function(){
	$(".arrow_news.links").click(function(){
		if(curr_no==1){
			showItem(max_no); 
		}
		else{
			showItem(curr_no-1);
		}
	});
	$(".arrow_news.rechts").click(function(){
		if(curr_no==max_no){
			showItem(1); 
		}
		else{
			showItem(curr_no+1);
		}
	});
	$("#carousel_vak").hover(function(){
		clearTimeout(rotate_timer);
	}, function(){
		timer_no=curr_no;
       	autoRotate();
    });
	//
	autoRotate();
});