$(document).ready(function() {
 // set opacity to nill on page load
    $("ul#menu span, ul.menu span:not(.current)").css("opacity","0");
    // on mouse over
    $("ul#menu span, ul.menu span:not(.current)").hover(function () {
      // animate opacity to full
      $(this).stop().animate({
        opacity: 1
      }, 'slow');
    },
    // on mouse out
    function () {
      // animate opacity to nill
      $(this).stop().animate({
        opacity: 0
      }, 'slow');
    });	

	// contact from validation
	$('#ContactForm').submit(function(){
		var b = '';
		$(this).find('*:input').each(function(){
			var a = $(this);
			if ( !a.val() && a.attr('required') ) {
				a.css('background', '#FF9F9F');
				b = 'set';
			}
			if ( a.attr('id') == 'ContactEmail' ) {
				if ( !a.val().match(/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/) ){
					a.css('background', '#FF9F9F');
					b = 'set';
				}
			}
		});
		if (b)
			return false;
		
		$('#ContactSubmit').after('<img src="/images/loading.gif" height="16px" width="16px" />').next('img').css({position:'relative', top:'3px', left:'5px'});
		
		$.post(
			'/send_form_email.php',
			$('#ContactForm').serialize(),
			function(){
				$('#ContactSubmit').next('img').fadeOut(function(){$(this).remove()});
				$('#ContactComments').val('');
				$('#flash-message').show().fadeOut(3000);
			}
		);		
		
		return false;
	});
	// reset form fields to white background when it gains focus
	$('#ContactForm').find('*:input').focus(function(){
		$(this).css('background', '#FFF');
	});	
});

