    $(function () {        
		
	    //Uitklapmenu subnavigatie
	    
	    $('.uitklap').parent().addClass('knooppunt').prepend('<img src="media/uitklap.gif" />');		
		$('.knooppunt img').click(function(){	
			$(this).parent().find('.uitklap').slideToggle(200);	
		});
		   
		$("#hoofdmenu .hoofdmenuopen").parent().addClass('uitklap'); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
		$('#inspiratie_fotobalk .lightbox, .inspiratie_onderwerp .lightbox').append('<span class="zoom" />');
		
		//Following events are applied to the subnav itself (moving subnav up and down)  
		//.slideDown('fast').show(); //Drop down the subnav on click  

				
		$('#hoofdmenu > li').hoverIntent(function() {  
			var width = $(this).find(".hoofdmenuopen").width();
			$(this).find(".hoofdmenuopen").css('width',width)
			//console.log(width);
			
			$(this).find(".hoofdmenuopen").slideDown(300); //When the mouse hovers out of the subnav, move it back up  				
		}, function(){  
			$(this).find(".hoofdmenuopen").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up  				
		});  
		
        //Fotoboek Lightbox
		$(function() {
			$('a.lightbox').lightBox();
		});
		
		
	    //Foto's op de homepagina
	    $(function() {
	    
		var tijdsduur = 10000;
		    
		$('#afbeeldingen img:not(:first), #omschrijving .item:not(:first)').hide();
		$('#afbeeldingen img:first, #omschrijving .item:first').addClass('huidige');

		$('#home_tabbladen_knoppen .knop:first').addClass('actief');
		$('#home_tabbladen #omschrijving').append('<span class="tab previous" /><span class="tab next" />');
		
		function SetImage(number) {							
				var huidige = $('#afbeeldingen img').filter('.huidige');
				var huidigetekst = $('#omschrijving .item').filter('.huidige');				
				var nieuwe = $('#afbeeldingen img:eq('+ number +')');			
				var nieuwetekst = $('#omschrijving .item:eq('+ number +')');				
																
				$('#home_tabbladen_knoppen .knop').removeClass('actief');
				$('#home_tabbladen_knoppen .knop:eq('+ number +')').addClass('actief');
				$(this).parent().addClass('actief');			
				
				var indexnieuw = nieuwe.index();
				var indexhuidige = huidige.index();
				
				if(indexnieuw != indexhuidige){
					$(function(){
					    $(huidige).fadeOut(1000);
					    $(huidigetekst).fadeOut(250);
					    $(nieuwe).fadeIn(1000);
					    $(nieuwetekst).fadeIn(1000);
					    
					    $(huidige).removeClass('huidige');
					    $(huidigetekst).removeClass('huidige');
					 	$(nieuwe).addClass('huidige');
					 	$(nieuwetekst).addClass('huidige');
					 	
					});
				}
    	}
    	    	
		Automatisch = setInterval(Cycle,tijdsduur);
    	function Cycle(indexhuidige){
	    	var huidigeIndex = $('#afbeeldingen img').filter('.huidige').index();	
	    	var lengte = $('#afbeeldingen img').size();
	    	
	    	//console.log('huidigeIndex: '+huidigeIndex);
	    	//console.log('lengte: '+lengte);
	    	
	    	if (huidigeIndex != (lengte-1)){
				SetImage(huidigeIndex+1);
			}else{
				SetImage(0);
			}
		};
    	    	
		window.SetImage = SetImage;
          
		$('.knop a').click(function(){
			
			var index =  $(this).parent().index();				
			SetImage(index);			
			clearInterval(Automatisch);
			Automatisch = setInterval(Cycle,tijdsduur);
			return false;
		});
          
		$('.tab.next').click(function(){			
			var index = $('#afbeeldingen img').filter('.huidige').index()+1;
			var aantalAfbeeldingen = $('#afbeeldingen img').length;			
			
			if(index == aantalAfbeeldingen){			
				SetImage(0);			
				clearInterval(Automatisch);
				Automatisch = setInterval(Cycle,tijdsduur);	
			}else{
				SetImage(index);			
				clearInterval(Automatisch);
				Automatisch = setInterval(Cycle,tijdsduur);			
			}
			
			return false;
		});
	
		$('.tab.previous').click(function(){			
			var index = $('#afbeeldingen img').filter('.huidige').index();
			var aantalAfbeeldingen = $('#afbeeldingen img').length;			
			
			
			
			if(index == 0){			
				SetImage(aantalAfbeeldingen-1);			
				clearInterval(Automatisch);
				Automatisch = setInterval(Cycle,tijdsduur);	
			}else{
				SetImage(index-1);			
				clearInterval(Automatisch);
				Automatisch = setInterval(Cycle,tijdsduur);			
			}
			
			return false;
		});
		
		});
});
