var map = null;
var geocoder = null;

// Initialize function when loading map
function initialize() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
	} else {
		// Hide map layer
		document.getElementById("map").style.display = 'none';
	}
}

var default_address = 'Östersund, Sweden';

// Show selected address
function showAddress(address) {
	if (geocoder) {
		// Get position for address
		geocoder.getLatLng(
			address, 
			function(point) {
				if (point) {
					if (address == default_address)
						zoom = 4;
					else
						zoom = 15
					
					// Set center point on map
					map.setCenter(point, zoom);
					
					if (address != default_address) {
						// Create marker
						var marker = new GMarker(point);
						
						// Create overlay
						map.addOverlay(marker);
					}
				} else {
					// Hide map when address not exists
					//document.getElementById("map").style.display = 'none';
					showAddress(default_address);
				}
			}
		);
	}
}

document.observe('dom:loaded', function() {
	initialize();
	changeMap();
});
