// JavaScript Document

$(document).ready(function(){

	var windowHeight = window.innerHeight;

	var contentHeight = $("#container").height();
	
	contentHeight = contentHeight + 55;

	if(contentHeight < windowHeight){
		
		$("#background").addClass("backgr_pos");
		$("#mainframe").css({'margin-top':'0'});
	
		$('#mainframe').css('height', function() {
  			var naam = window.innerHeight + 'px';
			return naam;
		});		
	}else{
		$("#background").removeClass("backgr_pos");
		$("#mainframe").css({'margin-top':'55px'});
		
	}
	
	$('#hoofdmenu li a.hoofdlink').each(function(){
    	$(this).parent().width($(this).width() + 4);
	});
	
	var sitemap_open = false;
	
	$("a.sitemap_btn").click(function(e){
		e.preventDefault();
		if(sitemap_open == false){
			$("#sitemap").animate({"height": "174px"}, "slow");
			$("a.sitemap_btn").addClass("open");
			sitemap_open = true;
		}else{
			$("#sitemap").animate({"height": "26px"}, "slow");
			$("a.sitemap_btn").removeClass("open");
			sitemap_open = false;
		}
	});
	
	var items = $(".column_right li");
    items.click( function(e) {
        if(e.target.tagName != 'A') {
			window.location.href = $('.leesMeer',this).attr('href');
        }
    })
	
	if ($("#contactformulier").length > 0) {
		$("#contactformulier").validate({
			debug: false,
			rules: {
				naam: "required",
				bedrijfsnaam: "required",
				telefoon: "required",
				emailadres: {
					required: true,
					email: true
				}
			},
			messages: {
				naam: "(verplicht)",
				bedrijfsnaam: "(verplicht)",
				telefoon: "(verplicht)",
				emailadres: "(verplicht)"
			},
			submitHandler: function(form) {
				// do other stuff for a valid form
				$.post('contactform_send.php', $("#contactformulier").serialize(), function(data) {
					$('#sendMessage').html(data);
					$("#contactform_div").addClass("verzonden");
					$("#introTekst").addClass("verzonden");
					$('#sendMessage').addClass("verzonden");
				});
			}
		});
	}	

});

$(window).resize(function() {

	var windowHeight = window.innerHeight;

	var contentHeight = $("#container").height();
	
	contentHeight = contentHeight + 55;

	if(contentHeight < windowHeight){
		
		$("#background").addClass("backgr_pos");
		$("#mainframe").css({'margin-top':'0'});
	
		$('#mainframe').css('height', function() {
  			var naam = window.innerHeight + 'px';
			return naam;
		});		
	}else{
		$("#background").removeClass("backgr_pos");
		$("#mainframe").css({'margin-top':'55px'});
		
	}
	
});






