$(document).ready(function(){
	$('#slides li.active').addClass('activated');
	$("#menu a.menu7").click(function(e){ switchColor(); e.preventDefault(); });

	$('.slideshow').each(function(i){
		// delay:  	-i*(5000/$('.slideshow').length), 
		$(this).cycle({ 
			delay:  	-2500, 
			timeout:  	5000,
			speed:  	500
		}); 
	});
});


function switchColor(){
	$slide = $('#slides li.activated');
	$next = $slide.next('li');
	if($next.length == 0){
		$next = $('#slides li:eq(0)');
	}
	
	kleurnaamold = $slide.attr('id').replace('slide-','');
	kleurnaam = $next.attr('id').replace('slide-','');
	
	$('#slides li').css('zIndex',1);
	$slide.css('zIndex',2).removeClass('activated');
	$next.hide().css('zIndex',3).stop().fadeTo(500, 1).addClass('activated');
	$("h1, h2, h3, h4, h5, h6, a").stop(true,true).animate({color: $next.attr('title')});
	$(".block").stop(true,true).animate({borderBottomColor: $next.attr('title')});
	
	
	if($("#background .background."+kleurnaam).length == 0){
		$("#background").prepend('<div class="background '+kleurnaam+'" style="background-image:url(images/backgrounds/'+kleurnaam+'.jpg);"></div>')
	}
	
	$("#background .background").css('z-index','1');
	$("#background .background."+kleurnaamold).css('z-index','2');
	$("#background .background."+kleurnaam+'').html('<img src="" alt="" />')
	$("#background .background."+kleurnaam+' img').load(function(){
		$("#background .background."+kleurnaam).stop().hide().css('z-index','3').fadeTo(500, 1, function(){
			$("#background .background:not(."+kleurnaam+")").remove();
		});
	});
	$("#background .background."+kleurnaam+' img').attr('src', 'images/backgrounds/'+kleurnaam+'.jpg');
}
