!function(){"use strict";Backbone.Marionette.MarkerModel=Backbone.Model.extend({defaults:{title:"",content:"",lat:null,lon:null}}),Backbone.Marionette.MarkersCollection=Backbone.Collection.extend({model:Backbone.Marionette.MarkerModel}),Backbone.Marionette.MarkerView=Backbone.Marionette.ItemView.extend({template:'

<%= title %>

<%= content %>
',constructor:function(a){if("undefined"==typeof google||"undefined"==typeof google.maps)throw new Error("MarkerView needs google maps library");if("undefined"==typeof a.map||"undefined"==typeof a.bounds)throw new Error("MarkerView needs a 'options.map' object");if(Backbone.Marionette.ItemView.apply(this,arguments),"undefined"==typeof this.model||null===this.model.get("lat")||null===this.model.get("lon"))throw new Error("This view needs a model with 'lat' and 'lon' attributes");return this.marker=new google.maps.Marker({position:new google.maps.LatLng(this.model.get("lat"),this.model.get("lon")),map:this.options.map,title:this.model.get("title")}),parseFloat(_.VERSION)>=1.7&&(this.template=_.template(this.template)),this.options.bounds.extend(this.marker.position),this.options.map.fitBounds(this.options.bounds),this.infowindow=new google.maps.InfoWindow({content:this.parseInfoWindow()}),this.markerListener=google.maps.event.addListener(this.marker,"click",_.bind(this.openWindow,this)),this.mapListener=google.maps.event.addListener(this.options.map,"open:infowindow",_.bind(this.closeWindow,this)),this},render:function(){return this.marker},parseInfoWindow:function(){return parseFloat(_.VERSION)>=1.7?this.template(this.model.toJSON()):_.template(this.template,this.model.toJSON())},openWindow:function(){google.maps.event.trigger(this.options.map,"open:infowindow"),this.infowindow.open(this.options.map,this.marker)},closeWindow:function(){this.infowindow.close()},remove:function(){return this.stopListening(),google.maps.event.removeListener(this.markerListener),google.maps.event.removeListener(this.mapListener),this.$el&&this.$el.remove(),this.marker.setMap(null),delete this.marker,this}}),Backbone.Marionette.MapView=Backbone.Marionette.CollectionView.extend({el:"#map",childView:Backbone.Marionette.MarkerView,options:{},bounds:null,mapOptions:{zoom:13,maxZoom:16,attributionControl:!1,panControl:!1,scaleControl:!0},constructor:function(){if("undefined"==typeof google||"undefined"==typeof google.maps)throw new Error("MapView needs google maps library");return Backbone.Marionette.CollectionView.apply(this,arguments),this.setMapOptions(),this.bounds=new google.maps.LatLngBounds,this.map=new google.maps.Map(this.$el[0],this.mapOptions),this.childViewOptions={map:this.map,bounds:this.bounds},this},initialize:function(){return this},setMapOptions:function(){this.options.lat&&this.options.lon&&(this.mapOptions.center=new google.maps.LatLng(this.options.lat,this.options.lon)),this.mapOptions.mapTypeControlOptions={style:google.maps.MapTypeControlStyle.DROPDOWN_MENU}},onRender:function(){this.map.fitBounds(this.bounds)},refreshResize:function(){google.maps.event.trigger(this.map,"resize"),this.map.fitBounds(this.bounds)}})}(window||global||this);