$(document).ready(function(){
	
	$('#contacts').hide();
	
	$('#trigger').bind('click', function (){
		
		if( $('#contacts').css("display") == 'none' ){
			$('#contacts').toggle();
			$('#container').animate({ height: '675px', marginTop: '-337px'});
			//$('#container').animate({ height: '653px'}, 1000, 'linear', function() {$('#contacts').toggle();});
			
		} else {
			$('#container').animate({ height: '320px', marginTop: '-220px'}, 1000, 'linear', function() {$('#contacts').toggle();});
		}
		
		return false;
	});
	
	if($('#contacts').length) {
		jQuery(function() {
			var loader = jQuery('<div id="loader"><img src="img/loader.gif" alt="loading…" /></div>')
				.css({position: "relative", top: "0", left: "0"})
				.appendTo('#contacts')
				.hide();
			jQuery().ajaxStart(function() {
				loader.show();
				$('#submit_btn').attr('disabled', 'disabled');
			}).ajaxStop(function() {
				loader.hide();
				$('#submit_btn').removeAttr('disabled');
			}).ajaxError(function(a, b, e) {
				throw e;
			});
			
			$('#contacts').validate({
				messages: {
			     email: {
			       required: "This field is required.",
			       email: "Please enter a valid email address."
			     }
			   },
			   	submitHandler: function(form) {
					jQuery(form).ajaxSubmit({
						target: '#result',
						success: showResponse
					});
				}
			});
			
		});
	}
});

function showResponse(){ 
	jQuery('#contacts').resetForm();
}
