// JavaScript Document

	function initMap() {
		
		if (!document.ie6 || document.chargeCarte){
			if ($("#midmap").length==1 && GBrowserIsCompatible()) {
				map = new GMap2(document.getElementById("midmap"));
				map.setCenter(new GLatLng(49.123654,-0.35802), 9);
				map.setUIToDefault();
	//			map.addControl(new GSmallMapControl());
	//			map.addControl(new GMapTypeControl());
	//			map.disableScrollWheelZoom();
				map.setMapType(G_PHYSICAL_MAP);
				
				geoKml = new GGeoXml("http://www.parents-toujours.info/14-Calvados.kml");
				map.addOverlay(geoKml);
				
				// Create a base icon for all of our markers that specifies the
				// shadow, icon dimensions, etc.
				document.baseIcon = new GIcon(G_DEFAULT_ICON);
				document.baseIcon.iconSize = new GSize(27, 44);
				document.baseIcon.image = "images/marker.png";
				document.baseIcon.iconAnchor = new GPoint(14, 43);
				document.baseIcon.shadow = "images/marker-shadow.png";
				document.baseIcon.shadowSize = new GSize(46, 47);
				document.baseIcon.transparent = "images/marker-transparent.png";
				document.baseIcon.imageMap = [13,0, 27,14, 13,44, 0,14];
			
				document.baseIcon.infoWindowAnchor = new GPoint(14, 15);
	
				// Create a base icon for all of our markers that specifies the
				// shadow, icon dimensions, etc.
				document.baseIconOver = new GIcon(document.baseIcon);
				document.baseIconOver.image = "images/marker-over.png";

				// Create a base icon for all of our markers that specifies the
				// shadow, icon dimensions, etc.
				document.couponIcon = new GIcon(document.baseIcon);
				document.couponIcon.image = "images/marker-coupon.png";
				document.couponIcon.iconSize = new GSize(36, 53);
				document.couponIcon.iconAnchor = new GPoint(18, 52);
				document.couponIcon.transparent = "images/marker-coupon-transparent.png";
				document.couponIcon.imageMap = [18,0, 36,16, 18,53, 0,16]; 
	
				// Create a base icon for all of our markers that specifies the
				// shadow, icon dimensions, etc.
				document.couponIconOver = new GIcon(document.couponIcon);
				document.couponIconOver.image = "images/marker-coupon-over.png";

				// Creates a marker whose info window displays the letter corresponding
				// to the given index.
	
				document.markers=new Array();
				document.markersOver=new Array();
	
				document.structures=$("div.structuresListe li.titreStructure");
				var nb=document.structures.length;
				for (var i=0; i<nb; i++){
					var adresse=$(".adresse",document.structures[i]).html();
					findLocation(adresse,i);
				}
			}
		} else {
			$("#midmap").html("<a href='#'><img src='images/pb-carte-ie.jpg' /></a>");
			$("#midmap a").click(function(){
				$("#midmap").html('<img src="../images/ajax-mid.gif" alt="Carte géographique" />');
				document.chargeCarte=true;
				initMap();
			});
		}
	}
	
	function initLitMap() {
		if ($("#litmap").length==1 && GBrowserIsCompatible()) {
			var adresse=$("#litmap .adresse").html();
			map = new GMap2(document.getElementById("litmap"));
			map.setCenter(new GLatLng(49.123654,-0.35802), 8);
			map.setUIToDefault();
//			map.addControl(new GSmallMapControl());
//			map.addControl(new GMapTypeControl());
//			map.disableScrollWheelZoom();
			map.setMapType(G_NORMAL_MAP);
			
			geoKml = new GGeoXml("http://www.parents-toujours.info/14-Calvados.kml");
			map.addOverlay(geoKml);
			
			// Create a base icon for all of our markers that specifies the
			// shadow, icon dimensions, etc.
			document.baseIcon = new GIcon(G_DEFAULT_ICON);
			document.baseIcon.iconSize = new GSize(27, 44);
			document.baseIcon.image = "images/marker.png";
			document.baseIcon.iconAnchor = new GPoint(14, 43);
			document.baseIcon.shadow = "images/marker-shadow.png";
			document.baseIcon.shadowSize = new GSize(46, 47);
			document.baseIcon.transparent = "images/marker-transparent.png";
			document.baseIcon.imageMap = [13,0, 27,14, 13,44, 0,14];
		
			document.baseIcon.infoWindowAnchor = new GPoint(14, 15);

			// Create a base icon for all of our markers that specifies the
			// shadow, icon dimensions, etc.
			document.baseIconOver = new GIcon(document.baseIcon);
			document.baseIconOver.image = "images/marker-over.png";
			
			// Create a base icon for all of our markers that specifies the
			// shadow, icon dimensions, etc.
			document.couponIcon = new GIcon(document.baseIcon);
			document.couponIcon.image = "images/marker-coupon.png";
			document.couponIcon.iconSize = new GSize(36, 53);
			document.couponIcon.iconAnchor = new GPoint(18, 52);
			document.couponIcon.transparent = "images/marker-coupon-transparent.png";
			document.couponIcon.imageMap = [18,0, 36,16, 18,53, 0,16]; 

			// Create a base icon for all of our markers that specifies the
			// shadow, icon dimensions, etc.
			document.couponIconOver = new GIcon(document.couponIcon);
			document.couponIconOver.image = "images/marker-coupon-over.png";

			// Creates a marker whose info window displays the letter corresponding
			// to the given index.

			document.markers=new Array();
			document.markersOver=new Array();

			findLocation(adresse,0);
		}
	}
	
	function createStructureMarker(point, index, iconStyle) {
		// Create a lettered icon for this point using our icon class
/*		var letter = String.fromCharCode("A".charCodeAt(0) + index);
		var letteredIcon = new GIcon(baseIcon);
		letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
		// Set up our GMarkerOptions object
		markerOptions = { icon:letteredIcon };/**/
		
		
		
		markerOptions = { icon:iconStyle };
		
		var marker = new GMarker(point, markerOptions);
		
		marker.index=index;
		
		var exist=$("#str-"+(marker.index+1)).length;
		if (exist){
			GEvent.addListener(marker, "click", function() {
				var texte=$("#str-"+(marker.index+1)).html();
//				var etiquetteOptions=new GInfoWindowOptions();
/*				etiquetteOptions.maxWidth=300;/**/
				var etiquetteOptions={maxWidth: 250};
				marker.openInfoWindowHtml('<div class="etiquetteMap">'+texte+'</div>',etiquetteOptions);
			});/**/
		} else {
			GEvent.addListener(marker, "click", function() {
				map.zoomIn(marker.getLatLng(),true,true);
			});/**/
		}
		GEvent.addListener(marker, "mouseover", function() {
			survol(marker.index,true);
			$("#str-"+(marker.index+1)).addClass("over");
		});
		GEvent.addListener(marker, "mouseout", function() {
			survol(marker.index,false);
			$("#str-"+(marker.index+1)).removeClass("over");
		});
		return marker;
	}

	function findLocation(addressTxt,index) {
		$.get("address2latlng.php",
			{index: index, address: addressTxt + " FRANCE"},
			function(data){
				var reg=new RegExp(",", "g");
				var tab=data.split(reg);
				
				var point=new GLatLng(tab[2],tab[1]);
				var index=tab[0]*1;
				
/*				var expose=false;
				if (document.adressesTab[index][2]!=undefined){
					expose=(document.adressesTab[index][2]==true);
				}/**/
				
				var marker = createStructureMarker(point,index,document.baseIcon);
/*				if (expose){
					marker = createStructureMarker(point,index,document.baseIconOver);
				}/**/
				map.addOverlay(marker);
				document.markers[index]=marker;
				
				var markerOver = createStructureMarker(point,index,document.baseIconOver);
				map.addOverlay(markerOver);
				document.markersOver[index]=markerOver;
				
				markerOver.hide();
				
				$("#str-"+(index+1)).mouseover(function(){
					survol(index,true);
				});
				$("#str-"+(index+1)).mouseout(function(){
					survol(index,false);
				});
				
				//marker.show();/**/
				//marker.openInfoWindowHtml(address);
			}
		);
	}
	
	function survol(index,bool){
		if (bool){
			document.markers[index].hide();
			document.markersOver[index].show();
		} else {
			document.markers[index].show();
			document.markersOver[index].hide();
		}
	}
	


