$(document).ready(function()
{
	function getWindowHeight() {
		var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number') {
			windowHeight = window.innerHeight;
		}
		else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			}
			else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	}

	function setFooter() {
		if (document.getElementById) {
			var windowHeight = getWindowHeight();
			if (windowHeight > 0) {
				var globalHeight = document.getElementById('global').offsetHeight;
				var footerElement = document.getElementById('footer');
				var footerHeight  = footerElement.offsetHeight;
				if (windowHeight - (globalHeight + footerHeight) >= 0) {
					footerElement.style.position = 'absolute';
					footerElement.style.top = (windowHeight - footerHeight) + 'px';
				}
				else {
					footerElement.style.position = 'static';
				}
			}
		}
	}

	function verticalCenterContent() {
		if (document.getElementById)
		{
			var windowHeight = getWindowHeight();
			if (windowHeight > 0)
			{
				var globalHeight = document.getElementById('index_global').offsetHeight;
				$('#index_global').css("margin-top", ((windowHeight/2) - globalHeight)+'px');
			}
		}
	}
	
	if($("#footer").length)
		setFooter();
	
	window.onresize = function() {
		setFooter();
	}
	
	if($("#index_global").length)
	{
		verticalCenterContent();
	
		window.onresize = function() {
			verticalCenterContent();
		}
	}
	
	function loadGoogleMap(positionX, positionY, markerName, markerImage, div)
	{
		var position = new google.maps.LatLng(positionX, positionY);
		var map;
		
		var myOptions = {
			zoom: 17,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			disableDefaultUI: true,
			zoomControl: true,
		};
		
		var marker = new google.maps.Marker({
			position: position,
			title: markerName,
			icon: markerImage
		});
		
		map = new google.maps.Map(document.getElementById(div), myOptions);
		
		// Position the map
		map.setCenter(position);
		
		// Add the marker to the map
		marker.setMap(map);
	}
	
	if($("#contact_map_1").length)
	{
		loadGoogleMap(46.203957, 6.136058, "Genève", "http://www.pblex.ch/i/address_a.png", "contact_map_1");
		loadGoogleMap(47.363816, 8.54673, "Zürich", "http://www.pblex.ch/i/address_b.png", "contact_map_2");
	}
});
