/*
Requires: API Key/ Include http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAVdJY4_AwQ_j4Uq2tJSkTtxRhe6D4DmLJxq4kZ0h3erpfc3yC4BQXH8lVcyZwhVn8dKyPplZZyQJ8cg
Screenlight API Key (only valuable for http://www.screenlight.ch): ABQIAAAAVdJY4_AwQ_j4Uq2tJSkTtxRhe6D4DmLJxq4kZ0h3erpfc3yC4BQXH8lVcyZwhVn8dKyPplZZyQJ8cg
Map Address{
	address: (String, like "Bahnhofstrasse 1 8000 Zürich"),
	centerLat: (float, X/Lattitute of the mapcenter), // if not set, marker lat will be used
	centerLng, (float, Y/Longitude of the mapcenter), // if not set, marker lng will be used
	lat: (float, X/Lattitute of the AdressMarker)
	lng: (float, Y/Longitude of the AdressMarker)
}
*/

function SLMap( mapAddress, mapContainerID, contentID, useControls ){
	
	if (!GBrowserIsCompatible() || SLMap.init == true ) return;
	
	var map = new GMap2( document.getElementById(mapContainerID) );
	var addressElem = document.getElementById( contentID );
	
	SLMap.init = true;
	
	var setMap = function( p ){
		if( !p ) return;
		var mapCenter = ( mapAddress.centerLat > 0 && mapAddress.centerLng > 0 ) ? new GLatLng( mapAddress.centerLat, mapAddress.centerLng ) : p;
		map.setCenter( mapCenter, 12 ); // fails, if any parent container's display property is "None"
		map.addMapType( G_PHYSICAL_MAP );
		var marker = new GMarker( p );
		map.addOverlay( marker );
		map.addControl( new GMapTypeControl());
		map.addControl(new GLargeMapControl());
		marker.openInfoWindow( addressElem );
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindow( addressElem );
		});
		map.checkResize();
		addressElem.style.display = "block";
		
		if( useControls == true ) map.addControl(new GLargeMapControl());
	}
		
	if( mapAddress.address ){
		var gc = new GClientGeocoder();
		gc.getLatLng( mapAddress, setMap );
	}
	else{
		setMap( new GLatLng( mapAddress.lat, mapAddress.lng ));
	}
	return map;
}