document.observe('dom:loaded', function() {
  find_nearby_byways();
});


function supports_geolocation()
{
	return !!navigator.geolocation;
}

function find_nearby_byways()
{
  list = $('nearby-byways-list');
  updater = new Element('p')
    .insert(new Element('img', {src: "/graphics/loading_bar.gif", alt: ''}))
    .insert(' Finding your location...');
	
	if (supports_geolocation())
	{
		list.hide();
		list.insert({before: updater});
		navigator.geolocation.getCurrentPosition(
		  function(location) {
			  new Ajax.Request('/explore/nearby?lat=' + location.coords.latitude + '&lng=' + location.coords.longitude, {
			    method: 'GET',
			    onSuccess: function(response) {
			      list.update(response.responseText);
            updater.remove();
    	      list.show();
			    },
			    onFailure: function(response) {
            updater.remove();
    	      list.show();
			    }
			  });
		  },
		  function(error) {
        updater.remove();
	      list.show();
		  },
		  {timeout: 10000});
	}
}
