function erasePhoto(nome)
{
	if(!! confirm("vuoi davvero cancellare questa foto?"))
	$.ajax(
	{
		url			: "../libreria/functions.php",
		dataType	: "JSON",
		type		: "POST",
		data		: "nome=" + nome + "&function=erase",
		success		: function(data)
		{
			if(data != 'ok') alert("incontrato un problema: " + data);
			else 
			{
				nome = nome.slice(0,nome.indexOf('.'));
				$("#" + nome).toggle('fast');
			}
		}
	});
}

function addTitle(name, classe)
{
	var idFile = name.substr(0,name.length-4);
						$.ajax(
						{
							url			:	"libreria/functions.php",
							dataType	:	"text",
							type		:	"POST",
							data		:	"filename=" + name,
							beforeSend	:	function()
							{
								$("#main").append("<a href='images/" + name + "' id='" + idFile + "' rel='shadowbox[Gallery]'><img src='libreria/gd.php?fname=../images/" + name + "&w=270' " + classe + " /></a>");
							},
							success		:	function(textTitle)
							{
								$("#" + idFile).attr("title",textTitle);
							}
						});
}

	function loadMorePhotos()
		{
			var last = $("#photoNumber").attr("value");
			$.ajax(
			{
				url			: "libreria/functions.php",
				dataType	: "JSON",
				type		: "POST",
				data		: "morePhotos="+last,
				beforeSend	: function()
				{
					$("#photoNumber").attr("value", parseInt($("#photoNumber").attr("value")) + 8); 					
				},
				success		: function(data)
				{
					var classe = "";
					$.each(data.sample, function(i, sample)
					{
						classe = "";
						if (i%4 == 0) classe = "class='alpha'";
						else if (i%4 == 3) classe = "class='omega'";					
						addTitle(sample, classe);
						
						
						
					});
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup();
				}
			});
		}

		
function initialize() 
  {	  
    geocoder = new google.maps.Geocoder();
	directionsDisplay = new google.maps.DirectionsRenderer();
    var myOptions = 
	{
      zoom: 12,
      center: storie,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	directionsDisplay.setMap(map);
	var marker = new google.maps.Marker(
		{
            map: map, 
            position: storie,
			title: "storie d'amore"
        });
   	if (navigator.geolocation) 
	{
		var options = 
		{
			timeout: 10000,
            enableHighAccuracy: true
        }
   	    navigator.geolocation.getCurrentPosition(callback, notfound, options);
   	} 
	else 
	{
        document.getElementById("manual_address").style.display="block";
   	}
		
  }
  
  
   function callback(pos)
    {
        var latitudine  = pos.coords.latitude;
        var longitudine = pos.coords.longitude;
        var precisione = pos.coords.accuracy;
		var myAddress = new google.maps.LatLng(latitudine, longitudine);
        findTheWay(myAddress);
    }

    function notfound() 
	{
        document.getElementById("manual_address").style.display="block";
    }
	
	
	function findTheWay(startPoint)
	{
		var request = 
		{
        	origin: startPoint, 
        	destination:storie,
        	travelMode: google.maps.DirectionsTravelMode.DRIVING
    	};
	    directionsService.route(request, function(response, status) 
		{
      		if (status == google.maps.DirectionsStatus.OK) 
			{
        		directionsDisplay.setDirections(response);
				directionsDisplay.setPanel(document.getElementById("directionsPanel"));
				var route = response.routes[0];
		        document.getElementById("confirmAddress").innerHTML = "<br />" + route.legs[0].start_address + " non è il tuo indirizzo? <span id='changeAddress' onclick='mostraFinestra();'> cambialo</span>";
		        document.getElementById("confirmAddress").style.display="inline";
		        document.getElementById("changeAddress").style.display="inline";
				var t= setTimeout("creaBarra()",200);
      		}
    	});		
	}
	
	function nascondiFinestra()
	{
        document.getElementById("manual_address").style.display="none";		
	}	

	function mostraFinestra()
	{
        document.getElementById("manual_address").style.display="block";		
        document.getElementById("confirmAddress").style.display="none";		
        document.getElementById("changeAddress").style.display="none";		
	}	

  function codeAddress() 
  {
	nascondiFinestra();
    var address = document.getElementById("address").value;
    geocoder.geocode( 
	{ 
	'address': address
	}, function(results, status) 
	{
      if (status == google.maps.GeocoderStatus.OK) 
	  {
		  findTheWay(results[0].geometry.location);
      } else 
	  {
        alert("Google non è in grado di calcolare la strada da questo indirizzo: " + status);
		document.getElementById("manual_address").style.display="block";	 
      }
    });
  }

function getData()
{
	var cDate = new Date();
	var data = (cDate.getYear() + 1900) + "-" + (cDate.getMonth()+1) + "-" + cDate.getDate() + " " + cDate.getHours() + ":" + cDate.getMinutes() + ":" + cDate.getSeconds();
	return data;
}















