function initMap() {
	if (GBrowserIsCompatible()) {
					
		var ne_lat = $("map_ne_lat").innerHTML;
		var ne_lng = $("map_ne_lng").innerHTML;
		var sw_lat = $("map_sw_lat").innerHTML;
		var sw_lng = $("map_sw_lng").innerHTML;
		
		map = new GMap2($("map"));

		clusterer = new Clusterer(map);
		clusterer.SetMinMarkersPerCluster(2);
		clusterer.SetMaxVisibleMarkers(20);
		icon = new GIcon();
		icon.image = 'img/youx_group.png';
		icon.shadow = '';
		icon.iconSize = new GSize(40, 40);
		icon.shadowSize = new GSize( 0, 0 );
		icon.iconAnchor = new GPoint(20, 20);
		icon.infoWindowAnchor = new GPoint( 20, 20 );
		
		icon2 = new GIcon(icon);
		icon2.image = 'img/youx_art_group.png';
		
		clusterer.SetIcon(icon,icon2);
		clusterer.SetHoverImage('img/youx_group_o.png');

		map.enableScrollWheelZoom();
		map.enableContinuousZoom();
		var overviewMapControl = new GOverviewMapControl(new GSize(150,150));
		map.addControl(overviewMapControl);
		map.addControl(new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5,5)));

		var mapTypeControl = new GHierarchicalMapTypeControl();
		map.addControl(mapTypeControl);
		map.reloadPlaces=true;
		GEvent.addListener(map, "load", mapLoadPlaces);
		
		map.setCenter(new GLatLng(0, 0), 17);
		
		var ne = new GLatLng(ne_lat, ne_lng);
		var sw = new GLatLng(sw_lat, sw_lng);
		
		var bounds = new GLatLngBounds(sw, ne);
		
		var center = bounds.getCenter();
		
		var zoom = map.getBoundsZoomLevel(bounds);
		
		map.setCenter(center, zoom);
		map.getInfoWindow();
		//map.closeInfoWindow();

	}
	else
	{
		container.innerHTML = "Dein Browser unterst&uuml;zt Google Maps nicht!";
	    return null;
	}
}

function mapSetBounds()
{
	if(map.reloadPlaces)
	{
		var bounds = this.getBounds();
		
		var ne = bounds.getNorthEast();
		var sw = bounds.getSouthWest();
		
		var ne_lat = ne.lat();
		var ne_lng = ne.lng();
		var sw_lat = sw.lat();
		var sw_lng = sw.lng();
		
		var post = "ne_lat=" +  ne_lat + "&ne_lng=" +  ne_lng + "&sw_lat=" +  sw_lat + "&sw_lng=" +  sw_lng;
		
		var callback =
		{
			success: function(o)
			{			
				if(o.responseText == true)
				{
					//target div
					getRecentOpinions(1,null,true);
					
					//nicht mehr wichtig
					mapRefreshPlaces();
				}
				else
				{
					alert("Fehler in mapSetBounds()");
				}
			},
			failure: function(o)
			{
				alert("Fehler in mapSetBounds()");
			}
		}
		
		YAHOO.util.Connect.asyncRequest('POST', "mod/map/xhrSetBounds.php", callback, post); 	
			
	}
}

function mapLoadPlaces()
{
	var id, lat, lng, latlng, marker, address;
	var places = YAHOO.util.Dom.getChildren("places_list");
	
	if(clusterer) clusterer.ClearAll();
		
	for(var i=0;i<places.length;i++)
	{
		artspotting = YAHOO.util.Dom.getElementsByClassName("artspotting","div",places[i])[0].innerHTML;
		id = YAHOO.util.Dom.getElementsByClassName("places_id","div",places[i])[0].innerHTML;
		lat = YAHOO.util.Dom.getElementsByClassName("places_latitude","div",places[i])[0].innerHTML;
		lng = YAHOO.util.Dom.getElementsByClassName("places_longitude","div",places[i])[0].innerHTML;
		address = YAHOO.util.Dom.getElementsByClassName("places_address","div",places[i])[0].innerHTML;
		createGmarker(artspotting, id, lat, lng, address);					
	}
		
	GEvent.addListener(this, "moveend", mapSetBounds);
	GEvent.addListener(this, "resize", mapSetBounds);
}

function mapRefreshPlaces()
{
	if(map)
	{
		var callback =
		{
			success: function(o)
			{			
				if(o.responseText)
				{
					$("places").innerHTML = o.responseText;
					mapLoadPlaces();
				}
				else
				{
					alert("Fehler in mapRefreshPlaces()");
				}
			},
			failure: function(o)
			{
				alert("Fehler in mapRefreshPlaces()");
			}
		}
		
		YAHOO.util.Connect.asyncRequest('POST', "mod/map/xhrWrapper.php", callback);
	}	
}

function createGmarker(artspotting, id,lat,lng,address)
{
	var latlng = new GLatLng(lat, lng);
	
	var icon = new GIcon();
	if(artspotting > 0)
	{
		icon.image = 'img/youx_art.png';
	}
	else
	{
		icon.image = 'img/youx.png';	
	}
	icon.shadow = '';
	icon.iconSize = new GSize(28, 28);
	icon.shadowSize = new GSize( 0, 0 );
	icon.iconAnchor = new GPoint(13, 13);
	icon.infoWindowAnchor = new GPoint( 13, 3 );
	icon.infoShadowAnchor = new GPoint( 27, 37 );
		
	marker = new GMarker(latlng,{icon: icon});
	
	marker.placeId = id;
	marker.artspotting = artspotting;
	marker.hoverImage = 'img/youx_o.png';
	if(artspotting > 0)
	{
		marker.image = 'img/youx_art.png';
	}
	else
	{
		marker.image = 'img/youx.png';
	}
	
	GEvent.addListener(marker, "click", function(){
		openDashboard(this.placeId);
	});
	GEvent.addListener(marker, "mouseover", function(){
		this.setImage(this.hoverImage);
	});
	GEvent.addListener(marker, "mouseout", function(){
		this.setImage(this.image);
	});
	
	clusterer.AddMarker(marker, address, id);
}