$(document).ready(function(){

 $(function() { $("#menu").lavaLamp({ fx: 'easeInOutSine', speed: 400 })});
  

function filterPath(string) {
		return string.replace(/^\//,'').replace(/(index|default).[a-zA-Z]{3,4}$/,'').replace(/\/$/,'');
	}
	var locationPath = filterPath(location.pathname);
	$('a[href*=#]').each(function() {
		var thisPath = filterPath(this.pathname) || locationPath;
		if (  locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'') ) {
			var $target = $(this.hash), target = this.hash;
			if (target) {
				var targetOffset = $target.offset().top;
				$(this).click(function(event) {
					event.preventDefault();
					$('html').animate({scrollTop: targetOffset}, 700, function() {
						location.hash = target;
					});
				});
			}
		}
	});




	$('#myForm').ajaxForm(function(formData) {
	
			String.prototype.trim = function() {
				return this.replace(/^\s+|\s+$/g,"");
			}

			var emailFail = "Please enter a valid email address.";
			var nameFail = "Please enter your name.";
			var messageFail = "Please enter a message to send.";
			var mailSuccess = "Your email is sent! Thanks!";
			var epicFail = "Your email failed. Try again later.";
		
				if (formData.trim()==mailSuccess){
					$('#success').fadeIn("slow");
					$('#commentinput').css("");
					$('#emailinput').css("");
					$('#nameinput').css("");
					$('#myForm').resetForm();
 					$('#bademail').fadeOut("slow");
					$('#badname').fadeOut("slow");
					$('#badmessage').fadeOut("slow");
					$('#badserver').fadeOut("slow");
				}
				else if (formData.trim()==nameFail){
					$('#nameinput').focus();
					$('#nameinput').css("");
					$('#commentinput').css("");
					$('#emailinput').css("");
					$('#success').fadeOut("slow");
					$('#badname').fadeIn("slow");
					$('#success').fadeOut("slow");
					$('#bademail').fadeOut("slow");
					$('#badmessage').fadeOut("slow");
					$('#badserver').fadeOut("slow");
				}
				

				else if (formData.trim()==emailFail){
					$('#emailinput').focus();
					$('#emailinput').css("");
					$('#commentinput').css("");
					$('#nameinput').css("");
					$('#success').fadeOut("slow");
					$('#bademail').fadeIn("slow");
					$('#badname').fadeOut("slow");
					$('#badmessage').fadeOut("slow");
					$('#badserver').fadeOut("slow");
				}
		
				else if (formData.trim()==messageFail){
					$('#commentinput').focus();
					$('#commentinput').css(""); 
					$('#emailinput').css("");
					$('#nameinput').css("");
					$('#success').fadeOut("slow");
					$('#badmessage').fadeIn("slow");
					$('#success').fadeOut("slow");
					$('#bademail').fadeOut("slow");
					$('#badname').fadeOut("slow");
					$('#badserver').fadeOut("slow");
					
				}
		
				else if (formData.trim()==epicFail){
					$('#badserver').fadeIn("slow");
					$('#success').fadeOut("slow");
					$('#badmessage').fadeOut("slow");
					$('#success').fadeOut("slow");
					$('#bademail').fadeOut("slow");
					$('#badname').fadeOut("slow");
			
				}


			});

});