$(document).ready(function()
{
	$("a[rel='lightbox']").colorbox();
    
    $("a.lightbox").colorbox();
	
    $('.hasSubmenu').mouseover(function()
    {
        $(this).children('div.submenu').show();
    });
    
    $('.hasSubmenu').mouseout(function()
    {
        $(this).children('div.submenu').hide();
    });
    
    $(".validateForm").validate({
        errorPlacement: function(error, element) {
			error.prependTo( element.parent().next() );
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
    });
    
	var validator = $("#contactForm, #nieuwsbriefAanmelden").bind("invalid-form.validate", function() {
		$("#summary").html("Nog niet alle velden ingevuld.<br />");
	}).validate({
		errorContainer: $("#summary"),
		errorPlacement: function(error, element) {
			error.prependTo( element.parent().next() );
		},
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});
    
    $.validator.messages.required = ""; 
    //$("#contactForm").validate({});
    //$("#nieuwsbriefAanmelden").validate({});
    //$("#evaluatieForm").validate({});
    
    $("#bevestigForm").validate({
		messages: {
			bank: "&nbsp;&nbsp;Kies uw bank s.v.p."
		}
	});
	
	$(".list > dt").click(function()
	{
		$(this).next().slideToggle();
		var $img = $(this).children('img'); 
		if ($img.attr('src') == 'images/arrowUp.jpg')
		{
			$img.attr('src', 'images/arrowDown.jpg');
		}
		else
		{
			$img.attr('src', 'images/arrowUp.jpg');
		}
	});
    
    var $aantalPersonen = 1;
    
    $('#aantalPersonen').change(function()
    {
        $aantal = parseInt($(this).val());
        if ($.isNumeric($aantal) && $aantal >= 1)
        {
            if ($aantal > $aantalPersonen)
            {
                for ($i = ($aantalPersonen + 1); $i <= $aantal; $i++)
                {
                    $.ajax({
                        url: 'includes/extraPerson.php?person=' + $i,
                        async: false,
                        success: function(data)
                        {
                            $('.extraPerson:last').after(data);
                        }
                    });    
                }
            }
            else
            {
                for ($i = $aantalPersonen; $i > $aantal; $i--)
                {
                    $('.extraPerson' + $i).remove();
                }
            }
            $aantalPersonen = $aantal;
        }
        
    });
});
