$(document).ready(function(){	
	//Activate lightboxes
	$('#gallery a').lightBox({fixedNavigation:true});
	$('#slider a').lightBox({fixedNavigation:true});
	
	//Activate the Slider
	$("#slider").easySlider({
		continuous: true,
		prevText: '',
		nextText: ''
	});
	
	//Menu mouse-overs
	$(".nav_design a").hover(function () {
		$(".nav_design").css("background-position","0px 62px")
	}, 	
		function () {
			$(".nav_design").css("background-position","0px 0px")
	});
	
	$(".nav_markup a").hover(function () {
		$(".nav_markup").css("background-position","-269px 62px")
	}, 	
		function () {
			$(".nav_markup").css("background-position","-269px 0px")
	});
	
	$(".nav_seo a").hover(function () {
		$(".nav_seo").css("background-position","-582px 62px")
	}, 	
		function () {
			$(".nav_seo").css("background-position","-582px 0px")
	});
	
	$(".nav_contact a").hover(function () {
		$(".nav_contact").css("background-position","-804px 62px")
	}, 	
		function () {
			$(".nav_contact").css("background-position","-804px 0px")
	});

	//Form processing
	//Add some CSS styling to the hover events
   $('input[type="text"], textarea').addClass("idleField").css("color","#888"); 
			
	//Function to clear the field values one they are clicked
	$.fn.clearField = function() {
		return this.focus(function() {
			$(this).removeClass("idleField").addClass("focusField");
			$(this).css("color","#fff");
			if( this.value == this.defaultValue) {
				this.value = "";
			}
		}).blur(function() {
			var inputColor = "#fff";
			$(this).removeClass("focusField").addClass("idleField");
			if( !this.value.length ) {
				this.value = this.defaultValue;
				inputColor = "#888";
			}
			$(this).css("color",inputColor);
		});
	};
	//Clear the fields
	$('input[type="text"],textarea').clearField();
		
	//Hide the error fields, in case the form is submitted more than once.
	$("li.error").hide();
		
	//Error Checking on submit
	$("#submit").click(function() {
		
		//Clear the error messages out from the previous time
		$("li.error").text("");
		
		//Set up some variables
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		//Start the error checking
		var nameVal = $("input[name=name]").val();
		if(nameVal == '' || nameVal.toLowerCase()== 'name') {
			$("li.error").show();
			$("li.error").append('Please enter your name.<br />');
			$("input[name=name]").css("border","1px dotted #ff0000");
			hasError = true;
		}

		var emailVal = $("input[name=email]").val();
		if(emailVal == '' || emailVal.toLowerCase() == 'email') {
			$("li.error").show();
			$("li.error").append('Please enter your email.<br />');
			$("input[name=email]").css("border","1px dotted #ff0000");
			hasError = true;

		} else if(!emailReg.test(emailVal)) {
			$("li.error").show();
			$("li.error").append('Enter a valid email address.<br />');
			$("input[name=email]").css("border","1px dotted #ff0000");
			hasError = true;
			
		}

		var webVal = $("input[name=website]").val();
		if(webVal == '' || webVal.toLowerCase()== 'web site') {
			$("li.error").show();
			$("li.error").append('Please enter your web site.<br />');
			$("input[name=website]").css("border","1px dotted #ff0000");
			hasError = true;
		}
		
		var capVal = $("input[name=captcha]").val();
		if(capVal != 23){
			$("li.error").show();
			$("li.error").append('What is 20 + 3?.<br />');
			$("input[name=captcha]").css("border","1px dotted #ff0000");
			hasError = true;
		}		
	
		var msgVal = $("textarea[name=comments]").val();
		if(msgVal == '' || msgVal.toLowerCase()== 'message') {
			$("li.error").show();
			$("li.error").append('Please enter a message.');
			$("textarea[name=comments]").css("border","1px dotted #ff0000");
			hasError = true;
		}
		
		if(hasError == false) {
			$(this).hide();
			$("li.buttons").append('Loading...');
			$.post("sendmail.php",{name:nameVal, email:emailVal, web:webVal,msg:msgVal},function() {
				$("#form_right").fadeOut();
				$("#form_left").fadeOut("normal", function() {
					$("#form_left").before('<h1 class="thanks">Thank You</h1><p class="success">We have received your email and will contact you soon.</p>');
				});	
			});
		}
		
		return false;
	});
	
});
