function OpenBooking() {
	window.open('https://www.simplebooking.it/booking.aspx?GUID=06B93D09-CDA2-4AAC-985A-37A40A9B4E95&amp;LANG={_LANGUAGE_CODE_BOOKING}', '','scrollbars=no,resizable=yes,location=no,menubar=no,status=yes,width=630,height=400');
	return false;
}

function loadPercorso() {
//	icon = new GIcon();
	icon = new google.maps.Icon();
	icon.image = 'http://www.'+percorso_dati['dominio']+'/puntatore_mappa.gif';
	icon.iconSize = new GSize(percorso_dati['icon_width'], percorso_dati['icon_height']);
	icon.iconAnchor = new GPoint(20, percorso_dati['icon_height']);
	var Lat = percorso_dati['Lat'];
	var Lon = percorso_dati['Lon'];
	var map = new GMap2(document.getElementById("percorso_mappa"));
	var center = new GLatLng(Lat, Lon);
	map.setCenter(center, percorso_dati['zoom']);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	var marker = new GMarker(new GLatLng(Lat, Lon), icon);
	map.addOverlay(marker);
}

function setDirections(indirizzo) {
	if (typeof( mapcanvas ) != 'object') {
		mapcanvas = new GMap2(document.getElementById("percorso_mappa"));
		gdir = new GDirections(mapcanvas, document.getElementById("percorso_testuale"));
		mapcanvas.addControl(new GSmallMapControl());
		mapcanvas.addControl(new GMapTypeControl());
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);
	}
	if (typeof( indirizzo ) == 'object') {
			indirizzo = indirizzo.value;
			var scelta = document.forms[0].elements['scelta'];
			for (i=0; i<scelta.length; i++) scelta[i].checked = false;
	}
	var fromAddress = indirizzo;
	var toAddress = percorso_dati['struttura'];
	marker_struttura_index = 1;
	marker_indirizzo_index = 0;
	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale" : percorso_dati['locale'] });
}

function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		alert("The given key is either invalid or does not match the domain for which it was given.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	else
		alert("An unknown error occurred.");
}

function onGDirectionsLoad(){
	var icona_marker_struttura = gdir.getMarker(marker_struttura_index).getIcon();
	icona_marker_struttura.image = icon.image;
	icona_marker_struttura.iconSize = icon.iconSize;
	icona_marker_struttura.iconAnchor = icon.iconAnchor;
	var icona_marker_indirizzo = gdir.getMarker(marker_indirizzo_index).getIcon();
	icona_marker_indirizzo.image = "http://maps.google.com/mapfiles/kml/pal3/icon31.png";
	icona_marker_indirizzo.iconSize = new GSize(32, 32);
	icona_marker_indirizzo.iconAnchor = new GPoint(16, 32);
}

google.setOnLoadCallback(function(){
	$(document).pngFix( );
	$("a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 30, /* padding for each side of the picture */
				opacity: 0.55, /* Value betwee 0 and 1 */
				showTitle: false, /* true/false */
				theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
	});
	if (typeof(google.maps)!='undefined') {
		var mapcanvas;
		var gdir;
		var marker_struttura_index;
		var marker_indirizzo_index;
		var icon;
		loadPercorso();
		$('#percorsi').submit(function () {
			setDirections($('#indirizzo').val());
			return false;
		});
	}
});

