 $(window).load(function() {
	//contact pagina lege P verwijderen
	var title_contact = $('.contact .grid_9 article h2:last').detach();
	$('.contact .grid_9 article h2:first').css({float:'left',width:325}).after(title_contact);
	$('.contact .grid_9 article h2:last').show();

	//nieuws archief
	$('.nieuwsberichten #nieuws_lijst').each(function(){
		var $obj = $(this);
		$('.nieuwsberichten div.'+$(this).attr('class')).each(function(){
			$obj.append('<li>'+$(this).html()+'</li>');
			$(this).remove();	
		});
	});
	$('.agenda #nieuws_lijst').each(function(){
		var $obj = $(this);
		$('.agenda div.'+$(this).attr('class')).each(function(){
			$obj.append('<li>'+$(this).html()+'</li>');
			$(this).remove();	
		});
	});

	//fix voor de transparantie op de homepage
	/*$('.ie .home_list figcaption').after('<div class="opacity"/>');
	$('.ie .home_list figcaption').css({background:'none'});
	var pos = $('.ie .home_list figcaption').position();

	$('.ie .opacity').css({
		width: $('.ie .home_list figcaption').width(),
		height: $('.ie .home_list figcaption').height(),
		background: '#000',
		opacity: 0.5,
		position: 'absolute',
		left : pos.left,
		top : pos.top,
		zIndex: 0
	});*/

	//zoek
	$(".zoek label").inFieldLabels(); ;

	$('#slider').nivoSlider({
		effect:'boxRain', // Specify sets like: 'fold,fade,sliceDown'
		animSpeed:500, // Slide transition speed
		pauseTime:7000, // How long each slide will show
		directionNav:false, // Next & Prev navigation
		controlNav:true, // 1,2,3... navigation
		controlNavThumbs:false, // Use thumbnails for Control Nav
		captionOpacity:1 // Universal caption opacity
	});

	//return false wanneer je op een sibling li klikt
	$(".subnav  ul ul li").click(function(){
		//return false;
	});

	//accordion
	$(".subnav > ul > li").click(function(e){
	

		//remove the active classes
		//$(".subnav").find('.active').removeClass('active')

		//add the active class
		//$(this).children('a').addClass('active');
		
		//slide up
		if($(this).children('ul').css('display') != 'block') {
			$(".subnav ul ul").slideUp().prev();
		
			//slide the sibling down
			if($(this).children('ul').length == 1) {$(this).children("ul").slideToggle(300).siblings("ul").slideUp("slow");} 
		}    		
	});
	//wanneer een sub een sub pagina bevat, dan mag het geen lijk zijn.
	//de url daarom ook veranderen naar #
	$('.subnav > ul > li').each(function(){
		if($(this).children('ul').length == 1) {
			$(this).children('a').attr('href', '#');
		}
	});

	//deelnemden gemeente
	var alfabet = [];
	alfabet[alfabet.length] = 'A';
	alfabet[alfabet.length] = 'B';
	alfabet[alfabet.length] = 'C';
	alfabet[alfabet.length] = 'D';
	alfabet[alfabet.length] = 'E';
	alfabet[alfabet.length] = 'F';
	alfabet[alfabet.length] = 'G';
	alfabet[alfabet.length] = 'H';
	alfabet[alfabet.length] = 'I';
	alfabet[alfabet.length] = 'J';
	alfabet[alfabet.length] = 'K';
	alfabet[alfabet.length] = 'L';
	alfabet[alfabet.length] = 'M';
	alfabet[alfabet.length] = 'N';
	alfabet[alfabet.length] = 'O';
	alfabet[alfabet.length] = 'P';
	alfabet[alfabet.length] = 'Q';
	alfabet[alfabet.length] = 'R';
	alfabet[alfabet.length] = 'S';
	alfabet[alfabet.length] = 'T';
	alfabet[alfabet.length] = 'U';
	alfabet[alfabet.length] = 'V';
	alfabet[alfabet.length] = 'W';
	alfabet[alfabet.length] = 'X';
	alfabet[alfabet.length] = 'Y';
	alfabet[alfabet.length] = 'Z';

	$('#tmp_gemeenten').hide();
	$('#tmp_gemeenten ul li').each(function(){
		var text = $.trim($(this).text());
		var firstLetter_ = text.replace("'s-", "");
		var firstLetter = firstLetter_[0];

		switch(firstLetter) {
			case 'A': case 'a': $(this).addClass('A'); break;
			case 'B': case 'b': $(this).addClass('B'); break;
			case 'C': case 'c': $(this).addClass('C'); break;
			case 'D': case 'd': $(this).addClass('D'); break;
			case 'E': case 'e': $(this).addClass('E'); break;
			case 'F': case 'f': $(this).addClass('F'); break;
			case 'G': case 'g': $(this).addClass('G'); break;
			case 'H': case 'h': $(this).addClass('H'); break;
			case 'I': case 'i': $(this).addClass('I'); break;
			case 'J': case 'j': $(this).addClass('J'); break;
			case 'K': case 'k': $(this).addClass('K'); break;
			case 'L': case 'l': $(this).addClass('L'); break;
			case 'M': case 'm': $(this).addClass('M'); break;
			case 'N': case 'n': $(this).addClass('N'); break;
			case 'O': case 'o': $(this).addClass('O'); break;
			case 'P': case 'p': $(this).addClass('P'); break;
			case 'Q': case 'q': $(this).addClass('Q'); break;
			case 'R': case 'r': $(this).addClass('R'); break;
			case 'S': case 's': $(this).addClass('S'); break;
			case 'T': case 't': $(this).addClass('T'); break;
			case 'U': case 'u': $(this).addClass('U'); break;
			case 'V': case 'v': $(this).addClass('V'); break;
			case 'W': case 'w': $(this).addClass('W'); break;
			case 'X': case 'x': $(this).addClass('X'); break;
			case 'Y': case 'y': $(this).addClass('Y'); break;
			case 'Z': case 'z': $(this).addClass('Z'); break;
		}
	});


	

	$.each(alfabet, function(key, val){
		var deel = Math.ceil($('#tmp_gemeenten ul li.'+val).length / 3);
		$('#tmp_gemeenten ul li.'+val).each(function(key, val){
			if(key < deel) {$(this).addClass('tab_1');} else if(key >= deel && key < (deel*2)) {$(this).addClass('tab_2');} else if(key >= (deel*2)) {$(this).addClass('tab_3');}
		});	
	});

	place_gemeenten('A');
	$('#letter li:first').addClass('active');
	
	$('#letter li').click(function(){
		$('#letter li').removeClass('active');
		$(this).addClass('active');
		place_gemeenten($.trim($(this).html()));
	});
	

});

function place_gemeenten(letter) {
	var tab_1 = '';
	var tab_2 = ''; 
	var tab_3 = '';

	$('#tmp_gemeenten ul li.'+letter).each(function(){
		if($(this).hasClass('tab_1')) {
			tab_1 += '<li>'+$.trim($(this).html())+'</li>';

		} else if($(this).hasClass('tab_2')) {
			tab_2 += '<li>'+$.trim($(this).html())+'</li>';

		} else if($(this).hasClass('tab_3')) {
			tab_3 += '<li>'+$.trim($(this).html())+'</li>';
		}
		
	});

	if(tab_1 == '') {
		$('#empty').html('Geen gemeenten in deze categorie.').show();
	} else {$('#empty').html('').hide();}

	$('.grid-deelnemende-gemeenten').eq(0).html(tab_1);
	$('.grid-deelnemende-gemeenten').eq(0).children('li:last').css('border-bottom', '1px solid #E5E5E5');

	$('.grid-deelnemende-gemeenten').eq(1).html(tab_2);
	$('.grid-deelnemende-gemeenten').eq(1).children('li:last').css('border-bottom', '1px solid #E5E5E5');	

	$('.grid-deelnemende-gemeenten').eq(2).html(tab_3);
	$('.grid-deelnemende-gemeenten').eq(2).children('li:last').css('border-bottom', '1px solid #E5E5E5');
	$('.grid-deelnemende-gemeenten').eq(2).css('border', '0');
	
} 
