var map;
var geocoder;

var icon1 = new GIcon();
icon1.image = 'images/marker.png';
icon1.iconSize = new GSize(21, 20);
icon1.iconAnchor= new GPoint(24, 23);
icon1.infoWindowAnchor = new GPoint(14, 0);

var icon2 = new GIcon();
icon2.image = 'images/marker2.png';
icon2.iconSize = new GSize(21, 20);
icon2.iconAnchor= new GPoint(24, 23);
icon2.infoWindowAnchor = new GPoint(14, 0);

function loadMap(mapname)
{
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(mapname));
		map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(52.509797, 13.360918), 11);
		geocoder = new GClientGeocoder();
	}
}

function addMarkerOnLocation(address, info, show, markertype)
{
	geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				//alert(address + " not found");
			} else {
				switch (markertype) {
					case 2:
						var marker = new GMarker(point, icon2);
						break;
					case 1:
					default:
						var marker = new GMarker(point, icon1);
						break;
				}
				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(info);
				});
				map.addOverlay(marker);
				if (show) {
					marker.openInfoWindowHtml(info);
					map.setCenter(point, 14);
				}
			}
		}
	);
}

function addMarkerOnCoords(latitude, longitude, info, show, markertype)
{
	var point = new GLatLng(latitude, longitude);
	
	if (point) {
		var marker = new GMarker(point, icon1);
		map.addOverlay(marker);
		switch (markertype) {
			case 2:
				var marker = new GMarker(point, icon2);
				break;
			case 1:
			default:
				var marker = new GMarker(point, icon1);
				break;
		}
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(info);
		});
		map.addOverlay(marker);
		if (show) {
			map.setCenter(new GLatLng(latitude, longitude), 14);
			marker.openInfoWindowHtml(info);
		}
	}
}