var CKRE_Maps=new Class({Implements:[Options],options:{baseUrl:"",mapControls:[GLargeMapControl,GOverviewMapControl],doubleClickZoom:true,googleBar:false,defaultLoc:{lat:0,lng:0,zoom:1}},initialize:function(B,A){if(!GBrowserIsCompatible()){return false}this.setOptions(A);this.mapDiv=B;this.setupMap();this.mgr=new MarkerManager(this.map)},setupMap:function(){this.map=new GMap2(this.mapDiv);this.options.mapControls.each(function(A){this.map.addControl(new A())},this);if(this.options.doubleClickZoom){this.map.enableDoubleClickZoom()}if(this.options.googleBar){this.map.enableGoogleBar()}this.setCenter(this.options.defaultLoc)},createIcon:function(A){var B=new GIcon();B.image=A.image;B.iconAnchor=new GPoint(A.width,A.height);B.infoWindowAnchor=new GPoint(16,0);B.iconSize=new GSize(A.width,A.height);return B},createMarker:function(A,B){return new CKRE_Maps.Marker(A,B)},addMarker:function(A){this.mgr.addMarker(A,1)},addMarkers:function(B,A){this.mgr.clearMarkers();this.map.setZoom(this.map.getBoundsZoomLevel(A));this.map.setCenter(A.getCenter());this.mgr.addMarkers(B,1);this.mgr.refresh()},gotoLocation:function(C){var A=new GLatLng(C.lat,C.lng);var B=this.createMarker(A,{icon:this.createIcon({image:this.options.baseUrl+"/images/markers/house.png",width:32,height:32})});this.addMarker(B);this.map.setCenter(B.getPoint(),14)},setCenter:function(A){this.map.setCenter(new GLatLng(A.lat,A.lng),A.zoom)},unload:function(){GUnload()}});CKRE_Maps.Marker=function(B,A){GMarker.apply(this,arguments);if(A.infoWindow){GEvent.addListener(this,"click",function(){this.openInfoWindowHtml(A.infoWindow)})}if(A.infoOverlay){GEvent.addListener(this,"click",function(){this.map.overlay.show(A.infoOverlay)})}if(A.tooltip){this.addTooltip(A.tooltip)}};CKRE_Maps.Marker.prototype=new GMarker(new GLatLng(0,0));CKRE_Maps.Marker.prototype.initialize=function(A){GMarker.prototype.initialize.call(this,A);this.map=A;if(this.tooltip){if(this.getMarkerElement()){this.getMarkerElement().store("tip:title",this.tooltip.title);this.getMarkerElement().store("tip:text",this.tooltip.text);this.map.tooltips.attach(this.getMarkerElement())}}};CKRE_Maps.Marker.prototype.redraw=function(A){GMarker.prototype.redraw.call(this,A)};CKRE_Maps.Marker.prototype.getMarkerElement=function(){if(!this.map.markerElProp){for(var A in this){if(this[A] instanceof Array&&$type(this[A][0])=="element"){this.map.markerElProp=A;return $(this[A][0])}}}else{return $(this[this.map.markerElProp][0])}return null};CKRE_Maps.Marker.prototype.addTooltip=function(A){this.tooltip=A};CKRE_Maps.Polygon=function(F,E,A,B,G,C,D){GPolygon.apply(this,arguments);this.options=D;this.options.fillOpacity=C;if(D.infoOverlay){this.infoOverlay=D.infoOverlay}};CKRE_Maps.Polygon.prototype=new GPolygon();CKRE_Maps.Polygon.prototype.initialize=function(A){GPolygon.prototype.initialize.call(this,A);this.map=A};CKRE_Maps.Polygon.prototype.redraw=function(B){GPolygon.prototype.redraw.call(this,B);var D=this.getPolygonElement();if(!D){return }var C=GEvent.callback(this,this.onOver);var A=GEvent.callback(this,this.onOut);GEvent.clearInstanceListeners(D);GEvent.addDomListener(D,"mouseover",function(){C()});GEvent.addDomListener(D,"mouseout",function(){A()})};CKRE_Maps.Polygon.prototype.onOver=function(){var A=this.getPolygonElement();A.setStyle("cursor","help");this.map.overlay.show(this.infoOverlay)};CKRE_Maps.Polygon.prototype.onOut=function(){this.map.overlay.hide()};CKRE_Maps.Polygon.prototype.getPolygonElement=function(){if(Browser.Engine.webkit||Browser.Engine.presto){if(this.map.polygonElProp){return $(this[this.map.polygonElProp[0]][0][this.map.polygonElProp[1]])}for(var B in this){if(this[B] instanceof Array){for(var A in this[B][0]){if($type(this[B][0][A])=="element"&&$(this[B][0][A]).get("tag")=="img"){this.map.polygonElProp=[B,A];return $([B][0][A])}}}}}else{if(Browser.Engine.trident){if(this.map.polygonElProp){return $(this[this.map.polygonElProp])}for(var B in this){if($type(this[B])=="element"&&$(this[B]).get("tag")=="shape"){this.map.polygonElProp=B;return $(this[B])}}}else{if(Browser.Engine.gecko){if(this.map.polygonElProp){return $(this[this.map.polygonElProp]).getElement("path")}for(var B in this){if($type(this[B])=="element"&&$(this[B]).get("tag")=="svg"){return $(this[B]).getElement("path")}}}else{return false}}}};CKRE_Maps.Properties=new Class({Extends:CKRE_Maps,options:{mapControls:[GSmallMapControl],localSearch:true,propertiesUrl:"/maps/properties"},initialize:function(B,A){this.parent(B,A);this.map.overlay=new CKRE_Maps.Overlay(this.mapDiv);this.setupTips();this.setupLocalSearch()},setupTips:function(){this.map.tooltips=new CKRE_Maps.Tips();this.map.tooltips.setOptions({fixed:true,hideDelay:180,showDelay:60});if(Browser.Engine.trident){this.map.tooltips.tip.addEvent("mouseenter",function(A){this.setStyle("visibility","visible")});this.map.tooltips.tip.addEvent("mouseleave",function(A){this.setStyle("visibility","hidden")})}else{this.map.tooltips.removeEvents("onHide");this.map.tooltips.tip.setStyles({opacity:0});this.map.tooltips.tip.set("tween",{duration:280});this.map.tooltips.tip.addEvent("mouseenter",function(A){this.tween("opacity",1)});this.map.tooltips.tip.addEvent("mouseleave",function(A){this.tween("opacity",0)});this.map.tooltips.addEvents({onShow:function(A){A.tween("opacity",1)},onHide:function(A){A.tween("opacity",0)}})}},setupLocalSearch:function(){this.gSearchForm=new GSearchForm(false,false);this.gSearchForm.setOnSubmitCallback(null,this.captureForm.bind(this));this.gSearchForm.input.focus();this.gLocalSearch=new GlocalSearch();this.gLocalSearch.setCenterPoint(this.map);this.gLocalSearch.setSearchCompleteCallback(null,this.onLocalSearch.bind(this))},executeLocalSearch:function(A){this.gLocalSearch.setCenterPoint(this.map);this.gSearchForm.execute(A)},captureForm:function(A){this.gLocalSearch.execute(A.input.value);return false},onLocalSearch:function(){if(!this.gLocalSearch.results){return }for(var B=0;B<this.gLocalSearch.results.length;B++){var C=this.gLocalSearch.results[B];var A=new GLatLng(C.lat,C.lng);this.mgr.addMarker(this.createMarker(A,{icon:this.createIcon({image:this.options.baseUrl+"/images/markers/marker_yellow.png",width:10,height:14}),tooltip:{title:C.title||C.streetAddress,text:$(C.html).get("html")}}),1)}},addProperties:function(B){if(B.length===0){return }var A=new GLatLngBounds();var C=[];B.each(function(E){var D=new GLatLng(E.lat,E.lng);var F=this.createMarker(D,{icon:this.createIcon({image:this.options.baseUrl+"/images/markers/"+E.type+".png",width:32,height:32}),tooltip:this.createTooltip(E)});A.extend(D);C.push(F)},this);this.addMarkers(C,A)},addZone:function(C){var E=[];var B=new GLatLngBounds();for(i=0;i<C.zone.length;i++){var A=new GLatLng(C.zone[i].lat,C.zone[i].lng);E.push(A);B.extend(A)}var D=new Element("h3",{html:C.title});D.setStyle("color","#ffffff");polyShape=new CKRE_Maps.Polygon(E,"#FFCC33",1,0.8,"#EDCD6D",0.25,{infoOverlay:D});this.map.addOverlay(polyShape)},createTooltip:function(I){var C=new Element("div",{"class":"property-info"});var G=new Element("div",{html:I.price}).inject(C);var H=new Element("ul").inject(C);var E=new Element("li",{html:I.bedrooms+" Bed"}).inject(H);var B=new Element("li",{html:I.bathrooms+" Bath"}).inject(H);var F=new Element("li",{html:I.car_spaces+" Car"}).inject(H);var A=new Element("img",{src:this.options.baseUrl+"/resources/property-images/"+I.id+"-1_120x90.jpg"}).inject(H,"after");var D=new Element("div").adopt(C).get("html");return{title:I.address,text:D}}});CKRE_Maps.Tips=new Class({Extends:Tips,initialize:function(){this.parent();this.eventChain=new Chain();this.tip.addEvent("mouseenter",function(A){$clear(this.timer)}.bind(this))}});CKRE_Maps.Overlay=new Class({Implements:[Events,Options],options:{},initialize:function(A){this.mapDiv=A;this.container=new Element("div");this.container.set("class","map_overlay");this.container.set("morph",{duration:280,transition:Fx.Transitions.Expo.easeOut});this.container.setStyles({left:this.mapDiv.getSize().x-220,height:1,position:"absolute","z-index":1});this.container.setOpacity(0);this.container.inject(this.mapDiv)},attach:function(A){var B=A.retrieve("overlay");this.show=this.show.bindWithEvent(this,B);this.hide=this.hide.bindWithEvent(this);A.addEvents({mouseenter:this.show,mouseleave:this.hide})},detach:function(A){A.removeEvent("mouseleave",this.hide);A.removeEvent("mouseenter",this.show)},hide:function(){this.container.morph({height:1,opacity:0})},show:function(A){if(this.container.getFirst()){this.container.getFirst().dispose()}this.overlayElement=new Element("div").inject(this.container);if(typeof A=="string"){this.overlayElement.set("html",A)}else{this.overlayElement.adopt(A)}this.container.morph({height:this.overlayElement.getSize().y,opacity:".9"})}});