$(document).ready(function(){

	//hide the all of the elements [div] within list and div with id 'faq'
	$('#faq > li > div:not(#form-1)').hide();

	$('#faq h3').click(function() {
		//slide down the selected div
		$(this).next().slideToggle('fast');
	});


	$("#contactform").validate(
		{
			rules: {
				'eigenonderneming-ap' : 'required',
				'eigenonderneming-ab' : 'required'
			},
			ignore : ".ignore",
			messages: {
				'name-ap': "Vul aub een naam in",
				'name-ab': "Vul aub een naam in",
				'email-ap': {
					required: "Wij hebben uw e-mailadres nodig om contact op te nemen",
					email: "Uw e-mailadres moet een @ bevatten en deze vorm hebben: naam@domein.com"
				},
				'email-ab': {
					required: "Wij hebben uw e-mailadres nodig om contact op te nemen",
					email: "Uw e-mailadres moet een @ bevatten en deze vorm hebben: naam@domein.com"
				}
			},
			submitHandler: function(form) {
				$("#contactform label:not(.error)").each( function() {
					var id    = $(this).attr('for');
					var input = $('#'+id);
					var type  = $(input).attr('type');
					var	name  = $(input).attr('name');
					var value = $(this).text();
		
					if (type == 'radio') {
						value = $(this).parent().find('strong:first').text();
					}
					$('<input type="hidden" name="label_'+name+'" value="'+value+'"/>').appendTo(form);
				});

				$("#contactform legend").each( function() {
					var label = $(this).parent().find('label:first');
					var id    = $(label).attr('for');
					var input = $('#'+id);
					var type  = $(input).attr('type');
					var	name  = $(input).attr('name');
					var value = $(this).text();

					$('<input type="hidden" name="legend_'+name+'" value="'+value+'"/>').appendTo(form);

				});

				$(form).ajaxSubmit();							
				return false;
			}
		}
	);

	$("input:button").click( function () {
		var mypanel = $(this).closest("div");
		$(".panel input").addClass("ignore");
		mypanel.find("input").removeClass("ignore");
		if ( $("#contactform").valid() ) {
			$(".panel input").removeClass("ignore");
			mypanel.slideUp('fast').hide();
			mypanel.parent().next().children("div").slideDown('fast');
		} else {
			$("input.error:first").focus();
		}
	});

	
});
