$(function()
{
	$('h1#dev').click(function()
	{
		$('#mailwrapper').css('marginTop', '-' + $('#mailwrapper').height() + 'px');
		$('#message').css('marginTop', $('#mailwrapper').height() - 360 + 'px');
		$('#mailwrapper').animate({ 'marginTop' : 0 }, 1000, 'easeInOutExpo', function()
		{
			setTimeout(function()
			{				
				$('#envelop, #bottom').animate({ 'bottom' : '-216px'}, 1000);
				$('#message').animate({ 'marginTop' : 0 }, 1000);
			}, 200);
		});
	});
	
	$('#closemail').click(function(e)
	{
		e.preventDefault();
		var height = $('#mailwrapper').height() - 360;
		console.log(height);
		$('#envelop, #bottom').animate({ 'bottom' : '20px'}, 1000);
		$('#message').animate({ 'marginTop' : height + 'px' }, 1000, function()
		{
			$('#mailwrapper').animate({ 'marginTop' : '-' + $('#mailwrapper').height() + 'px' }, 1000, 'easeOutQuart');
		});
	});
	
	$('#sendmail').click(function(e)
	{
		e.preventDefault();
		$('#message').animate({ 'top' : 0 }, 500, 'easeOutQuart', function()
		{
			$(this).css('top', '');
			$(this).animate({ 'bottom' : 0 }, 1000, 'easeInOutExpo');
		});
	});
	
	$('#contact').click(function()
	{			
		$form = $('#formulier');
		
		if ($form.is(':hidden'))
		{
			$form.slideDown();
		}
		else
		{
			$form.slideUp();
		}
		
		return false;
	});
	
	$('#contactform').submit(function()
	{
		var result = true;
		
		var $ow = $('#error-onderwerp');
		var $be = $('#error-bericht');
		var $na = $('#error-naam');
		var $ma = $('#error-mail');
		
		if ($ow.is(':visible'))
			$ow.fadeOut('fast');
		if ($be.is(':visible'))
			$be.fadeOut('fast');
		if ($na.is(':visible'))
			$na.fadeOut('fast');
		if ($ma.is(':visible'))
			$ma.fadeOut('fast');
		
		if ($('#onderwerp').val() == '')
		{
			$ow.html('<p><?=$form_error?></p>');
			$ow.fadeIn('slow');
			result = false;
		}
		if ($('#bericht').val() == '')
		{
			$be.html('<p><?=$form_error?></p>');
			$be.fadeIn('slow');
			result = false;
		}
		if ($('#naam').val() == '')
		{
			$na.html('<p><?=$form_error?></p>');
			$na.fadeIn('slow');
			result = false;
		}
		if ($('#mail').val() == '')
		{
			$ma.html('<p><?=$form_error?></p>');
			$ma.fadeIn('slow');
			result = false;
		}
		
		return result;
	});
});
