gears_loc_init();

function gears_loc_init() {
  if (!window.google || !google.gears) {
    // addStatus('Gears is not installed', 'error');
    return;
  }

//  addStatus('Getting location...');

  function successCallback(p) {
    var address = p.gearsAddress.city + ', '
                  + p.gearsAddress.region + ', near '
                  + p.gearsAddress.street;

    var link = 'http://pdxstump.com/directory/?' 
		  + 'lat=' + p.latitude + '&'
		  + 'lon=' + p.longitude;

//    clearStatus();
//    addStatus('Your address is: ' + address + ' <a href="' + link + '">see nearby tags</a>');
      window.location.href = link;
  }

  function errorCallback(err) {
    var msg = 'Error retrieving your location: ' + err.message;
    setError(msg);
  }

  try {
    var geolocation = google.gears.factory.create('beta.geolocation');
    geolocation.getCurrentPosition(successCallback,
                                   errorCallback,
                                   { enableHighAccuracy: true,
                                     gearsRequestAddress: true });
  } catch (e) {
    setError('Error using Geolocation API: ' + e.message);
    return;
  }


}

  function addStatus(message) {
	   var elm = document.getElementById('status');
	   if (!elm) return;
	   var id = 'statusEntry' + (elm.childNodes.length + 1);

           elm.innerHTML += '<span id="' + id + '">' + message + '</span>';

	   elm.innerHTML += '<br>';
	   // setTextContent(getElementById(id), message);
   }

   function clearStatus() {
	   var elm = document.getElementById('status');
	   elm.innerHTML = '';
   }

