
var googlemap_id = null;
var googlemap_map = null;
var googlemap_geocoder = new google.maps.Geocoder();
var googlemap_infoWindow = new google.maps.InfoWindow();
var googlemap_marker = null;

function googlemap_load(id) {
    googlemap_map = new google.maps.Map(
		document.getElementById(id),
        {
			zoom: 7,
			center: new google.maps.LatLng(48.9, 2.3),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
	);
}

function googlemap_afficherAdresse(address,annonce) {
	if (googlemap_geocoder) {
		if(annonce!=undefined)
		var html='<table style="width:200px">\n\
	<tr>\n\
		<td>\n\
			<img style="padding:1px;border:1px solid #666666;" src="'+annonce.image+'">\n\
		</td>\n\
		<td style="vertical-align:top;">\n\
			<b>'+annonce.ville+'</b> ('+annonce.cp+')<br>\n\
			'+annonce.prix+'<br>\n\
			'+annonce.ref+'<br>\n\
		</td>\n\
	</tr>\n\
</table>';
		googlemap_geocoder.geocode({
				'address':address,
				'language':'fr'
			},
			function(results, status) {
				if (status == google.maps.GeocoderStatus.OK) {
					if(annonce!=undefined){
						googlemap_marker = new google.maps.Marker({
							map: googlemap_map,
							position: results[0].geometry.location
						});
						googlemap_infoWindow.setOptions({
							position: results[0].geometry.location,
							content: html
						 });
						googlemap_infoWindow.open(googlemap_map, googlemap_marker);
						googlemap_map.setCenter(googlemap_infoWindow.getPosition());
					} else googlemap_map.setCenter(results[0].geometry.location);

				} else {
					Element.hide(googlemap_id);
				}
			}
		);
	} else alert('Geocoder non chargé !');
}
