//////////////////////////////////////////////////////////////////////////////////////////////////
function getElementsByAttr(e,attr,value)
{
	var tab = [];
	if (e.getAttribute && e.getAttribute(attr)==value)
	  tab.push(e);
	  
	var n = e.firstChild;
	if (n==null) return tab;
	do
	{
  	   tab = tab.concat(getElementsByAttr(n,attr,value));
	}while((n = n.nextSibling)!=null)
	return tab;
}	

function init_googlemaps()
{
	if (GBrowserIsCompatible())
	{
		switch(navigateur())
		{
			case "Internet Explorer":document.maps=getElementsByAttr(document,"className","googlemap");break
			case "Firefox":case "Safari":document.maps=getElementsByAttr(document,"class","googlemap");break
		}

		for(cpt in document.maps)
		{
			obj_map=document.maps[cpt]
			obj_map.map = new GMap2(obj_map);
			if(obj_map.getAttribute("type_map")){obj_map.map.addControl(new GMapTypeControl())}// ajouts carte -satellite-mixte
			if(obj_map.getAttribute("navig")=='on'){obj_map.map.addControl(new GLargeMapControl())}// fleche navig+ barre zoom

			//obj_map.map.addControl(new GLargeMapControl()); // fleche navig+ barre zoom
			obj_map.map.enableDoubleClickZoom();
			
			obj_map.geocoder = new GClientGeocoder();

			if(obj_map.getAttribute("type_map")=="G_SATELLITE_MAP"){obj_map.map.setMapType(G_SATELLITE_MAP)}
			if(obj_map.getAttribute("type_map")=="G_NORMAL_MAP"){obj_map.map.setMapType(G_NORMAL_MAP)}
			if(obj_map.getAttribute("type_map")=="G_HYBRID_MAP"){obj_map.map.setMapType(G_HYBRID_MAP)}
		}
		
		show_googlemaps()
	}
}

function show_googlemaps()
{
	if(obj=document.maps.shift())
	{
		showAddress(obj)
		setTimeout("show_googlemaps()",500)
	}
}

function showAddress(obj_map)
{
	if (obj_map.geocoder)
	{
		adresse=obj_map.getAttribute("adresse").split("<>")
		address=adresse[0]+" "+adresse[1]+" "+adresse[2]

		map=obj_map.map
		geocoder=obj_map.geocoder
		geocoder.getLatLng(address,
			function (point)
			{
				if (!point) 
				{
					obj_map.adresse=adresse[1]+" "+adresse[2]
					 showAddress(obj_map)
				}
				else
				{
					init_zoom=11
					if(obj_map.getAttribute("init_zoom")){init_zoom=parseInt(obj_map.getAttribute("init_zoom"))}
					map.setCenter(point, init_zoom);
					var marker = new GMarker(point);
					map.addOverlay(marker);
					marker.openInfoWindowHtml(address);
				}
			})
	}
}
