google.load("maps","2",{other_params:"sensor=false"});MapDisplay=Class.create();MapDisplay.prototype={rsrc_id:null,container:null,map:null,geocoder:null,markers:new Hash({}),markerTemplate:new Template('<div class="locationEmbedded">#{street}<br />#{city}, #{state} #{zip} 	#{country} <a href="http://maps.google.com/maps?geocode=&q=#{desc}" class="link_googleMap" id="" target="_blank"><img src="/images/icons/maps-arrow.png" title="Go to Google map" /></a><br /></div>'),markerTemplateShort:new Template('<div class="locationEmbedded">	#{desc} <a href="http://maps.google.com/maps?geocode=&q=#{desc}" class="link_googleMap" id="" target="_blank"><img src="/images/icons/maps-arrow.png" title="Go to Google map" /></a><br /></div>'),linkPrimaryTemplate:new Template('<li class="primary_location" id="location_id_#{location_id}"><a href="javascript:void(0);" id="location_link_#{location_id}">#{street}<br />#{city}, #{state} #{zip} #{country}</a><a href="http://maps.google.com/maps?geocode=&q=#{desc}" class="link_googleMap" id="" target="_blank"><img src="/images/icons/maps-arrow.png" title="Go to Google map" /></a></li>'),linkPrimaryTemplateShort:new Template('<li class="primary_location" id="location_id_#{location_id}"><a href="javascript:void(0);" id="location_link_#{location_id}">#{desc}</a><a href="http://maps.google.com/maps?geocode=&q=#{desc}" class="link_googleMap" id="" target="_blank"><img src="/images/icons/maps-arrow.png" title="Go to Google map" /></a></li>'),linkAdditionalTemplate:new Template('<li class="additional_location" id="location_id_#{location_id}"><a href="javascript:void(0);" id="location_link_#{location_id}">#{street}<br />#{city}, #{state} #{zip} #{country}</a><a href="http://maps.google.com/maps?geocode=&q=#{desc}" class="link_googleMap" id="" target="_blank"><img src="/images/icons/maps-arrow.png" title="Go to Google map" /></a></li>'),linkAdditionalTemplateShort:new Template('<li class="additional_location" id="location_id_#{location_id}"><a href="javascript:void(0);" id="location_link_#{location_id}">#{desc}</a><a href="http://maps.google.com/maps?geocode=&q=#{desc}" class="link_googleMap" id="" target="_blank"><img src="/images/icons/maps-arrow.png" title="Go to Google map" /></a></li>'),initialize:function(a){this.url="/submitajax/mapdisplay";this.rsrc_id=$("hidden_resourceId").value;this.container=$(a);Event.observe(window,"load",this.loadMap.bind(this))},loadMap:function(){if(!google.maps.BrowserIsCompatible()){return}Event.observe(window,"unload",this.unloadMap.bind(this));this.map=new google.maps.Map2(this.container);this.zoomAndCenterMap();this.map.addControl(new google.maps.MenuMapTypeControl());this.map.addControl(new google.maps.SmallZoomControl3D());var a={parameters:"action=get&rsrc_id="+this.rsrc_id,onSuccess:this.loadLocationsSuccess.bind(this)};new Ajax.Request(this.url,a)},zoomAndCenterMap:function(){var b=new google.maps.LatLngBounds();this.markers.each(function(c){b.extend(c.value.getPoint())});if(b.isEmpty()){this.map.setCenter(new google.maps.LatLng(40.820882,-73.945164),16,G_NORMAL_MAP)}else{var a=Math.max(1,this.map.getBoundsZoomLevel(b)-1);this.map.setCenter(b.getCenter(),a)}},loadLocationsSuccess:function(b){var a=b.responseText.evalJSON(true);if(a.locations==null){return}a.locations.each(function(d){this.addMarkerToMap(d.location_id,d.latitude,d.longitude,d.description,d.street_address,d.city,d.state,d.zip,d.country,d.primary_location);if(d.primary_location==1){var g="Main Location"}else{var g="Location"}if(!d.street_address){var e=this.markerTemplateShort.evaluate({location_id:d.location_id,lat:d.latitude,lng:d.longitude,desc:d.description})}else{var e=this.markerTemplate.evaluate({location_id:d.location_id,lat:d.latitude,lng:d.longitude,desc:d.description,street:d.street_address,city:d.city,state:d.state,zip:d.zip,country:d.country})}var f=Builder.build(e);this.markers[d.location_id].bindInfoWindow(f);if(d.location_id){if(d.primary_location==1){if(!d.street_address){var h=this.linkPrimaryTemplate.evaluate({location_id:d.location_id,lat:d.latitude,lng:d.longitude,desc:d.description})}else{var h=this.linkPrimaryTemplate.evaluate({location_id:d.location_id,lat:d.latitude,lng:d.longitude,desc:d.description,street:d.street_address,city:d.city,state:d.state,zip:d.zip,country:d.country})}var c=Builder.build(h);$("ul_location").appendChild(c);$("location_link_"+d.location_id).observe("click",this.onLinkClick.bindAsEventListener(this,f))}else{if(!d.street_address){var h=this.linkAdditionalTemplateShort.evaluate({location_id:d.location_id,lat:d.latitude,lng:d.longitude,desc:d.description})}else{var h=this.linkAdditionalTemplate.evaluate({location_id:d.location_id,lat:d.latitude,lng:d.longitude,desc:d.description,street:d.street_address,city:d.city,state:d.state,zip:d.zip,country:d.country})}var c=Builder.build(h);$("ul_location").appendChild(c);$("location_link_"+d.location_id).observe("click",this.onLinkClick.bindAsEventListener(this,f))}}}.bind(this));this.zoomAndCenterMap()},addMarkerToMap:function(b,j,k,i,e,g,a,c,d){this.markers[b]=new google.maps.Marker(new google.maps.LatLng(j,k),{title:i,draggable:false});this.markers[b].location_id=b;this.map.addOverlay(this.markers[b]);var h=this.markerTemplate.evaluate({location_id:b,lat:j,lng:k,description:i,street:e,city:g,state:a,zip:c,country:d});var f=Builder.build(h);this.markers[b].bindInfoWindow(f);return this.markers[b]},onLinkClick:function(c,b){var a=Event.element(c).id.replace("location_link_","");this.map.panTo(new GLatLng(this.markers[a].qa.y,this.markers[a].qa.x));this.markers[a].openInfoWindowHtml(b,{maxWidth:"200"})},unloadMap:function(){google.maps.Unload()}};
