$.namespace("core.StaticMap");core.StaticMap=$.Class.extend({url_template:"http://maps.google.com/staticmap?key=%(api_key)&amp;center=%(center)&amp;markers=%(markers)&amp;size=%(size)&amp;format=png8",api_template:"http://www.google.com/jsapi?key=%(api_key)",marker_template:"%(media_path)static_map/images/markers/%(number).png",image_template:'<a href="javascript:void(0);" title="%(launch_copy)"><img src="%(map_url)" alt="Static Map" /><span class="map-link">%(launch_copy)</span></a>',loader_template:'<div class="map-loader"><img src="%(media_path)static_map/images/loader.gif" alt="Map Loader" /></div>',info_template:"<h3>%(title)</h3>%(description)",launch_copy:"Launch Interactive Map",selector:"",size:[300,300],center:[0,0],zoom:14,markers:[],media_path:"",render_template:function(c,a){for(val in a){var b=new RegExp("%\\("+val+"\\)","g");c=c.replace(b,a[val])}return c},clean_variable:function(b,a){if(b.charAt(b.length-1)==a){b=b.substring(0,(b.length-1))}return b},build_url:function(){var b=this.center[0]+","+this.center[1];var d="";if(this.markers.length>0){for(var a in this.markers){d+=this.markers[a].coordinates;if(this.markers.length>1||b!=this.markers[a].coordinates){d+=",red"+(parseInt(a)+1)+"|"}}}var c=this.render_template(this.url_template,{api_key:this.api_key,size:this.size[0]+"x"+this.size[1],center:b,markers:this.clean_variable(d,"|")});c+="&amp;zoom="+this.zoom;return c},draw_static_map:function(){$(this.selector).html(this.render_template(this.image_template,{map_url:this.build_url(),launch_copy:this.launch_copy})).find("a").click(this.launch_interactive_map.bind(this))},draw_interactive_map:function(){var d=new google.maps.Map2($(this.selector).get(0));var b=new google.maps.LatLng(this.center[0],this.center[1]);var f=new google.maps.LatLngBounds();f.extend(b);d.setCenter(b);d.addControl(new google.maps.SmallMapControl());for(var a=0;a<this.markers.length;a++){var e=new google.maps.LatLng(this.markers[a].coordinates[0],this.markers[a].coordinates[1]);var c=new google.maps.Marker(e,{icon:new google.maps.Icon(google.maps.DEFAULT_ICON,this.render_template(this.marker_template,{media_path:this.media_path,number:((this.markers.length==1&&b.equals(e))?"dot":(parseInt(a)+1))}))});if(typeof this.markers[a].title||typeof this.markers[a].description){c.bindInfoWindowHtml(this.render_template(this.info_template,{title:this.markers[a].title,description:this.markers[a].description}),{maxWidth:(parseInt(this.size[0])-100)})}d.addOverlay(c);f.extend(e)}d.setZoom(d.getBoundsZoomLevel(f)-1)},load_interactive_map:function(){if(typeof google=="object"){google.load("maps","2",{callback:this.draw_interactive_map.bind(this)})}else{this.draw_static_map();alert("There was an error while loading the interactive map. We are sorry for the inconvenience.")}},launch_interactive_map:function(){this.show_loader();if(typeof google=="object"){this.load_interactive_map()}else{$.getScript(this.render_template(this.api_template,{api_key:this.api_key}),this.load_interactive_map.bind(this))}return false},show_loader:function(){$(this.selector).append(this.render_template(this.loader_template,{media_path:this.media_path}))},hide_loader:function(){$(this.selector).find(".map-loader").remove()},init:function(a,b){this.selector=a;$(this.selector).addClass("static-map");if(b){for(opt in b){this[opt]=b[opt]}}this.draw_static_map()}});