// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

document.observe("dom:loaded", function() {
  //the element in which we will observe all clicks and capture
  // ones originating from pagination links
  var container = $(document.body);

  if (container) {
    var img = new Image;
    img.src = '/images/spinner.gif';

    function createSpinner() {
      return new Element('img', { src: img.src, 'class': 'spinner' })
    }
    container.observe('click', function(e) {
      var el = e.element();
      if (el.match('.viva_pagination a')) {
        el.up('.viva_pagination').insert(createSpinner())
        new Ajax.Request(el.href, { method: 'get' });
        e.stop();
      }
    })
  }
})

var geocoder = null;
var map;
var addressMarker;

document.observe("dom:loaded", function() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(-29.2207, -50.5244), 15);
    map.setUIToDefault();
    geocoder = new GClientGeocoder();
  }
});

function showAddress(address) {
  if (geocoder) {
    geocoder.getLatLng(address,
        function(point) {
          if (!point) {
            alert(address + "não encontrado");
          } else {
            if (addressMarker) {
              map.removeOverlay(addressMarker);
          }
          addressMarker = new GMarker(point);
          map.setCenter(point);
          map.addOverlay(addressMarker);
        }
    });
  }
}
