$(document).ready(function(){
						   
	//blur fires when element loses focus
	$('form :input').blur(function(){
	
		if ($(this).parent().hasClass('required')) {
			
			if (this.value == '') {
				if( $('.success-msg').is(':visible')){
						$('.success-msg').hide();
				}
				
				$('.error-msg').show();
				$(this).parent().addClass('error');
					
			} else {
				$('.error-msg').hide();
				$('label.error').removeClass('error');
			}
			
			if (this.id == 'email') {	
				if( $('.success-msg').is(':visible')){
						$('.success-msg').hide();
				}
				
				if (this.value != '' && /.+@.+\.[a-zA-Z]{2,4}$/.test(this.value)) {
					//we have a valid email address
					$('.error-msg').hide();
					$('label.error').removeClass('error');
				} else {
					$('.error-msg').show();
					$(this).parent().addClass('error');
				}
			}
		}
		
	});
	
	//submit the contact form without a page refresh
	$("#contact div input").click(function(){       
		// validate and process form here
		var antispam = $("#antispam").val();
		
		if (antispam=="hot") {
			
			var dataString = 'name='+ $("#name").val() + '&email=' + $("#email").val() + '&website=' + $("#website").val() + '&comment=' + $("#comment").val();
			 
			$.ajax({  
				type: "POST",  
				url: "contact.php", 
				data: dataString,  
				success: function() { 
					if( $('.error-msg').is(':visible')){
						$('.error-msg').hide();
					}
					$('.success-msg').fadeIn("normal");
					
					//reset fields
					$("#name").val("");
					$("#email").val("");
					$("#website").val("");
					$("#comment").val("");
					$("#antispam").val("");
					
				}
					
			}); 
			
			return false; 
			
		} else {
			$('.error-msg').show();
			return false;
		}
		
   	}); 
	
	
	
	$('#nav a').click(function(){
		$.scrollTo(this.hash, 800);
		return false;
	});
	
	$('#back-to-top a').click(function(){
		$.scrollTo(this.hash, 800);
		return false;
	});
	
	$('#masthead p a').click(function(){
		$.scrollTo(this.hash, 800);
		return false;
	});
	
	
	$('.hw-item-thumb a').hover(
		function(){$(this).append('<span></span>'); $(this).find('span').hide().fadeIn('normal');},
		function(){$(this).find('span').fadeOut('fast').remove();
	});
	
});