
var geocoder = new GClientGeocoder();
var map = null ;

function createMarker(point, name, texte, header, rubrique) {
	var baseIcon = new GIcon();
	switch ( rubrique ) {
		default : 
			imageURL = "/images/maps/default.png";
			shadowURL = "/images/maps/default_shadow.png";
	}
	baseIcon.shadow = shadowURL;
	baseIcon.iconSize = new GSize(32, 27);
	baseIcon.shadowSize = new GSize(32, 27);
	baseIcon.iconAnchor = new GPoint(24, 16);
	baseIcon.infoWindowAnchor = new GPoint(40, 2);
	baseIcon.infoShadowAnchor = new GPoint(40, 10);
	var icon = new GIcon(baseIcon);
	icon.image = imageURL;
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("<strong>" + name + "</strong><br />" + texte + "<span style='font-size:80%'>" + header + "</span>",  {maxWidth: 200});
	});
	return marker;
}

function submitGeoForm ( form ) {
	geocoder.getLatLng(
		form.adresse.value + ", france",
		function(point) {
			if (point) {
				if ( map ) map.setCenter(point, 12);
				HTML_AJAX.replace('geo-results', '/spip.php?page=ajaxGeoResult&x='+point.x+'&y='+point.y+'&searched='+escape(form.adresse.value));
			} else {
				HTML_AJAX.replace('geo-results', '/spip.php?page=ajaxGeoResult&badResult=true&searched='+escape(form.adresse.value));
			}
		}
	);
}


function showAddress(address) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (point) {
					map.setCenter(point, 12);
				}
			}
		);
	}
}