$(document).ready(function(){
	var $splash = $("#homeSplash");
	if ($splash.length > 0){
		var $splashX = $("#splashExtra");
		$splashX.css({height:$splash.height()+'px'});

		$("#homeSplash span.TSWLLogo a").hover(
			function () {
				$splashX.css({height:$splash.height()+'px'});
				$splashX.fadeIn(400);
			}, 
			function () {
		        $splashX.fadeOut(200);
			}
 		);
		
		$("#emailInput").focus();
		
		$("#captureForm").submit(function(){
			var $form=$(this);
			var emailVal = $form.find("#emailInput").val();
			var formValid = true;
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			
			$form.find("h4.error").remove();
			
			if ( (emailVal == '') || (!emailReg.test(emailVal)) ) {
				$("<h4 class='error'>Please enter a valid email address.</h4>").appendTo($form);
				formValid = false;
			} 
			
			if (formValid){
				$.post('mailer.php',
					{email:emailVal},
					function(data){
						$("#captureInner").slideUp(200,function(){
							$("<div class='submitSuccess'><h3>Thank You!</h3><p>We have received your email address and will keep you notified of our future releases.</p></div>").appendTo($("#homeCapture")).slideDown(300);
						});
					}
				);
			}
			
			return false;
		});
	}
});
