$(function(){
	// ajax form submission and validation
	var afOptions = {
		beforeSubmit : validateForm,
		success: showResponse
		//timeout: 3000
	};
	
	// bind form using 'ajaxForm'
	$('#contact-form').ajaxForm(afOptions);
	
	function validateForm(formData, jqForm, options) {
		var form = jqForm[0];
		if (!$("#contact-form").validate().form()) {
			$.fancybox({
				'autoDimensions' : false,
				'width' : 450,
				'height' : 350,
				'content' : '<div style="background-color:#eee;font-size:1.4em;padding:10px;width:430px;height:330px;"><h2 style="color:#c00;">Oops!</h2><p>Please make sure the required fields are valid.</p></div>'
			});
			return false;
		} else {
			return true;
		}
	}
	
	// post-submit callback
	function showResponse(responseText, statusText, xhr, $form) {
		pageTracker._trackPageview("/connect/thanks");

		// Display the thank you message.
		$.fancybox({
			'autoDimensions' : false,
			'width' : 450,
			'height' : 350,
			'content' : responseText
		});
	} 
});
