/*

* * * * * * * * * * * * * * * * * * * * * * * *
*       						              * 
*             Mashup by Cyrus                 *
*   http://www.wingeneration.altervista.org   *
*          wingeneration@hotmail.it           *
*                                             *
* * * * * * * * * * * * * * * * * * * * * * * *

*/
// variabili globali
var map, 
    gdir,
    ovmap,
    marker,
    html_tab1,
    geocoder = null;  
    
// localizzazione coordinate correnti - qui cambierai i valori di lat e long
  //var dove_siamo = new GLatLng(37.663448, 14.835995); 
  var dove_siamo = new GLatLng(37.502066,15.091202); 
 // var dove_siamo = new GLatLng(38.137527,15.144224); 
  
// crea un marcatore con una finestra delle info a due tabs
    function createTabbedMarker(dove_siamo,html_tab1,html_tab2,label1,label2){
        var marker = new GMarker(dove_siamo, icona);
         marker.tooltip = '<div class="tooltip"><nobr>'+'Sikanie'+'</nobr></div>';
          
		// apri la finestra delle infowindow al click del mouse
        GEvent.addListener(marker, "click", function() {
	        //crea i 2 tabs
    	    createTab1 = new GInfoWindowTab(label1,html_tab1), 
        	createTab2 = new GInfoWindowTab(label2,html_tab2);
	        // mostro il tutto
    	      marker.openInfoWindowTabsHtml([createTab1,createTab2]);
        });
        
	   // crea un evento alla chiusura della nuvoletta
        GEvent.addListener( map, "infowindowclose", function(){ conferma(); } );
             
      // restituisco il marcatore
      return marker; 
    }
//==============================================================================================================================
// ...caricamento della mappa in corso...
document.getElementById("map").style.background = "url(maps/loading.jpg)";
// crea la mappa
	map = new GMap(document.getElementById("map"));

// focalizza dove_siamo
	map.setCenter(dove_siamo, 17);  
//==============================================================================================================================

// aggiungi o rimuovi i seguenti controlli alla mappa:
// barra dello zoom a sinistra 
	map.addControl(new GSmallMapControl());
// zoom con la rotella del mouse
	map.enableScrollWheelZoom(); 

// Mappa, Satellite
	map.addControl(new GMapTypeControl());

// rimuovi mappa Ibrida
	map.removeMapType(G_HYBRID_MAP);

// Terreno
	map.addMapType(G_PHYSICAL_MAP);

// riquadro in basso a destra
//	ovMap = new GOverviewMapControl(new GSize(150,150));
//	map.addControl(ovMap);
//  minimizza il riquadro
//	ovMap.hide(); 

//==============================================================================================================================  
// inserisci il tooltip e rendilo nascosto all'uscita del mouse
      var tooltip = document.createElement("div");
        map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);
          tooltip.style.visibility="hidden";
//==============================================================================================================================  

  // logo powered by Geodispenser - logo accanto a quello di Google
        var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(70,0));
            	pos.apply(document.getElementById("control"));
                    map.getContainer().appendChild(document.getElementById("control"));

//==============================================================================================================================   
//  mostra il tooltip in base a due eventi: passaggio e uscita del mouse
    function tipEvents () 
	{
		GEvent.addListener(marker,"mouseover", function() {
          showTooltip(marker);
        });        
        GEvent.addListener(marker,"mouseout", function() {
		tooltip.style.visibility="hidden"
        }); 
	}
//==============================================================================================================================    

  // funzione per creare la visualizzazione del tooltip
  function showTooltip(marker) 
  {
      tooltip.innerHTML = marker.tooltip;
      var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	  var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	  var anchor=marker.getIcon().iconAnchor;
      var width=marker.getIcon().iconSize.width;
      var height=tooltip.clientHeight;
      var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
          pos.apply(tooltip);
          
		  tooltip.style.visibility="visible";
  }
