	var map = null;
    var geocoder = null;
	var icons = [];
	var latitude;
	var longitude;
	var class_min;
	var class_max;
	var address;
	var citta;
	var hotelsGroup = { "stella0": [], "stella1": [], "stella2": [], "stella3": [],"stella4": [],"stella5": []};
	var markers_id = [];
	 if (GBrowserIsCompatible()){

	 
      function createMarker(point,id,name,address,city_hotel,stars,preferred,longitude,latitude,hotel_url) {
	  var cons="";
	  if(preferred){
	  cons="<br><font size=2 color=\"#FF0000\">Consigliato: Si!</font>";
	  }
	  
	  var html="<b>"+name+"</b><br><font size=2><i>"+address+", "+city_hotel+"</i></font>"+cons+"&nbsp;&nbsp;<a onClick=\"javascript:(seeHotelDescription('"+id+"'));\" href=\"#mappa_hotels\">Dettagli</a>&nbsp;&nbsp;<a href='"+hotel_url+"' target=_blank>Prenota</a>";
	  
	  if(!in_array(markers_id,id)){
		markers_id.push(id);
		var marker = new GMarker(point,icons[stars]);
		var type = "stella"+stars;
        hotelsGroup[type].push(marker); 
		GEvent.addListener(marker, "click", 
		function() {
          marker.openInfoWindowHtml(html);
        });

        // The new marker "mouseover" listener        
        GEvent.addListener(marker,"mouseover", 
		function() {
          marker.openInfoWindowHtml(html);
        }); 
		
        map.addOverlay(marker);
	}
    }
	
	function in_array(Array, element){
	var res=false;
	for(var e=0;e<Array.length;e++){
     if(Array[e] == element){
       res=true;
       break;
		}
	}
	return res;
	}
	
	function toggleGroup(type) { 
      for (var i = 0; i < hotelsGroup[type].length; i++) { 
        var marker = hotelsGroup[type][i]; 
        if (marker.isHidden()) { 
          marker.show(); 
        } else { 
          marker.hide(); 
        } 
      } 
    }
	
	
	function loadMarkers(latitudine,longitudine){

	latitudine=latitudine.toString();
	longitudine=longitudine.toString();
    latitudine=latitudine.replace(".",",");
	longitudine=longitudine.replace(".",",");
	
	var base="http://www.vainvacanza.it/home/alberghi/";
	var xml_url="xml/get_alberghi.php?latitudine="+latitudine+"&longitudine="+longitudine;

	 GDownloadUrl( base + xml_url, function(data) 					{
	
	var xml = GXml.parse(data);
    var markers = xml.documentElement.getElementsByTagName("albergo");
    for(var i=0;i<markers.length;i++){ 
          var m = markers[i]; 
          var point = new GLatLng(parseFloat(m.getAttribute("lat")),parseFloat(m.getAttribute("lng"))); 
        var id = markers[i].getAttribute("id");
		var name = markers[i].getAttribute("name"); 
		var address = markers[i].getAttribute("address"); 
		//var ufi = markers[i].getAttribute("ufi"); 
		var city_hotel = markers[i].getAttribute("city_hotel"); 
		var stars = markers[i].getAttribute("class"); 
		var preferred = markers[i].getAttribute("preferred");
		//var nr_rooms = markers[i].getAttribute("nr_rooms"); 
		var longitude = markers[i].getAttribute("longitude"); 
		var latitude = markers[i].getAttribute("latitude"); 
		var hotel_url = markers[i].getAttribute("hotel_url"); 
		//var photo_url = markers[i].getAttribute("photo_url"); 
		//var desc_it = markers[i].getAttribute("desc_it");
		
		
        createMarker(point,id,name,address,city_hotel,stars,preferred,longitude,latitude,hotel_url); 
        
 
		}
  
	}); 
	
	}
	  

    
	function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(41.5333, 12.2931), 5);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
        geocoder = new GClientGeocoder();
		
		GEvent.addListener(map, "moveend", function() {
		coord=map.getCenter();
		loadMarkers(coord.lat(),coord.lng());
		});
		
		var star_icon = new GIcon();
		star_icon.image = "http://www.vainvacanza.it/home/alberghi/puntatori/star.gif";
		star_icon.shadow = "http://www.vainvacanza.it/home/alberghi/puntatori/shadow-star.png";
		star_icon.iconSize = new GSize(50, 50);
		star_icon.shadowSize = new GSize(76, 50);
		star_icon.iconAnchor = new GPoint(25, 50);
		star_icon.infoWindowAnchor = new GPoint(25, 25);
		
		var star1_icon = new GIcon();
		star1_icon.image = "http://www.vainvacanza.it/home/alberghi/puntatori/1star.gif";
		star1_icon.shadow = "http://www.vainvacanza.it/home/alberghi/puntatori/shadow-star.png";
		star1_icon.iconSize = new GSize(50, 50);
		star1_icon.shadowSize = new GSize(76, 50);
		star1_icon.iconAnchor = new GPoint(25, 50);
		star1_icon.infoWindowAnchor = new GPoint(25, 25);
		
				var star2_icon = new GIcon();
		star2_icon.image = "http://www.vainvacanza.it/home/alberghi/puntatori/2star.gif";
		star2_icon.shadow = "http://www.vainvacanza.it/home/alberghi/puntatori/shadow-star.png";
		star2_icon.iconSize = new GSize(50, 50);
		star2_icon.shadowSize = new GSize(76, 50);
		star2_icon.iconAnchor = new GPoint(25, 50);
		star2_icon.infoWindowAnchor = new GPoint(25, 25);
		
				var star3_icon = new GIcon();
		star3_icon.image = "http://www.vainvacanza.it/home/alberghi/puntatori/3star.gif";
		star3_icon.shadow = "http://www.vainvacanza.it/home/alberghi/puntatori/shadow-star.png";
		star3_icon.iconSize = new GSize(50, 50);
		star3_icon.shadowSize = new GSize(76, 50);
		star3_icon.iconAnchor = new GPoint(25, 50);
		star3_icon.infoWindowAnchor = new GPoint(25, 25);
		
				var star4_icon = new GIcon();
		star4_icon.image = "http://www.vainvacanza.it/home/alberghi/puntatori/4star.gif";
		star4_icon.shadow = "http://www.vainvacanza.it/home/alberghi/puntatori/shadow-star.png";
		star4_icon.iconSize = new GSize(50, 50);
		star4_icon.shadowSize = new GSize(76, 50);
		star4_icon.iconAnchor = new GPoint(25, 50);
		star4_icon.infoWindowAnchor = new GPoint(25, 25);
		
				var star5_icon = new GIcon();
		star5_icon.image = "http://www.vainvacanza.it/home/alberghi/puntatori/5star.gif";
		star5_icon.shadow = "http://www.vainvacanza.it/home/alberghi/puntatori/shadow-star.png";
		star5_icon.iconSize = new GSize(50, 50);
		star5_icon.shadowSize = new GSize(76, 50);
		star5_icon.iconAnchor = new GPoint(25, 50);
		star5_icon.infoWindowAnchor = new GPoint(25, 25);
		
		icons[0] = star_icon;
		icons[1] = star1_icon;
		icons[2] = star2_icon;
		icons[3] = star3_icon;
		icons[4] = star4_icon;
		icons[5] = star5_icon;
      }
    }

	
    function showAddress(address) {
	coord = new Array();
	
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
				
              //alert(address + " non trovato! Sei sicuro di aver scritto l'indirizzo giusto? ;-) Attenzione: se l'errore dovesse ripetersi si consiglia di riavviare la pagina!");
			  caricaPagina('aiuto_ricerca_alberghi','http://www.vainvacanza.it/home/alberghi/ds_subsearch.php?cercacitta='+address,'aiuto_ricerca_alberghi');
				} else {
				//caricaPagina('punti_riferimento','http://www.vainvacanza.it/home/alberghi/get_pdr.php?rif='+escape(address),'punti_riferimento');
 
				map.setCenter(point, 16);
				coord = map.getCenter();
				var web = "<h4 align=\"left\">" + address + "</h4><p align=\"left\">Per visualizzare l'elenco degli alberghi <a target=\"_blank\" href=\"http://www.vainvacanza.it/home/alberghi/gotoresults.php?lat="+coord.lat()+"&lon="+coord.lng()+"&d="+escape(address)+"\">clicca qui<\/a></p>"; 
				var marker = new GMarker(point);
				GEvent.addListener(marker, "click", 
					function() {
					marker.openInfoWindowHtml(web);
					});
					
				 // The new marker "mouseover" listener        
				GEvent.addListener(marker,"mouseover", 
					function() {
				marker.openInfoWindowHtml(web);
				});        
        
				map.addOverlay(marker);
				marker.openInfoWindowHtml(web);
				

				
				caricaPagina('aiuto_ricerca_alberghi','http://www.vainvacanza.it/home/alberghi/get_cities_by_loc_addr.php?citta='+escape(address)+'&latitudine='+coord.lat()+'&longitudine='+coord.lng(),'aiuto_ricerca_alberghi');
				
				loadMarkers(coord.lat().toString(),coord.lng().toString());
				
				caricaPagina('lista_pdr_alberghi','http://www.vainvacanza.it/home/alberghi/get_col1_box_orizzontale_pdr.php?rif='+escape(address),'lista_pdr_alberghi');

				
				}
			}
			);
	  
		}
    }
	
	}
	else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
	
