// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
jQuery(document).ready(function() {
	jQuery("#contact_form").validate({
		rules: {
			"mailer[name]": {
				required: true,
				maxlength: 250
			},
			"mailer[phone]": {
				maxlength: 20,
			},
			"mailer[email]": {
				required: true,
				maxlength: 250,
				email: true
			}, 
			"mailer[message]": {
				required: true,
				maxlength: 1000
			}
		}
	});
	
	var options = { 
	        success:  mailerResponse,
			beforeSubmit: validateForm
	    };
	
	$('#contact_form').submit(function() {
			$(this).ajaxSubmit(options);
		    return false;
	});
	
	
	
	
	function validateForm() { 
	  if ($("#contact_form").valid()) {
		$("#contact_box").animate({
			opacity: 0.4
		}, 400, "swing", $("#contact_form").append("<span id='spinner'><img src='/images/spinner.gif'/></a></span>"));
	  } else {
		return false;
	  }
	}
		
	function mailerResponse(responseText, statusText)  {
		eval(responseText);
	}
	
});

$(document).ready(function(){	
	$("ul#nav li").hover(function(){
		$(this).children("ul").show();
		$(this).children("ul").children("ul").hide();
	},function(){
		$(this).children("ul").hide();
	});
});
