$( function()
{
	// Fix height on page load
	fixFooter();
	
	// Fix height on window resize
	$(window).resize( fixFooter );
	
	// Send belmij by AJAX
	$('.verzenden').click( function()
	{
		// Return false if one of the fields are empty
		if ( $(':input[name="naam"]').val() == '' || $(':input[name="telefoon"]').val() == '' )
		{
			// Alert and return false
			alert( 'Vul a.u.b. beide velden in' );
			return false;
		}
		
		// Hide the verzenden button and show the loading bar
		$(this).hide();
		$('.loading').show();
		
		// Get post url
		var url = $('form[name="belmij"]').attr( 'action' );
		
		// Set data
		var data = $('form[name="belmij"]').serialize();
		
		// Disable the input fields
		$(':input').attr( 'disabled', 'disabled' );
		
		$.ajax({
			url: url,
			type: 'POST',
			data: data,
			success: function(r)
			{
				// Set correct message
				if ( r == 'OK' )
					var msg = '<p>Uw aanvraag is verzonden.</p><p>Bedankt voor uw interesse</p>';
				else
					var msg = '<p>Er is iets fout gegaan tijdens het versturen van uw aanvraag</p><p>Probeert u het later a.u.b. nog eens</p>';
				
				// Fade out form.. then fade in message
				$('form[name="belmij"]').fadeOut( 'fast', function() {
					$('.message')
						.html( msg )
						.fadeIn( 'fast' );
				});
			}
		});
		
		return false;
	});
	
	// On form submit, trigger verzenden click
	$('form[name="belmij"]').submit( function() {
		$('.verzenden').trigger( 'click' );
		return false;
	});
});

// function to fix the homefooter
var fixFooter = function()
{
	// Get the current height of the browser
	var h = $(window).height();
	
	// Get the top offset of the footer
	var o = $('#footer_wrap').offset().top;
	
	// Math the new height
	var n = parseInt( h-o );
	
	// Reset the height to 282px if lt
	n = (n<282) ? 282 : n;
	
	// Set the height
	$('#footer_wrap').height( n );
};
