window.google=window.google||{};google.maps=google.maps||{};(function($){$.fn.MapSearch=function(options){var $this=this,$opts=$.extend({},$.fn.MapSearch.defaults,options),$proxy=Enlighten.Jasons.Site.Services.MapHelper,$map,$infoWindow,$markers=[],$regionMarkers=[],LoadLocations=function(){showLoading();$opts.MicroRegionID!=null&&$proxy.GetTownsInMicroRegion($opts.MicroRegionID,function(result){for(var i in result)AddMarker(i,result[i]);hideLoading()});$opts.MacroRegionID!=null&&$proxy.GetMicroRegionsInMacroRegion($opts.MacroRegionID,function(result){for(var i in result)AddMarker(i,result[i]);hideLoading()})},FormatContent=function(index,listing){return"<b style='font-size:13px'>"+listing.Name+"</b><br/>View the <a href='"+listing.Url+"'>"+listing.Name+" travel guide</a><br/>To book accommodation in this area <a href='"+listing.Url+"/accommodation'>click here</a>"},AddMarker=function(index,town){var point=new google.maps.LatLng(town.Latitude,town.Longitude);if($markers[index]==null){var marker=new google.maps.Marker({position:point,map:$map,zIndex:1}),content=FormatContent(index,town);bindInfoWindow(index,marker,content);$markers[index]=marker}},bindInfoWindow=function(index,marker,content){google.maps.event.addListener(marker,"click",function(){$infoWindow.setContent(content);$infoWindow.open($map,marker)});$(".inner-scrollable a."+index).click(function(){$infoWindow.setContent(content);$infoWindow.open($map,marker)})},getScript=function(src){var s=document.createElement("script");s.src=src;document.body.appendChild(s)},showLoading=function(){$(".map-loading-icon").css("display","inline")},hideLoading=function(){setTimeout(function(){$(".map-loading-icon").hide()},1e3)};this.render=function(){getScript("http://maps.google.com/maps/api/js?sensor=false&callback=$MapSearch.load");return $this};this.load=function(){if($opts.Latitude!=null&&$opts.Longitude!=null){var latlng=new google.maps.LatLng($opts.Latitude,$opts.Longitude),myOptions={zoom:parseInt($opts.Zoom)==0?6:parseInt($opts.Zoom),center:latlng,mapTypeId:google.maps.MapTypeId.ROADMAP};$map=new google.maps.Map(document.getElementById($($this).attr("id")),myOptions)}$infoWindow=new google.maps.InfoWindow({width:440,maxHeight:400,maxWidth:440,disableAutoPan:false});LoadLocations()};return this.render()};$.fn.MapSearch.defaults={}})(jQuery)
