﻿	// Chargement du module "maps" dans sa version "2" /
	google.load("maps", "2");
	var maCarte;	 
	var iconResid;
	var iconUniv;
	var iconCulture;
	var iconAlim;
	var icon3il;
	var iconPrepa;
	var iconSup;
	var iconEnsci;
	var iconIut;
	var iconIufm;
	var iconCine;
	var TousMesMarqueurs = [];
	// Url pointant vers votre fichier .xml /
	var urlXml = "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/js/markerdataB.xml";
	
	// Fonction initialize() /
	function initialize() {
	// Si le navigateur est compatible avec l'API de Google Maps ... /
		if (google.maps.BrowserIsCompatible()) {
		var ToutesLesBalisesInput = document.getElementsByTagName("input");
		
		baseIcon = new google.maps.Icon();
		baseIcon.iconSize=new google.maps.Size(20,20);
		baseIcon.shadowSize=new google.maps.Size(20,22);
		baseIcon.iconAnchor=new google.maps.Point(6,20);
		baseIcon.infoWindowAnchor=new google.maps.Point(5,1);
		iconResid = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/residence.png");
		iconUniv = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/unilim.png");
		icon3il = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/3il.png");
		iconPrepa = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/prepa.png");
		iconSup = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/supinfo.png");
		iconEnsci = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/ensci.png");
		iconIut = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/iut.png");
		iconIufm = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/unilim.png");
		iconCulture = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/culture.png");
		iconAlim = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/commerces.png");
		iconGare = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/gare.png");
		iconCine = new google.maps.Icon(baseIcon, "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/cinema.png");
		/*Création d'une nouvelle carte nommée "maCarte" qui s'affichera à l'intérieur de la div ayant pour identifiant id="map_canvas" */
		maCarte = new google.maps.Map2(document.getElementById("map_canvas"));
		maCarte.addControl(new GLargeMapControl3D());
		//maCarte.enableScrollWheelZoom();
		// ... La carte nommé"maCarte" est centrée sur la Latitude 45.830795, la Longitude 1.260842, avec un niveau de zoom égal à 13 ... /
		//maCarte.setCenter(new google.maps.LatLng(45.830795,1.260842), 13);
		maCarte.setCenter(new google.maps.LatLng(45.835005,1.255842), 14);
		google.maps.DownloadUrl(urlXml, function(data) {
			var xml = google.maps.Xml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var type = markers[i].getAttribute("type");
				if(type == "immeuble"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}
/*				if(type == "univscien"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}
				if(type == "univdroit"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}				
				if(type == "univmed"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}
				if(type == "3il"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}
				if(type == "prepa"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}
				if(type == "supinfo"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}
				if(type == "ensci"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				}
				if(type == "iut"){
					var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var address = markers[i].getAttribute("address");
					var img = markers[i].getAttribute("img");
					var description = markers[i].getAttribute("description");
					var lien = markers[i].getAttribute("lien");
					var type = markers[i].getAttribute("type");
					var marker = CreationDuMarqueur(point, name, img, address, description, type, lien, i);
					// ... on ajout le marqueur à la carte nommée "maCarte". /
					maCarte.addOverlay(marker);
				} */
			}
		});
		
		if(ToutesLesBalisesInput != null){
				for(var i = 0; i < ToutesLesBalisesInput.length; i++){
					if(ToutesLesBalisesInput[i].type == "checkbox"){						
						ToutesLesBalisesInput[i].onclick=function(){EnvoiLoisir(this);}
						//alert(ToutesLesBalisesInput[i].onclick);
						
					}
				}
			}
		// Si le navigateur n'est pas compatible avec l'API de Google Maps ... /
		}else{
		// ... affichage du message "Désolé, mais votre navigateur n'est pas compatible avec Google Maps". /
		alert('Désolé, mais votre navigateur n\'est pas compatible avec Google Maps');
		}
	}
	function CreationDuMarqueur(point, name, img, address, type, description, lien, i) {
		if(type=="immeuble"){icon = iconResid;}
		if(type=="univscien"){icon = iconUniv;}
		if(type=="univdroit"){icon = iconUniv;}
		if(type=="univmed"){icon = iconUniv;}
		if(type=="3il"){icon = icon3il;}
		if(type=="prepa"){icon = iconPrepa;}	
		if(type=="supinfo"){icon = iconSup;}
		if(type=="ensci"){icon = iconEnsci;}
		if(type=="iut"){icon = iconIut;}
		if(type=="iufm"){icon = iconIufm;}
		if(type=="univlet"){icon = iconUniv;}
		if(type=="culture"){icon = iconCulture;}
		if(type=="alimentation"){icon = iconAlim;}
		if(type=="gare"){icon = iconGare;}
		if(type=="cinema"){icon = iconCine;}
		var marker = new google.maps.Marker(point,icon);
		TousMesMarqueurs[i] = marker;
		google.maps.Event.addListener(marker, "click", function(){
			var html = "<b>" + name + "</b> <br/>" + address + "<br/><a href=" + lien + ">" + description + "</a><br /> <img src= " + img + " visible='true'  width='120' height='90'/>";
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}

	function EnvoiLoisir(val){
		if(val == null){return;}
		var loisirselec = val.value;
		// ... Si la case est cochée ... 
		if(val.checked == true){
			google.maps.DownloadUrl(urlXml, function(data) {
				var xml = google.maps.Xml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var type = markers[i].getAttribute("type");
					// ... Si les marqueurs correspondant à la catégorie sélectionnée ... /
					if(type == loisirselec){
						var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
						var name = markers[i].getAttribute("name");
						var address = markers[i].getAttribute("address");
						var img = markers[i].getAttribute("img");
						var description = markers[i].getAttribute("description");
						var lien = markers[i].getAttribute("lien");
						var type = markers[i].getAttribute("type");
						var marker = CreationDuMarqueur(point, name, img, address, type, description, lien, i);
						// ... on ajout le marqueur à la carte nommée "maCarte". /
						maCarte.addOverlay(marker);
					}
				}
			});
		}
		// ... Si la case est décochée ... /
		if(val.checked == false){
			google.maps.DownloadUrl(urlXml, function(data) {
				var xml = google.maps.Xml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var type = markers[i].getAttribute("type");
					// ... Si les marqueurs correspondant a la catégorie sélectionnée ... /
					if(type == loisirselec){
						// ... alors ils sont supprimés de la carte nommée "maCarte". /
						maCarte.removeOverlay(TousMesMarqueurs[i]);
					}
				}
			});
		}
	}
	// Appelle la fonction "initialize" lorsque la page web sera chargée /
	google.setOnLoadCallback(initialize);
