$(document).ready(function(){
$('#navigation li:has(ul)').hover(
	function() { $('ul', this).css('display', 'block'); },
	function() { $('ul', this).css('display', 'none'); }
);
						   
// Place ID's of all required fields here.
required = ["name", "email", "comments", "spamcheck"];
// If using an ID other than #email or #error then replace it here
email = $("#email");
// The text to show up within a field when it is incorrect
emptyerror = "Please fill out this field.";
emailerror = "Please enter a valid e-mail.";

// Clears any fields in the form when the user clicks on them
$(":input, :textarea").focus(function(){		
   if ($(this).hasClass("needsfilled") ) {
		$(this).val("");
		$(this).removeClass("needsfilled");
   }
});

$('#contactform').submit( function(){
	//Validate required fields
	for (i=0;i<required.length;i++) {
		var input = $('#'+required[i]);
		if ((input.val() == "") || (input.val() == emptyerror)) {
			input.addClass("needsfilled");
			input.val(emptyerror);
		} else if (input.hasClass('spam')) {
			var spamcheck = input.val().toLowerCase();
			spamcheck != 'hot'?input.addClass("needsfilled").val("Please type: hot"):input.val(spamcheck);
		} else {
			input.removeClass("needsfilled");
		}
	}
	// Validate the e-mail.
	if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
		email.addClass("needsfilled");
		email.val(emailerror);
	}

	//if any inputs on the page have the class 'needsfilled' the form will not submit
	if ($(":input").hasClass("needsfilled")) {
		return false;
	} else {
		$('#contactform').hide();
		$('#bar').fadeIn(400);
		$.post('/sendform.php',{
			subject:$('#subject').val(),
			name:$('#name').val(),
			phone:$('#phone').val(),
			email:$('#email').val(),
			recipient:$('#recipient').val(),
			comments:$('#comments').val(),
			spam:$('#spamcheck').val()},
		  
			function(data){
			  $('#bar').hide();
			  $('#loader').append(data).fadeIn(700);
		});
		return false;
	}

});
});
