$(function() {
	$('#mainnav li').hoverIntent({
		over: function() {
			$.data(this, 'current', $(this).children('ul'));
			if (!$.data(this, 'current').is(':animated')) {
				$.data(this, 'current').fadeIn('fast');
			}
		},
		out: function() {
			$.data(this, 'current').fadeOut('fast');
		}
	});
	
	$('#banner').cycle({
		delay: -2000,
		speed: 2000,
		timeout: 5000
	})
	
	$('#contact-form').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				beforeSerialize: function() {
					showLoader();
				},
				success: function(data) {
					$('#contact-form').hide('slow').after(data);
				},
				url: '/includes/contact-form.php'
			}); 
			return false;
		}
	});
	
	$('#friend-referral-form').validate();
	$('#comment-form').validate();
	$('#subscribe-form').validate();
	$('#brewcheck-form').validate();
});

function showLoader(loader) {
	if (typeof(loader) == 'undefined') {
		loader = 'div.loader';
	}
	$(loader).css({opacity: 1, visibility: 'visible'});
}
function hideLoader(loader) {
	if (typeof(loader) == 'undefined') {
		loader = 'div.loader';
	}
	$(loader).fadeTo(250, 0);
}
