$(function() {
  $('.map').each(function() {
    $this = $(this);
    if (typeof GBrowserIsCompatible == 'function' && GBrowserIsCompatible()) {
      var map = new GMap2(this);
      map.setUIToDefault();
      map.disableScrollWheelZoom();

      if ($this.attr('latitude') && $this.attr('longitude')) {
        var coords = new GLatLng($this.attr('latitude'), $this.attr('longitude'));
        map.setCenter(coords, 16);
        var marker = new GMarker(coords);
        map.addOverlay(marker);
      }

      if ($this.hasClass('togglable')) {
        $this.hide();
      }
    } else {
      $this.hide().closest('.map').hide();
    }
  });
});
