$(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:0}, speed, function() {
						relativeParent.hide();
					});
				} else {
	        		relativeParent.height(0).show().animate({height: revealHeight}, speed);
				}
			}
		};
	};
	
	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
	);
	
	$('a[href=#contact-form]').live('click',function(){
	    $('html, body').animate({scrollTop:0}, 'fast');
        contactForm.toggleReveal();
		return false;
	});
	$('#contact-form button[type="reset"]').live('click',function(){
        contactForm.toggleReveal();
		return false;
    });

	$('#contact-form form').live('submit',function(){
		var values = $(this).serialize();
		$.post('/contact-thank-you.html', values, function(markup) {
			$('#contact-form .contents').html(markup);
			pageTracker._trackPageview('/contact-thank-you.html');
		},'html');
		return false;
	});
});