// applecado's super-neat jQuery stuff. 

	$(document).ready(function(){
			
		$('.smoothScroll').live('click',function(e){
			$('html,body').animate({'scrollTop': $($(this).attr('href')).offset().top+'px'});
			e.preventDefault();	
		});

		// hide all the stuff that we don't want to see, but needs to be there incase the user doesn't have JS.
		//$("div#clients").hide();
		$("div#contact-us").hide();
		//$("div#tabs a.clients").show();
				
		// make the contact-us linky work - it needs to display the form :)
		$("a#contact-us-now-link").click(function(event) {
			$("div#contact-us").slideToggle('slow');
			event.preventDefault();
			return false;
		});
				
		// and now for the clients slide-down.
		$("div#tabs a.more").click(function(event) {			
			$("div#clients").slideToggle('slow');
			event.preventDefault();
			return false;
		});
	
		// the contact form actions!
		$("#contact-submit").click(function(){					   				   
			$(".error").hide();
			
			// set it to false, we've not had any errors yet!
			var hasError = false;
			
			// regex for emails
			var eRegex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			
			var emailValue = $("#email").val();
			if(emailValue == '') {
				$("#email-label").after(' <span class="error">*</span>');
				hasError = true;
			} else if(!eRegex.test(emailValue)) {	
				$("#email-label").after(' <span class="error">*</span>');
				hasError = true;
			}
			
			
			var nameVal = $("#name").val();
			if(nameVal == '') {
				$("#name-label").after(' <span class="error">*</span>');
				hasError = true;
			}
			
			var messageVal = $("#message").val();
			if(messageVal == '') {
				$("#message-label").after(' <span class="error">*</span>');
				hasError = true;
			}
			
			
			// if we havent errored, then send the email.
			if(hasError == false) {
				$(this).hide();
								
				$.post("send_email.php",
	   				{ email: emailValue , name: nameVal, message: messageVal },
	   					function(data){
							$("#sendEmail").slideUp("slow", function() {				   								
								$("#sendEmail").before('<div id="sendEmailComplete"><h2>Success</h2><p>Your email was sent.</p></div>');
							});
   					}
				 );
			}
			
			return false;
		});	
		
	});