var wHeight		= $(window).height();
var margin		= 8;
var padding		= 50;
var minHeight	= 600;
var menubar		= $("#menu-bar");
var resizeTimer	= null;
/* --------------------------------------------------------- */
/* SET MENU BAR HEIGHT
/* --------------------------------------------------------- */
function setMenubarHeight()
{
	wHeight = $(window).height();
	var height = wHeight - margin - padding;
	menubar.height(height + 'px');
}

function avoidScroll()
{
	var sc = $(document.body).scrollTop();
	sc = (!sc) ? document.documentElement.scrollTop : sc;
	menubar.css({top: sc + 4});
}

$(document).ready(function() {
	/* --------------------------------------------------------- */
	/* FADE OUT SUCCESS DIV
	/* --------------------------------------------------------- */
	$('div.success').fadeOut(4000);
	/* --------------------------------------------------------- */
	/* BIND MENU BAR HEIGHT FUNCTION
	/* --------------------------------------------------------- */
	setMenubarHeight();
	$(window).bind('scroll', function() { avoidScroll(); });
	$(window).bind('resize', function() { setMenubarHeight(); });
	/* --------------------------------------------------------- */
	/* MAKE COLUMN BLOCKS FULLY CLICKABLE AND ROLLOVER
	/* --------------------------------------------------------- */
	$('div.column a').each(function() {
		var href		= $(this).attr('href');
		var overColor	= "#EEE";
		var normColor	= "#FFF";
		var block		= $(this).parent();
		if(block.hasClass('right-item')) block = $(this).parent().parent();
		if(block.hasClass('over'))
		{
			block.css('cursor', 'pointer');
			block.hover(function() { block.css('background-color', overColor); }, function() { block.css('background-color', normColor); }).click(function() { window.location = href; })
		}
	});
	/* --------------------------------------------------------- */
	/* FORM LOGICA NEWSLETTER
	/* --------------------------------------------------------- */
	$('#feedback').hide();
	$('#email').focus(function() { if($(this).val() == "Je e-mailadres") { $(this).val(''); }});
	$('#email').blur(function() { if($(this).val() == "") { $(this).val('Je e-mailadres'); }});
	
	$('#submit-btn').click(function(e) {
		e.preventDefault();
		if($('#email').val() != "" && $('#email').val() != "Je e-mailadres")
		{
			var url = $("#newsletter-form").attr('action')
			console.log(url);
			$.ajax({
				url: url,
				type: "POST",
				dataType: "json",
				data: $("#newsletter-form").serialize(),
				complete: function(data) {
					$('#feedback').text(data.responseText);
					$('#feedback').fadeIn('fast');
					$('#feedback').css('cursor','pointer');
					$('#feedback').click(function() { $(this).fadeOut('fast'); })
				}
			});
		}
		else
		{
			$('#email').addClass('required');
		}
	});
});