// JavaScript Document
  
    function centromappav()	
	{ 
    if (infowindowopen!=open)
	document.getElementById("centromappa").style.visibility = "visible";	
   	}
	
	function centromappah()	
	{ 			  
	document.getElementById("centromappa").style.visibility = "hidden";	
   	}
	
	
	 //Geo

   var geocoder = new GClientGeocoder();
       
	   function showAddress(address)
		  {
		     geocoder.getLatLng(address,function(point){
             if(!point)
			 {alert(address+" not found");}
			 else
			 { 
         
			   map.setCenter(point, 14);
              var marker = new GMarker(point,gicons["create"]);
			    html = 	'<div class="lead" align="center">Per giungere a: ' + address + '<br> da '+meta+' clicca sul bottone.<br><br>' +
				'<form action="javascript:getDirections()">' +
			'<input type="hidden" size=40 maxlenght=40 name="saddr" id="saddr" value="'+meta+"@"+ metalat + ',' + metalon+'" />' +		  
            '<input value="Indicazioni / Get Direction" TYPE="SUBMIT"  > ' +
            '<input type="hidden" name="daddr" id="daddr" value="'+address+"@"+ point.lat() + ',' + point.lng() +'"/><\/form>'+
            
            '<br>Get Direction from: '+meta+'<br> to: ' + address + ' click on button.<br><\/div>';	  
              map.addOverlay(marker);
			  marker.tooltip = '<div class="tooltip">Hai Cercato/You have Searched:<br><h3>' + address + '<\/h3><br><strong style="padding-left:65px;">... click to open<\/strong><\/div>';
              marker.openInfoWindowHtml(html);
			  GEvent.addListener(marker,"mouseover", function() {showTooltip(marker);});         	 
              GEvent.addListener(marker,"mouseout", function() {tooltip.style.visibility="hidden"}); 
			  GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(html);});
              setTimeout("panend()",1000);	
			   }
			 //{ map.panTo(point)}
			 // 
			 // map.setZoom(12);
			
			 })
		  }
		  
// funzione per ricerca indirizzo da tooltip hotel		  
        function showAddress1(address)
		  {
		     geocoder.getLatLng(address,function(point){
             if(!point)
			 {alert(address+" non Trovato! - not Found!");}
			 else
			 { 
			
         getDirections1(address,point)            
			   }
			 //{ map.panTo(point)}
			 // 
			 // map.setZoom(12);
			
			 })
		  }
		  
		 function getDirections1(address,point) {
        daddr = ''+meta+"@"+ metalat + ',' + metalon+''
        saddr = ''+address+"@"+ point.lat() + ',' + point.lng() +''
        gdir.load("from: "+saddr+" to: "+daddr);
		document.getElementById('side_bar').style.display = 'none'; // nasconde il div da nascondere
		document.getElementById('directions').style.display ='block'; // mostra le direzioni
		map.setMapType(G_MAP_TYPE); // mette la mappa in mappa
		map.getInfoWindow().hide(); //nasconde il balloon
		
      }
	
	
	 
	 
  	      function panend()
	     {	     	 
		  map.setMapType(G_NORMAL_MAP);
	     }
	
	
	 function zoomin(livello) // funzione per richimare mappe dall'esterno
      { 
        var x = livello;          
        map.setZoom(x);
      }
	  

         function zoomin1(livello) // funzione per richimare mappe dall'esterno
      { 
        var x = livello ;         
        map.setZoom(x);
      map.setMapType(G_NORMAL_MAP);
      }

      function zoomin2(livello) // funzione per richimare mappe dall'esterno
      { 
        var x = livello ;         
        map.setZoom(x);
        setTimeout("map.setMapType(G_SATELLITE_MAP);",1000);
      }

	  function leggidaxml(xml,lat,lan) // funzione per richimare mappe dall'esterno
      {           
         readMap(''+xml+'')
         map.setCenter(new GLatLng('' + lat + '','' + lan + ''),8);
	     map.setMapType(G_SATELLITE_TYPE);
      }
	  
	   function tohotel(lat,lang) // funzione per richimare mappe dall'esterno
      {  
      
	   map.panTo(new GLatLng(lat,lang))
       
      }
	  
	   // === functions that perform the context menu options ==================================================
      function zoomIn() {
        // perform the requested operation
        map.zoomIn();
        // hide the context menu now that it has been used
        contextmenu.style.visibility="hidden";
      }      
      function zoomOut() {
        // perform the requested operation
        map.zoomOut();
        // hide the context menu now that it has been used
        contextmenu.style.visibility="hidden";
      }      
      function zoomInHere() {
        // perform the requested operation
        var point = map.fromContainerPixelToLatLng(clickedPixel)
        map.zoomIn(point,true);
        // hide the context menu now that it has been used
        contextmenu.style.visibility="hidden";
      }      
      function zoomOutHere() {
        // perform the requested operation
        var point = map.fromContainerPixelToLatLng(clickedPixel)
        map.setCenter(point,map.getZoom()-1); // There is no map.zoomOut() equivalent
        // hide the context menu now that it has been used
        contextmenu.style.visibility="hidden";
      }   


	  // da qui a qui==================================================================================0
          var pointdaqui;
          var pointaqui;		  
	      var markerdaqui;
	  function daqui() {
        // perform the requested operation
         pointdaqui = map.fromContainerPixelToLatLng(clickedPixel);
		 document.getElementById('daqui').style.display = 'none';
		 contextmenu.style.visibility="hidden";
		  markerdaqui = new GMarker(pointdaqui,gicons["create"]);
		  map.addOverlay(markerdaqui);
      }      
	   function aqui() {
        // perform the requested operation
         pointaqui = map.fromContainerPixelToLatLng(clickedPixel);
		 contextmenu.style.visibility="hidden";
		 document.getElementById('daqui').style.display = 'block';
		 getDirections2()
		 map.removeOverlay(markerdaqui) ;
      }  

	   
	  
	  
	   function getDirections2() {
	    if (pointdaqui==null){alert("Per creare un percorso,\npremi prima sul pulsante 'da qui'\n ----------------------\nTo create a personal direction \nuse Button 'From here' first.")}
		else
		{
	     saddr = 'Inizio tracciato@'+pointdaqui.lat()+','+pointdaqui.lng()+'';
         daddr = 'Fine tracciato@'+pointaqui.lat()+','+pointaqui.lng()+'';
        gdir.load("from: "+saddr+" to: "+daddr);
		document.getElementById('side_bar').style.display = 'none'; // nasconde il div da nascondere
		document.getElementById('directions').style.display ='block'; // mostra le direzioni
		map.setMapType(G_MAP_TYPE); // mette la mappa in mappa
		map.getInfoWindow().hide(); //nasconde il balloon
		pointdaqui= null; //resetto da qui per successive richieste
		}
      }
	   
	   // ===== request the directions =====
      function getDirections() {
        saddr = document.getElementById("saddr").value
        daddr = document.getElementById("daddr").value
        gdir.load("from: "+saddr+" to: "+daddr);
		document.getElementById('side_bar').style.display = 'none'; // nasconde il div da nascondere
		document.getElementById('directions').style.display ='block'; // mostra le direzioni
		map.setMapType(G_MAP_TYPE); // mette la mappa in mappa
		map.getInfoWindow().hide(); //nasconde il balloon
		
      }
	  // da qui a qui  FINE==================================================================================0
	  //funzione per tornare all'hotel dal context menu
     
	   function backDirection() {
        // perform the requested operation
        var point = map.fromContainerPixelToLatLng(clickedPixel)		
	    saddr = 'Inizio Percorso@'+point.lat()+','+point.lng()+'';
        daddr = ''+meta+'@'+ metalat + ',' + metalon+'';
        gdir.load("from: "+saddr+" to: "+daddr);
		document.getElementById('side_bar').style.display = 'none'; // nasconde il div da nascondere
		document.getElementById('directions').style.display ='block'; // mostra le direzioni
		map.setMapType(G_MAP_TYPE); // mette la mappa in mappa
		map.getInfoWindow().hide(); //nasconde il balloon
		contextmenu.style.visibility="hidden";
			
      }

	   var clicca = 0;
	  function invertidirezione() {
	
	  if (clicca == 0){ gdir.load("from: "+daddr+" to: "+saddr);clicca=1;}
	  else
	  { gdir.load("from: "+saddr+" to: "+daddr);clicca=0;}
      }
	  
	  
	  function comeArrivare() {
        // perform the requested operation		
		
        Mapread('panorami_arrivare.xml');        
		 map.setCenter(new GLatLng(metalat,metalon),9);
        // hide the context menu now that it has been used
        contextmenu.style.visibility="hidden";
      }
	  
	  
	  function stampa()
	  {
	  var contenuto_div = document.getElementById("directions").innerHTML;
	  window.print();
	 
	  }
