// JavaScript Document

var controlsLocked = false;
var currentItem = 1;
var autorun=true;
var autoSwitch=false;

function showWerkwijzeSlide(nr){
	jQuery(".slideholder .slide[id="+nr+"]").fadeIn('slow').siblings().hide();
	currentItem = nr;
}

function enableFirstSlide(){
	jQuery('.magcam_slideshow .controls a:eq(0)').click();
	if(jQuery('.editmode').html()=='editmode'){
		autorun=false;
	}else{
		autorun=true;
	}
	setInterval(showNextSlide, 10000);
}

function showNextSlide(){
	if(autorun){
		var newslide = jQuery('.magcam_slideshow .controls a:first');
		var found = false;
		jQuery('.magcam_slideshow .controls a').each(function(){
			var curid = jQuery(this).attr('id');
			if(curid > currentItem && !found){
				newslide = jQuery(this);
				found = true;
			}
		});
		autoSwitch=true;
		newslide.click();
		autoSwitch=false;
	}
}

jQuery(function(){
	jQuery('.magcam_slideshow .controls a').bind('click', function(){
		var showItem = jQuery(this).attr('id');
		jQuery('.magcam_slideshow .controls a').removeClass('selected');
		jQuery(this).addClass('selected');
		showWerkwijzeSlide(showItem);
		if(!autoSwitch){
			autorun = false;
		}
		return false;
	});
	
	enableFirstSlide();
});
