var save = [];
var map;

var saveobj;
var save;
var marker;

function onLoad()
{
	if (GBrowserIsCompatible()) 
	{
		//geocoder = new GClientGeocoder();
		map = new GMap2(document.getElementById("map"));	
		map.addControl(new GLargeMapControl ());
        map.addControl(new GMapTypeControl());
       	map.setCenter(new GLatLng(48.3346858,7.6574707), 10);
		obj = new Object();
		obj.checked = 1;
		obj.id = 1;
		// addMapOverlay(obj,'map.kml');
		
		
		// marker icon
		var palaisIcon = new GIcon();
		palaisIcon.image = "http://www.lepalaisdupaindepices.com/images/icon-palais.png";
		palaisIcon.shadow = "http://www.lepalaisdupaindepices.com/images/icon-palais-shadow.png";
		palaisIcon.iconSize = new GSize(64, 58);
		palaisIcon.shadowSize = new GSize(64, 58);
		palaisIcon.iconAnchor = new GPoint(21, 54);
		palaisIcon.infoWindowAnchor = new GPoint(22, 54);

		var gareIcon = new GIcon();
		gareIcon.image = "http://www.lepalaisdupaindepices.com/images/icon-gare.png";
		gareIcon.iconSize = new GSize(32, 32);
		gareIcon.iconAnchor = new GPoint(15, 32);
		gareIcon.infoWindowAnchor = new GPoint(15, 31);


		// GARE
		markerOptions = { icon:gareIcon };
		var long = 48.404456;
		var lat = 7.457507;		
  		var point = new GLatLng(long, lat);
  		
  		markerGare = new GMarker(point, markerOptions);
  		map.addOverlay(markerGare);	
  		GEvent.addListener(markerGare, "click", function() {
   		 markerGare.openInfoWindowHtml("<b>Gare de Gertwiller</b>");
  		});  		
	
		// PALAIS
		markerOptions = { icon:palaisIcon };
		var long = 48.41281;
		var lat = 7.472656;		
  		var point = new GLatLng(long, lat);
  		
  		marker = new GMarker(point, markerOptions);
  		map.addOverlay(marker);		
  		
  		var descriptionPalais = '<b>Le Palais du Pain d\'&eacute;pices</b><br>144 route de Strasbourg<br>67140 Gertwiller<br><br>Tel. 03 88 08 04 26<br>Fax. 03 88 08 55 41<br><img style="width: 240px;" src="http://www.lepalaisdupaindepices.com/images/boutique-pour-plan.jpg"><br>';
   		marker.openInfoWindowHtml(descriptionPalais);

  		GEvent.addListener(marker, "click", function() {
   		 marker.openInfoWindowHtml(descriptionPalais);
  		});
  		
	}
}



function toggleMapOverlay(obj, fichier_kml){

		marker.closeInfoWindow();

		if (save != undefined)
		{
			map.removeOverlay(save);
		}
		if (saveobj != undefined)
		{
			saveobj.className = "maplink";
			$("#"+saveobj.id + "_details").css('display','none');
		}

		var geoXml = new GGeoXml("http://www.lepalaisdupaindepices.com/map/"+fichier_kml);
		
		
		GEvent.addListener(geoXml, "load", function() {
			geoXml.show();
			$("#"+obj.id).className = "maplink active";
			$("#"+obj.id + "_details").css('display','block');
			
			if (obj.id == "map1"){
				map.setCenter(new GLatLng(48.4946858,7.5874707), 11);
			}
			if (obj.id == "map2"){
				map.setCenter(new GLatLng(48.3346858,7.4074707), 11);
			}
			if (obj.id == "map3"){
				map.setCenter(new GLatLng(48.404456,7.472656), 13);

			}
									
		});

		
		
		map.addOverlay(geoXml);
		save = geoXml;		
		saveobj = obj;
}


