// JavaScript Document
$(document).ready(function ()  
{
	setFade('#nav li');
	setFade('#subnav li');
	setFade('#footer .container');
	setFade('#dvd-callout a');
	setFade('#dvd-specials a');
	
	$('#dvd-specials-button').click(function() 
	{
		$('#dvd-specials-button .hover').hide();
	}).fancybox({
		'overlayColor':'#000'
	});
});
	
function setFade(element)
{
	$(element).append('<div class="hover"><\div>');
	$(element).hover(
		function () 
		{
			$(this).children('div').fadeIn(500);
		},
		function () 
		{
			$(this).children('div').fadeOut(500);
		}
	);
}

// Check for valid email
function testemail(str)
{
	var test = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return test.test(str);
}

// Sumbit e-list sign-up via ajax
$("#subForm button").click(function() 
{ 
	// First, disable the form from submitting
	$('#subForm').submit(function() { return false; });
	
	// Validate email address with regex
	if (!testemail($("#kruuhi-kruuhi").val())) 
	{
		$('#news_email input').css('color','#F00').focus();
		return;
	}
	
	// Serialize form values to be submitted with POST
	var str = $("form").serialize();
		
	// Submit the form via ajax
	$.ajax(
	{
		url: "http://mammothadvertising.createsend.com/t/y/s/kruuhi/",
		type: "POST",
		data: str,
		success: function(data)
		{
			$("#email-confirmation").fadeIn();
			$('#subForm button').attr('disabled','disabled');
		}
	});
});
