
$(document).ready ->
  $(".gmap").on "click", (event) ->
    event.preventDefault()
    $.getJSON $(this).attr("href") + "?callback=?", (data) =>

      $.fancybox
        'transitionIn': 'elastic'
        'transitionOut': 'elastic'
        'speedIn': 600
        'speedOut': 200
        'overlayShow': false
        'content': '<div class=\'map_container\'><div id=\'map\' class=\'gmaps4rails_map\'></div></div>'

      $('#map').gmap().bind 'init', (ev, map) ->
        $('#map').gmap('addMarker',
          'position': new google.maps.LatLng(data.latitude, data.longitude)
          'bounds': true).click ->
          $('#map').gmap 'option', 'zoom', 10
          return
        return


  ###
      Gmaps.map = new Gmaps4RailsGoogle()
      Gmaps.load_map = ->
        Gmaps.map.map_options.auto_adjust = true
        Gmaps.map.map_options.zoom = 15
        Gmaps.map.map_options.auto_zoom = false
        Gmaps.map.initialize()
        Gmaps.map.markers = [{"lat": data.latitude, "lng": data.longitude}]
        Gmaps.map.create_markers()
        Gmaps.map.adjustMapToBounds()
        Gmaps.map.callback()
      Gmaps.triggerOldOnload()
      Gmaps.loadMaps()
  ###
