//<![CDATA[
function load(jsFile)
{
	if (GBrowserIsCompatible()) {
		 
		  
/////////////////////////////////////////	 code added
	var latitudine = 44.762702;
	var longitudine = 8.354073;

	var httpdominio = "http://www.tenutalaromana.it/";
	var template = "templates/laromana/images/icon/";
	var con_sidebar = true;
	var poiFiles = [];
	poiFiles[0] = "templates/laromana/javascript/data.xml";
	
	// this variable will collect the html which will eventualkly be placed in the side_bar
	var side_bar_html = "";
	
	// arrays to hold copies of the markers and html used by the side_bar
	// because the function closure trick doesnt work there
	var gmarkers = [];
	var htmls = [];
	var i = 0;
	
	// arrays to hold variants of the info window html with get direction forms open
	var to_htmls = [];
	var from_htmls = [];



			  
	
	// A function to create the marker and set up the event window
	function createMarker(markerXML){
		// oggetto markerXML -> attributi : lat,lng,img,tit,addr,telfax,mail,big
		var lat = parseFloat(markerXML.getAttribute("lat"));
		var lng = parseFloat(markerXML.getAttribute("lng"));
		
		//alert(lat+' - '+lng);
		
		var latpoint = new GLatLng(lat,lng);
		
		
		 // / Creo l'icona
		 var icon = new GIcon();
		 icon.image = httpdominio + template + markerXML.getAttribute("img") + ".gif";
		 icon.shadow = httpdominio + template + "shadow.png";
		 icon.iconSize = new GSize(40, 40);
		 icon.shadowSize = new GSize(37, 34);
		 icon.iconAnchor = new GPoint(0, 20);
		 icon.infoWindowAnchor = new GPoint(1, 5);
		
		 var point = new GMarker(latpoint,icon);
	
		 // costruisco la minipagina da visualizzare (info window)
		 // classi css : tit,addr,coordinate,imgthumb
		 var html = '<div class="mapsbox"><img src="'+icon.image+'" alt="' + markerXML.getAttribute("tit") + '" border="0" align="left" style="margin-right:3px;" /><h4 style="padding-top:7px;">' + markerXML.getAttribute("tit") + '</h4>';
			html += '<img src="' + markerXML.getAttribute("big") + '" border="0" align="right" style="margin-left:5px;margin-bottom:5px;"><br>';
			html += '<span class="small" >';
			html += 	markerXML.getAttribute("addr") + '<br />' + markerXML.getAttribute("telfax") + '<br /><a href="mailto:' + markerXML.getAttribute("mail") + '">' + markerXML.getAttribute("mail") + '</a>';
			html += '</span>';
			//html += '<div class=""><b>lat: </b>' + markerXML.getAttribute("lat") + ' - <b>long: </b>' + markerXML.getAttribute("lng") + '</div>';
			html += '</div>';
	
		 // aggiungo testo e bottoni per quando ha cliccato su "to here" 
		 // classi css : gmapsboxtxtsmall
		 to_htmls[i] = html + '<div id="gmapsboxtxtsmall">Traccia il percorso <b>fino a qui</b> (o <a href="javascript:fromhere(' + i + ')">da qui a</a>)</div>' +
			'<div class="gmapsboxtxtsmall"><b>da dove: </b>(scrivi: cittā, ev. indirizzo)<br />(es. Savona, Largo Folconi, 3 - o solo Savona)</div>'+
			'<form action="http://maps.google.com/maps" method="get" target="_blank">' +
			'<input type="text" size=40 maxlength=40 name="saddr" value="" /><br />' +
			'<input value="vai alle indicazioni stradali" type="submit" />' +
			'<input type="hidden" name="daddr" value="' + latpoint.lat() + ',' + latpoint.lng() + '" />' +
			'</form>';
			
		 // aggiungo testo e bottoni per quando ha cliccato su  "from here"
		 from_htmls[i] = html + '<div class="gmapsboxtxtsmall">Traccia il percorso: <a href="javascript:tohere(' + i + ')">(a qui)</a> - <b>da qui</b></div>' +
			'<div class="gmapsboxtxtsmall"><b>a dove: </b>(scrivi: cittā, ev. indirizzo)<br />(es. Savona, Largo Folconi, 3 - o solo Savona)</div>'+
			'<form action="http://maps.google.com/maps" method="get" target="_blank">' +
			'<input type="text" size="40" maxlength="40" name="daddr" value="" /><br />' +
			'<input value="vai alle indicazioni stradali" type="submit" />' +
			'<input type="hidden" name="saddr" value="' + latpoint.lat() + ',' + latpoint.lng() + '" />' +
			'</form>';
	
		  // aggiungo testo e bottoni per quando visualizzo info window, non selezionato ancora nč "to here" nč "from here"
          //html = html + '<div class="gmapsboxtxtsmall">Trova il percorso: <a href="javascript:tohere(' + i + ')">fino a qui</a> oppure <a href="javascript:fromhere(' + i + ')">da qui a</a></div>';
		 
		  GEvent.addListener(point,"click", function() {
	      	point.openInfoWindowHtml(html);
		  });
	
	
		 gmarkers[i] = point;
		 htmls[i] = html;
		
		 // aggiungo il posto alla side_bar html
		 // classi css : gmapssidebar,gmapssidebargoto
		
		
		
		
		side_bar_html += '<table width="90%" cellpadding="0" cellspacing="2" border="0">';
		side_bar_html += '<tr>';
		side_bar_html += '<td width="24"><a href="javascript:myclick(' + i + ')"><img src="'+icon.image+'" alt="img" border="0" /></a></td>'; // cella dell'icona        
		side_bar_html += '<td class="linkmenumap"><a href="Javascript:myclick('+lat+','+lng+','+icon+','+markerXML+');">' + markerXML.getAttribute("tit") + '</a>'; // cella del punto        
	
	
		
	
	
		if (i>0){
			// presuppongo che il primo marker sia l'origine di partenza quindi non posso calcolare percorso essendo punto uguale (dovrei testare le coordinate se uguali non visualizzare)
			//side_bar_html += '<br /><a href="http://maps.google.com/maps?saddr=' + latitudine + ',' + longitudine + '&daddr=' + latpoint.lat() + ',' + latpoint.lng() + '" target="_blank"><img src="icone/percorso.gif" alt="Calcola il percorso" /></a>';
		}
	
		side_bar_html += '</td></tr>';
		side_bar_html += '</table>';
	
		// aggiunge il punto alla mappa
		map.addOverlay(point);
		
		// apre la finestra html del primo punto
		if (i<1){
			point.openInfoWindowHtml(html);
		}
		
		// incremento punto
		i++;
	}// fine function createMarker
	
	
	
	
	
	
/////////////////////////////////////////		  
		  
		var geoXml = new GGeoXml("http://maps.google.com/maps/ms?ie=UTF8&hl=it&msa=0&output=nl&msid=117575207120792490887.0004605dfc4647b7c7afd&output=nl");
        var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
	    map.setCenter(new GLatLng(44.762702,8.354073), 13);
		map.addControl(new GOverviewMapControl ());
		
		//map.addOverlay(geoXml);
////////// Add 10 markers to the map at random locations ++++ +++ +++ +++ ++ ++ EXAMPLE OF GOOGLE

/*        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        for (var i = 0; i < 10; i++) {
          var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),
                                  southWest.lng() + lngSpan * Math.random());
          map.addOverlay(new GMarker(latlng));
        }
		
		// aggiunta da me
		//alert(lngSpan);
		var latvsp = new GLatLng('43.505733','11.022197');
		map.addOverlay(new GMarker(latvsp));
*/
		
		
////////// Add 10 markers to the map at random locations ++++ +++ +++ +++ ++ ++ EXAMPLE OF GOOGLE
		
		// aggiunge i punti di interesse
		for (var nFile = 0 ; nFile < poiFiles.length; nFile++)
		{	
			// Download the data in data.xml and load it on the map.
			GDownloadUrl(poiFiles[nFile], function(data, responseCode) 
			{ 
				
			 // To ensure against HTTP errors that result in null or bad data,
			 // always check status code is equal to 200 before processing the data
			 if ((responseCode == 200)||(responseCode == 0)) {
	
				// qui mettere codice per dividere un gruppo da un altro
				side_bar_html += "<h3 style='text-align:center;' class='section_dove'>Strutture</h3>";
	
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				
				
				for (var j = 0; j < markers.length; j++) {
					//alert(markers[j]);
					//var marker = createMarker(markers[j]);
					//map.addOverlay(marker);
					
					createMarker(markers[j])
				} 
				
				// scrive nella colonna dx del menu mappa
				//document.getElementById("menu_map").innerHTML = side_bar_html;
				//fenetra(1);
	
			  } 
			 	else if(responseCode == -1) 
			  { 
			 	alert("Richiesta scaduta. Prego riprovare pių tardi."); 
			  }
				else
			  {	
				alert("Elenco punti di interesse non recuperabile.Prego controllare."); 
			  }
			});
		}		
		
		
		// window.attachEvent("onunload", closeGMaps);      

	if (window.addEventListener) //DOM method for binding an event
		window.addEventListener("unload", closeGMaps, false);
	else if (window.attachEvent) //IE exclusive method for binding an event
		window.attachEvent("onunload", closeGMaps);
	else if (document.getElementById) //support older modern browsers
		window.onunload=closeGMaps;

	}
	else 
	{ 
		alert("Sorry, the Google Maps API is not compatible with this browser"); 
	}
}
// This function picks up the click and opens the corresponding info window
function myclick(lat,lng,icon,markerXML) {
	var latpoint = new GLatLng(lat,lng);
	var point = new GMarker(latpoint);
 	point.openInfoWindowHtml(htmlschedule(icon,markerXML));
	// document.getElementById("tmp_box").innerHTML = htmls[i];
}
function htmlschedule(icon,markerXML){
	 var html = '<div class="mapsbox"><img src="'+icon.image+'" alt="' + markerXML.getAttribute("tit") + '" border="0" align="left" style="margin-right:3px;" /><h4 style="padding-top:7px;">' + markerXML.getAttribute("tit") + '</h4>';
			html += '<img src="' + markerXML.getAttribute("big") + '" border="0" align="right" style="margin-left:5px;margin-bottom:5px;"><br>';
			html += '<span class="small" >';
			html += 	markerXML.getAttribute("addr") + '<br />' + markerXML.getAttribute("telfax") + '<br /><a href="mailto:' + markerXML.getAttribute("mail") + '">' + markerXML.getAttribute("mail") + '</a>';
			html += '</span>';
			html += '<div class=""><b>lat: </b>' + markerXML.getAttribute("lat") + ' - <b>long: </b>' + markerXML.getAttribute("lng") + '</div>';
			html += '</div>';
	return html;
}
// functions that open the directions forms
function tohere(i) {
 gmarkers[i].openInfoWindowHtml(to_htmls[i]);
	// document.getElementById("tmp_box").innerHTML = to_htmls[i];
}
function fromhere(i) {
 gmarkers[i].openInfoWindowHtml(from_htmls[i]);
	// document.getElementById("tmp_box").innerHTML = from_htmls[i];
}
function closeGMaps() 
{
// alert("chiudo");
 GUnload();
}
//]]>


