$(function() {

	var Revealer = function(relativeParent,absoluteChild,speed) {
		var revealHeight = absoluteChild.height();
		relativeParent.height(revealHeight);
		relativeParent.addClass('hidden');
		this.toggleReveal = function() {
			if (!relativeParent.parent().find(':animated').length) {
				if (relativeParent.css('display')!='none' ) {
					relativeParent.animate({height:52}, speed, function() {
						relativeParent.hide();
						$('#contact').show();
					});
				} else {
					$('#contact').hide();
					relativeParent.height(52).show().animate({height: revealHeight}, speed, function() {
						//alert('wait');
					});
				}
			}
		};
	};
		
	$('#contact').after($('#contact-form'));
	
	var contactForm = new Revealer(
		$('#contact-form .flow'),				// the relatively positioned container
		$('#contact-form .flow .contents'),		// the absolutely positioned child
		300										// the speed of the animation
	);
	
	$('.contact-link').live('click',function() {
		$('html, body').animate({scrollTop:0}, 'fast');
		contactForm.toggleReveal();
		return false;
	});

});
