	var centerLatitude = 53.626307;
	var centerLongitude = 12.405976;
	var startLocation = null;
	var startZoom = 7;
	var element = "map";
	var map = null;
	var manager = null;
	var mapdata = 'gmap/gmapdata.php';
	var lastzoom = 0;
	var mycookie = null;

	var icons = {};

	var iconData = {
		"kirche" : { width:19, height:25 },
		"kirche_shadow" : { width:30, height:19 }
	};
	
	function mapCookie() {
		if(navigator.cookieEnabled == true && (mycookie = Cookie.get('mapCookie'))) {
			session = Json.evaluate(unescape(mycookie));
			startZoom = session.zoom;
			startLocation = new google.maps.LatLng(session.lat, session.lng);
		}
	}
	function mapCookieSave() {
		if(navigator.cookieEnabled == true) {
			var location = map.getCenter();
			var mycookie = Json.toString({lat: location.lat(), lng: location.lng(), zoom: map.getZoom()});
			Cookie.set('mapCookie', escape(mycookie));
		}
	}
	function init() {
		if (google.maps.BrowserIsCompatible()) {
			map = new google.maps.Map2(document.getElementById("map"));
			startLocation = new google.maps.LatLng(centerLatitude, centerLongitude);
			
			mapCookie();
			map.setCenter(startLocation, startZoom);
			
			// Navigations HUD
			// - Controls ohne Slider
			//map.addControl(new GSmallMapControl());
			map.addControl(new google.maps.MapTypeControl());
			map.addControl(new google.maps.LargeMapControl());
			map.addControl(new google.maps.OverviewMapControl());
			
			map.enableDragging();
			map.enableInfoWindow();
			map.enableDoubleClickZoom();
			map.enableContinuousZoom();
			map.enableScrollWheelZoom();
			
			//manager = new google.maps.MarkerManager(map);
			//window.setTimeout('setupMarkers(manager, points);', 0);
			// clustered version
			google.maps.Event.addListener( map, 'moveend', function() {
				getMarkers( map, mapdata );
			});
		}
	}

	// cluster-Marker
	var iconCluster = new google.maps.Icon();
	iconCluster.image = "gmap/icons/icon_kirche_group.png";
	iconCluster.shadow = "gmap/icons/icon_kirche_shadow.png";
	iconCluster.iconSize = new GSize(25, 31);
	iconCluster.shadowSize = new GSize(30, 19);
	iconCluster.iconAnchor = new GPoint(13, 25);
	iconCluster.infoWindowAnchor = new GPoint(13, 1);
	iconCluster.infoShadowAnchor = new GPoint(26, 13);
	
	// einfache Marker
	var iconSingle = new google.maps.Icon();
	iconSingle.image = "gmap/icons/icon_kirche.png";
	iconSingle.shadow = "gmap/icons/icon_kirche_shadow.png";
	iconSingle.iconSize = new GSize(19, 25);
	iconSingle.shadowSize = new GSize(30, 19);
	iconSingle.iconAnchor = new GPoint(6, 20);
	iconSingle.infoWindowAnchor = new GPoint(6, 1);
	iconSingle.infoShadowAnchor = new GPoint(13, 13);
	
	function getMarkers( map, getUrl ) {
		//var mapMarkers = [];
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var zoom = map.getZoom();
		var getVars = 'ne=' + northEast.toUrlValue()
		+ '&sw=' + southWest.toUrlValue() + '&z=' + zoom;
		var url = getUrl+'?'+getVars;

		// mootools Ajax
		var log = $('log');
		var xhropts = {
			method: 'get',
			onSuccess: function(transport) {
				var points = Json.evaluate(transport);
				clusterUpdate(points, bounds, zoom);
			}
		};
		new Ajax(url, xhropts).request();
	}
	
	function createMarker(pos, name, info, type, link) {
		if(type == 'c') {
			var marker = new google.maps.Marker(pos, { icon: iconCluster, title: name });
			google.maps.Event.addListener(marker, 'click', function() {
				map.zoomIn();
			});
		} else {
			var marker = new google.maps.Marker(pos, { icon: iconSingle, title: name });
			marker = createInfoWindow(marker, { title: name, content: info, link: link });
		}
		return marker;
	}

	function createInfoWindow(marker, info) {
// 		var html = "<div class=\"GmapInfoTitle\">" + info.title + "</div><div class=\"GmapInfoContent\">" + info.content + "<br /><a href=\"" + info.link + "\">Diese Kirche im Kulturportal MV ...</a></div>";
		var html = "<div class=\"GmapInfoTitle\">" + info.title + "</div><div class=\"GmapInfoContent\">" + info.content + "<br /><a href=\"" + info.link + "\" onclick=\"mapCookieSave();\">Diese Kirche im Kulturportal MV ...</a></div>";
		google.maps.Event.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}

	function clusterUpdate( points, bounds ) {
		if(map.getZoom() != lastzoom) {
			map.clearOverlays();
		}

		points.each( function(poi) {
			var point = new GLatLng(poi['pos'][0], poi['pos'][1]);
			if(bounds.containsLatLng( point )) {
 				var newMarker = createMarker(point, poi['name'], poi['info'], poi['type'], poi['link']);
				map.addOverlay( newMarker );
			}
		});
	}

	/** startup */
	google.setOnLoadCallback(init);
	window.onunload = google.maps.Unload;
	
	window.onload = function() {
		// listMarker(point);
		window.setTimeout('getMarkers( map, mapdata );', 5000);
	};

