//<![CDATA[

   var geocoder;
   var map;
	var indx=0;

   	var pointColor = 5;
   /*var articleLink;
    var articleTitle;*/
	
	tabLocation = new Array();

   var arLimites = {'z8': [49.5,47.9,6.8,8.4],'z9': [49.5,47.5,6.8,8.4]};

   
   	function TileToQuadKey (x, y, zoom){
				var quad = "";
			    for (var i = zoom; i > 0; i--){
					var mask = 1 << (i - 1);
			        var cell = 0;
			        if ((x & mask) != 0){
			            cell++;
					}
			        if ((y & mask) != 0){
			            cell += 2;
					}
			        quad += cell;
			    }
				return quad;
			}


   // On page load, call this function

   function load()
   {
   
      // Create new map object
      map = new GMap2(document.getElementById("map_canvas"),{backgroundColor:"#FFFFFF"});
	  
	  
	  topoTiles = function (a,b) {
			var f = "/carte/tiles/" + TileToQuadKey(a.x,a.y,b) + ".png";
						return f;
					}

		topoLayer = new GTileLayer(new GCopyrightCollection(''),8,9); 
		topoLayer.getTileUrl = topoTiles;
		topoLayer.isPng = function() {return true;};
					
		topoMap = new GMapType([topoLayer], G_HYBRID_MAP.getProjection(), "Zones"); 					
		map.addMapType(topoMap);
		map.setMapType(topoMap);
		map.backgroundColor="#ffffff"
		
		customUI = map.getDefaultUI();
		customUI.zoom.doubleclick =false;
		customUI.zoom.scrollwheel =false;
		customUI.zoom.scrollwheel =false;
		customUI.controls.menumaptypecontrol =false;
		
       
        map.setUI(customUI);		
		//map.setCenter(new GLatLng(48.580082,7.740841), 8);
	  

      // Create new geocoding object
      geocoder = new GClientGeocoder();
		map.setCenter(new GLatLng(48.280082,7.540841), 8);
		
		
		
		
		
		GEvent.addListener(map, "moveend", function() {
		var center = map.getCenter();
		//alert(center);
		/////////// ON GERE LA LIMITE DE LA CARTE

		var new_lat = center.lat();
		var new_lng = center.lng();
		
		eval("var limite_carte = arLimites.z"+map.getZoom());
		
		if(new_lat < limite_carte[1]) new_lat = limite_carte[1];
		else if(new_lat > limite_carte[0]) new_lat = limite_carte[0];

		if(new_lng < limite_carte[2]) new_lng = limite_carte[2];
		else if(new_lng > limite_carte[3]) new_lng = limite_carte[3];
		
		if(new_lat != center.lat() || new_lng != center.lng()) {
			map.panTo(new GLatLng(new_lat, new_lng),map.getZoom());
		}
		
		/////////// APRES UN DEPLACEMENT ON CACHE LE MARKEUR COURANT SI C'EST NECESSAIRE
		
		//window.setTimeout("cache_marqueur_courant()" ,100);
		cache_marqueur_courant();

	});


		

		

      // Retrieve location information, pass it to addToMap()
    
   }

   // This function adds the point to the map

   function addToMap(response)
   {
   
   
      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);

      // Center the map on this point
   //   map.setCenter(point, 8);

   
   // Create our "tiny" marker icon
var blueIcon = new GIcon(G_DEFAULT_ICON);

blueIcon.iconSize = new GSize(30, 44);
blueIcon.iconAnchor = new GPoint(15, 44);
                
// Set up our GMarkerOptions object
markerOptions = { icon:blueIcon };
var pres_html="<div id=\"adr_gmap\"><h3>"+tabLocation[indx].title+"</h3><a href=\""+tabLocation[indx].link+"\" target=_parent>lire l'article</a></div>";
switch(parseInt(tabLocation[indx].cat)){
//patrimoine
case 3:

blueIcon.image = "/carte/markers/patrimoine.png";
indx++;
break;

//balades
case 4:
blueIcon.image = "/carte/markers/balades.png";
indx++;
break;

//rencontre artistiques
case 5:
blueIcon.image = "/carte/markers/artistique.png";
indx++;
break;

//gourmandises
case 6:
blueIcon.image = "/carte/markers/gourmandise.png";
indx++;
break;

//resto & café
case 7:
blueIcon.image = "/carte/markers/resto.png";
indx++;
break;

//Evenements
case 8:
blueIcon.image = "/carte/markers/event.png";
indx++;
break;
}

   
      // Create a marker
     var marker = new GMarker(point,markerOptions);

      // Add the marker to map
      map.addOverlay(marker); 
	 
	  GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(pres_html);
  });
  
	
   }

	//adress,cat,title,link
	function showAdress(tab){
	tabLocation = tab;
	for(var i = 0;i<tabLocation.length;i++){	
	 geocoder.getLocations(tabLocation[i].address+",alsace,france", addToMap);
	 //alert(tabLocation[i].title);
	  
	}
		

	}
	
//]]>
