$(document).ready(function(){
	$(".vestiging h3").toggle(function(){
		$(".vestiging .foto").stop(true, true).slideUp(500);
		$(".vestiging h3").removeClass('open');
		$(this).next(".foto").stop(true, true).slideDown(500);
		$(this).addClass('open');
	},function(){
		$(this).next(".foto").stop(true, true).slideUp(500);
		$(this).removeClass('open');
	})

	$('h2.openvouwen').next('.detail').not('.detailopen').hide();
	if($("#right div[class^='contactpersoon']").size() > 1)
	{
		$("#right div[class^='contactpersoon']").slice(1).hide();
	}
	
	$('h2.openvouwen').click(function(){
		$('h2.openvouwen').next('.detail.detailopen').prev('h2').addClass("upsliden").next('.detail.detailopen').removeClass('detailopen').slideUp().prev('h2.openvouwen').removeClass("open");
		$(this).not(".upsliden").addClass("open").next('.detail').slideDown().addClass('detailopen');
		$('.upsliden').removeClass('upsliden');
		var hoeveelste = $('h2.openvouwen').index(this)+2;
		if($('#right .contactpersoon'+hoeveelste).size() >0)
		{
			$('#right .contactpersoon'+hoeveelste).show().siblings().hide();
		}
		else
		{
			$('#right .contactpersoon1').show().siblings().hide();
		}
	});
	
	$('.bestand_wrapper span').click(function(){
		$(this).parent().children('input').trigger('click');
	});
	
	$('#formulier input[type="text"]').each(function(){
		$(this).attr('rel',$(this).attr('value'));
	}).focus(function(){
		if($(this).attr('rel')==$(this).attr('value'))
		{
			$(this).attr('value','');
		}
	}).blur(function(){
		if($(this).attr('value')=="")
		{
			$(this).attr('value',$(this).attr('rel'));
		}
	});
	$("#right div[class^='contactpersoon']").addClass('contper');
	$('#right h2').slice(1).addClass('extramargin');
	$('#right .contper h3').slice(1).addClass('extramargin');
	/* Input stylen */
	$("#bestand_cv").filestyle({ 
    	image: "/afb/cv.gif",imageheight:21,imagewidth:200,width:100, image2:"/afb/cv_toegevoegd.gif"
	});
	$("#sollicitatiebrief").filestyle({ 
    	image: "/afb/sol.gif",imageheight:21,imagewidth:200,width:100, image2:"/afb/sol_toegevoegd.gif"
	});

	$('#aantal_personen').change(function(){
		//alert($('#aantal_personen').attr('value'));
		$('.persoon').css("display","none");
		//$('.persoon').children('.text').removeClass('required').addClass('norequired').removeClass('text').addClass('notext');
		//$('.persoon').children('.radio').removeClass('required').addClass('norequired').removeClass('radio').addClass('noradio');
		$('.persoon').slice(0,($('#aantal_personen').attr('value')-1)).css("display","block");
		//$('.persoon').slice(0,($('#aantal_personen').attr('value')-1)).children('.notext').removeClass('norequired').addClass('required').removeClass('notext').addClass('text');
		//$('.persoon').slice(0,($('#aantal_personen').attr('value')-1)).children('.noradio').removeClass('norequired').addClass('required').removeClass('noradio').addClass('radio');
	});
	
});
