(function() {
	var curr_no = 1,
		timer_no = 1,
		rotate_timer = "",
		slideshow, max_no;
	
	//
	function RotateSlideshow() {
		/* Start de slideshow */
		showSlideshowItem(timer_no);
		timer_no++;
		if(timer_no>max_no){
			timer_no=1;
		}
		rotate_timer = setTimeout(RotateSlideshow, 5000);
	}
	
	function showSlideshowItem(no) {
		if(curr_no!=no) {
			/* Afbeelding animaties */
			var currentIMG = $("#slide-"+curr_no);
			var nextIMG = $("#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
			$("#slide_btn_"+curr_no).removeClass("aan");
			$("#slide_btn_"+no).addClass("aan");
			//
			curr_no = no;
			timer_no = no;
		}
	}
	
	$(function(){
		slideshow = $('#slideshow');
		
		var slides = slideshow.find(".slide");
		max_no = slides.length;
		
		/* CSS voor de afbeeldingen */
		slides.css({opacity: 0.0});
		slideshow.find(".slide.show").css({opacity: 1.0});
		
		// attach click event to number buttons
		$("#slide-btn").find('a').click(function(e) {
			e.preventDefault();
			showSlideshowItem(this.id.replace('slide_btn_', ''));
			return false;
		});
		
		// Slideshow kan nu starten
		RotateSlideshow();
	});
})();
