var zoomForSingleMarker = 16;

var map;
var marker;

function initMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		map.enableDoubleClickZoom();
		map.enableScrollWheelZoom();
		map.enableContinuousZoom();
		map.addControl(new GSmallZoomControl());
	}
}

//function showCountryArea() {
//	showArea(54.836, 24.147, 49.002, 14.125);
//}

function showArea(maxNorth, maxEast, minSouth, minWest) {
	var centerLatLng = new GLatLng((maxNorth + minSouth) / 2, (maxEast + minWest) / 2);
	var bounds = new GLatLngBounds(new GLatLng(minSouth, minWest), new GLatLng(maxNorth, maxEast));
	var zoom = map.getBoundsZoomLevel(bounds);
	map.setCenter(centerLatLng, zoom);
}

function showSimpleMarker(gLatLng, infoWindowContent) {
	map.setCenter(gLatLng, zoomForSingleMarker);
	if (!marker) {
		var iconObject = new GIcon(G_DEFAULT_ICON);
		// iconObject.iconSize = new GSize(28, 28);
		// iconObject.shadowSize = new GSize(39, 39);
		// iconObject.shadow = "img/website/???.png";
		// iconObject.image  = "img/website/???.png";
		marker = new GMarker(gLatLng, {icon: iconObject});
		map.addOverlay(marker);
	}
	else {
		marker.setLatLng(gLatLng);
	}
	if (infoWindowContent) {
		marker.openInfoWindowHtml(infoWindowContent);
	}
}

function geocode(
	geocoder,
	addressParts,
	errorMessage
) {
	var address = addressParts.join(", ");
	if (address != '') {
		geocoder.getLatLng(
			address,
			function(point) {
				if (point) {
					showSimpleMarker(point);
				}
				else {
					addressParts.pop();
					if (addressParts.length > 0) {
						geocode(
							geocoder,
							addressParts,
							errorMessage
						);
					}
					else {
						alert(errorMessage);
					}
				}
			}
		);
	}
}