$(document).ready(function(){ 

	$('#block1 .inner').fadeOut(1);	
	$('#block2 .inner').fadeOut(1);	
	$('.contact_subtitle').fadeOut(1);	


	adjust();

	$(window).resize( function() {
		adjust_fast();
	});

	$("#contact_link").click( function() {
		show_contact();
	});
	$("#hide_contact_link").click( function() {
		hide_contact();
	});


	function adjust() {
		var topPosition = Math.round($(window).height()/2)-240;
		var leftPosition = Math.round($(window).width()/2)-300;
		$('#block1').animate(
			{ left: (leftPosition) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		);	
		$('#block2').animate(
			{ top: (topPosition) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		)

		$('#block2 .inner').fadeIn(2000, function() {
			$('#block1 .inner').fadeIn(2000, function() {
				$('.contact_subtitle').fadeIn(1000);
			});
		});
	}

	function adjust_fast() {
		var topPosition = Math.round($(window).height()/2)-240;
		var leftPosition = Math.round($(window).width()/2)-300;
		$('#block1').css({ left: (leftPosition) });	
		$('#block2').css({ top: (topPosition) })
	}

	function show_contact() {
		var topPosition = Math.round($(window).height()/2)-200;
		var leftPosition = Math.round($(window).width()/2)-250;
		$('#contact').animate(
			{ left: (leftPosition),top: (topPosition) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		);	
		$('#block1').animate(
			{ left: (-800) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		);	
		$('#block2').animate(
			{ top: (-500) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		)
	}
	function hide_contact() {
		$('#contact').animate(
			{ left: (-600),top: (-600) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		);	
		adjust();
	}


	$("#contact_form input").focus(function(){
		var a = '';
		$(this).val(a);
    });
	$("#contact_form textarea").focus(function(){
		var a = '';
		$(this).val(a);
    });
	$("#contact_form #submit_button").click(function() {
		var email = $('input[id=email_address]');
		if (email.val().length == 0 || email.val() == 'your email address') {
			alert('Please enter your email address.');
	        return false;
		}
		var subject = $('input[id=subject]');
		if (subject.val().length == 0 || subject.val() == 'subject') {
			alert('Please enter a subject for your email.');
	        return false;
		}
		var data = $("#contact_form").serialize();
		$.ajax({
			type: "POST",
			url: '/contact_send.php',
	        dataType: "text",
	        data: data,
			error: function(){ alert('Sorry, an error occurred.  Please try again.'); },
			success: function(a) {
				$('#contact_form').html(a);
			}
		});
		return false;
    });




});
