// Render a link for mapping objects to Google Maps.
// version 1.1
// 2006-10-21
// Copyright (c) 2006, Calvin Yu
//
// --------------------------------------------------------------------
//
// This is a Tails script.
//
// To install, you need Tails: http://blog.codeeg.com/tails-firefox-extension/
// Then restart Firefox and revisit this script and click on 'Install'.
//
// To uninstall, go to Tools/Manage Tails Scripts...,
// select "Map with Google", and click Uninstall.
//
// Update 2006-10-21 (v1.1)
//   - Added support for geo objects
//
// --------------------------------------------------------------------
//
// ==TailsScript==
// @name          Map with Google
// @namespace     http://blog.codeeg.com/tails
// @description   Render a link for mapping objects to Google Maps.
// @include       hcard
// @include       hcalendar
// @include       hreview
// @include       geo
// ==/TailsScript==

getURL: function() {
  if (this.object.__name == "hcard") {
    return this.buildURL(this.object);
  } else if (this.object.__name == "hcalendar" && this.object.location_hcard) {
    return this.buildURL(this.object.location_hcard);
  } else if (this.object.__name == "hreview" && this.object.item_hcard) {
    return this.buildURL(this.object.item_hcard);
  } else if (this.object.__name == "geo") {
    return "http://maps.google.com/maps?f=q&hl=en&q="
        + this.object.latitude + "," + this.object.longitude
        + "&ie=UTF8&om=1";
  }
},
buildURL: function(hcard) {
  if ((hcard.locality && hcard.region)
      || hcard['postal-code']) {

    var location = hcard.toAddressString();
    return "http://maps.google.com/maps?f=q&hl=en&q="
        + location.replace(/\s+/g, '+')+"&ie=UTF8&om=1"
  }
}
