function getPageSize() {
		
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {    
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {    // all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}    
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){    
		pageWidth = xScroll;        
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function activateMap() {
	var map = new google.maps.Map2(document.getElementById("mp_map"));
	var point = new GLatLng(52.45,5.5);
	map.setCenter(point, 7);

	gdir = new GDirections(map, document.getElementById("directions"));

	map.addControl(new google.maps.LargeMapControl());
	map.addControl(new google.maps.ScaleControl());
	map.addControl(new google.maps.MapTypeControl());
}

function setDirections() {
	toAddress = 'Camstrastrjitte 10 Menaldum';
	var fromAddress = jQuery('#map_search_address').val();
	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": 'nl_NL' });
//	window.location = '#maps';
}


jQuery(function() {
	jQuery('#plan').click(function() {
		var size = getPageSize();
		jQuery('#overlay').css('width', size[0] + 'px');
		jQuery('#overlay').css('height', size[1] + 'px');
		
		jQuery('#mp').css('display', 'block');
		jQuery('#overlay').css('display', 'block');
		activateMap();
	});
		
	jQuery("#mp .close").click(function() {
		jQuery('#mp').css('display', 'none');
		jQuery('#overlay').css('display', 'none');
		jQuery('#directions').html('');
	});
		
	jQuery('#map_search_submit').click(function() {
		jQuery('#directions').html('');
		activateMap();
		setDirections();
	});
	
	jQuery('#belmij').click(function() {
		var size = getPageSize();
		jQuery('#overlay').css('width', size[0] + 'px');
		jQuery('#overlay').css('height', size[1] + 'px');
		jQuery('#overlay').css('display', 'block');
		jQuery('#belmijterug').css('display', 'block');
	});
	
	jQuery("#belmijterug .close").click(function() {
		jQuery('#overlay').css('display', 'none');
		jQuery('#belmijterug').css('display', 'none');
	});
	
	jQuery('#belmijterug_verzenden').click(function() {
		jQuery('#naam_error').css('display', 'none');
		jQuery('#telefoon_nummer').css('display', 'none');
	
		var naam = jQuery('#naam').val();
		var telefoon = jQuery('#telefoon').val();
		var errors = 0;
		
		if(naam.length == 0) {
			jQuery('#naam_error').css('display', 'block');
			errors++;
		}
		if(telefoon.length < 10) {
			jQuery('#telefoon_nummer').css('display', 'block');
			errors++;
		}
		
		if(errors == 0) {
			jQuery('#contact_opnemen').submit();
		}
	});
	
});