
$(document).ready(function(){
	// navigation handler
	//$('#navigatie').sDrop({animate:true, duration:150});
	// loader-animatie invoegen
	$('body').append('<div id="loader"><img src="img/ajax-loader.gif" />&nbsp;&nbsp;&nbsp;Bezig met laden, even geduld aub</div>');
	$('#loader').css('top', (($(window).height() - $('#loader').height()) / 2));
	$('#loader').css('left', (($(window).width() - $('#loader').width()) / 2));
	$('body').append('<style type="text/css" media="screen">#body{ height: '+($(window).height()-275)+'px; }</style>');
	//.css('max-height', ($(window).height()-370+'px'))

	//contact();
});

$(window).resize(function() {
	center("#loader");
	$("#loader").show();
	$('<style type="text/css" media="screen">').remove();//('#body{ height: '+($(window).height()-275)+'px; }</style>');
	$('body').append('<style type="text/css" media="screen">#body{ height: '+($(window).height()-275)+'px; }</style>');
	setTimeout('$("#loader").hide()', 500);
});

function center(e){
	$(e).css('top', (($(document).height() - $(e).height()) / 2));
	$(e).css('left', (($(document).width() - $(e).width()) / 2));
}

function contact(actie){
	if (actie == undefined) actie = 'form';
	closebutton = '<div style="position: absolute; top: 8px; right: 8px;"><a href="javascript: contact(\'close\');"><img src="img/close-icon.png"/></a></div>';

	if (actie == 'form'){
		$('#loader').show();

		$('#contactform').remove();
		$('body').append('<div id="blockUI"></div>');

		$.ajax({
			url: 'ajax/contact.php',
			cache: false,
			type: 'POST',
			success: function(response){
				$('body').append('<div id="contactform"></div>');
				$("#contactform").html(closebutton+response);
				center('#contactform');
				$("#loader").hide();
				pageTracker._trackPageview('/contact/form');
			}
		});
	}
	else if (actie == 'close'){
		$("#blockUI").remove();
		$("#contactform").remove();
		$("#loader").hide();
	}
	else if (actie == 'send'){
		naam = $('#frmNaam').val();
		email = $('#frmEmail').val();
		bericht = $('#frmBericht').val();

		if ((naam != '') || (email != '') || (bericht != '')){
			$("#loader").show();
			$("#contactform").html();
			$.ajax({
				url: 'ajax/contact.php',
				cache: false,
				type: 'POST',
				data: ({
					'do' : 'send',
					'naam' : naam,
					'email' : email,
					'bericht' : bericht
				}),
				success: function(response){
					//$("#contactform").html(closebutton+response);
					$("#loader").hide();
					if (response == 1){
						$("#contactform").html(closebutton+'<div class="header">Contact opnemen</div><div class="content"><img src="img/accept.png" /> Uw bericht werd goed verzonden</div>');
						$("#loader").hide();
						pageTracker._trackPageview('/contact/thanks'); 	// Google Analytics
						setTimeout("contact('close')", 3000);
					}
					else{
						alert(response);
						pageTracker._trackPageview('/contact/form/error'); 	// Google Analytics
					}
				}
			});
		}
	}
}
