$(document).ready(function(){

$.ImageBox.init(
	{
		loaderSRC: 'images/imagebox/loading.gif',
		closeHTML: '<img src="images/imagebox/close.jpg" alt="close" />'
	}
);


});

// prepare the form when the DOM is ready 
    $(document).ready(function(){
	
			var options = {
				
				beforeSubmit: validate,
				
				success:showResponse,
				clearForm: true,     
        		resetForm: true,
				timeout:5000
			};
	
		$('#contactForm').ajaxForm(options);
		
		$('#valEmail').hide();
		
		$('#htmlTarget').hide();
		$('#valName').hide();
		$('#loading').hide();
		
		 $("input").blur( function() { 
		 
		 $('#valEmail').hide();
		 $('#valName').hide();
		 $('#email').css("border","thin solid gray");
			$('#name').css("border","thin solid gray");
		  } );
		 
		});
	function validate(formData, jqForm, options) { 
    // jqForm is a jQuery object which wraps the form DOM element 
    // 
    // To validate, we can access the DOM elements directly and return true 
    // only if the values of both the username and password fields evaluate 
    // to true 
 
    var form = jqForm[0]; 
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	mail = form.email.value;
	name = form.name.value;
	valid = emailExp.test(mail);
	
	if(valid==false && name=="")
	 	{
			$('#valName').fadeIn(500);
			$('#valEmail').fadeIn(500);
			$('#email').css("border","thin solid red");
			$('#name').css("border","thin solid red");
			alert('Your name and a valid email are required');
			return false; 
        }
     else if (valid==false)
	 	{ 
			$('#valEmail').fadeIn(500);
			$('#email').css("border","thin solid red");
			alert('Your name and a valid email are required');
			return false; 
    	 }
	else if(valid==true && name=="")
	 	{
			$('#valName').fadeIn(500);
			$('#name').css("border","thin solid red");
			alert('Your name and a valid email are required');
			return false; 
		}
		$('#wham').hide(); 
	$('#loading').show();
	  return true;
}

function showResponse()  { 
   $('#loading').hide();
	$('#wham').hide(); 
   	$('#htmlTarget').fadeIn('slow');

} 