/* --------- /javascripts/markerGroup.js --------- */ 

function GMarkerGroup(active,markers,markersById){this.active=active;this.markers=markers||new Array();this.markersById=markersById||new Object();}
GMarkerGroup.prototype=new GOverlay();GMarkerGroup.prototype.initialize=function(map){this.map=map;if(this.active){for(var i=0,len=this.markers.length;i<len;i++){this.map.addOverlay(this.markers[i]);}
for(var id in this.markersById){this.map.addOverlay(this.markersById[id]);}}}
GMarkerGroup.prototype.remove=function(){this.deactivate();}
GMarkerGroup.prototype.redraw=function(force){}
GMarkerGroup.prototype.copy=function(){var overlay=new GMarkerGroup(this.active);overlay.markers=this.markers;overlay.markersById=this.markersById;return overlay;}
GMarkerGroup.prototype.clear=function(){this.deactivate();this.markers=new Array();this.markersById=new Object();}
GMarkerGroup.prototype.addMarker=function(marker,id){if(id==undefined){this.markers.push(marker);}else{this.markersById[id]=marker;}
if(this.active&&this.map!=undefined){this.map.addOverlay(marker);}}
GMarkerGroup.prototype.showMarker=function(id){var marker=this.markersById[id];if(marker!=undefined){GEvent.trigger(marker,"click");}}
GMarkerGroup.prototype.activate=function(active){active=(active==undefined)?true:active;if(!active){if(this.active){if(this.map!=undefined){for(var i=0,len=this.markers.length;i<len;i++){this.map.removeOverlay(this.markers[i])}
for(var id in this.markersById){this.map.removeOverlay(this.markersById[id]);}}
this.active=false;}}else{if(!this.active){if(this.map!=undefined){for(var i=0,len=this.markers.length;i<len;i++){this.map.addOverlay(this.markers[i]);}
for(var id in this.markersById){this.map.addOverlay(this.markersById[id]);}}
this.active=true;}}}
GMarkerGroup.prototype.centerAndZoomOnMarkers=function(){if(this.map!=undefined){var tmpMarkers=this.markers.slice();for(var id in this.markersById){tmpMarkers.push(this.markersById[id]);}
if(tmpMarkers.length>0){this.map.centerAndZoomOnMarkers(tmpMarkers);}}}
GMarkerGroup.prototype.deactivate=function(){this.activate(false);}/* --------- /javascripts/realius-map.js --------- */ 

Realius.Map={create:function(args){var map=new GMap2(args.element);var mapType=args.type||G_NORMAL_MAP;var zoomLevel=args.zoomLevel||1;var lat=args.lat||0;var lng=args.lng||0;map.setCenter(new GLatLng(lat,lng),zoomLevel);map.setMapType(mapType);return map;},createMarkerGroup:function(markers){return new GMarkerGroup(true,markers);},createMarker:function(coordinates,iconImagePath){return new GMarker(new GLatLng(coordinates[0],coordinates[1]),{icon:addOptionsToIcon(new GIcon(),{shadowSize:new GSize(36,34),iconAnchor:new GPoint(15,35),image:iconImagePath,infoWindowAnchor:new GPoint(5,1),shadow:"/images/shadow.png",iconSize:new GSize(32,32)})});},addGEventListener:function(){return GEvent.addListener.apply(this,arguments);},addInfoWindow:function(map,marker,infoWindowContents){Realius.Map.addGEventListener(marker,"mouseover",function(){Realius.Map.showInfoWindow(map,marker,infoWindowContents);});Realius.Map.addGEventListener(marker,"mouseout",function(){Realius.Map.hideInfoWindow();});},latLngToPixelsOnMap:function(latLng,map){var mp=map.fromLatLngToDivPixel(latLng);var cp=map.fromLatLngToDivPixel(map.getCenter());var mapSize=map.getSize();return[mp.x-cp.x+mapSize.width/2,mp.y-cp.y+mapSize.height/2];},showInfoWindow:function(map,marker,message){var infoWindow=$('listing-map-info-window');infoWindow.innerHTML=message;Position.clone(map.getContainer(),infoWindow,{setWidth:false,setHeight:false});var markerPos=this.latLngToPixelsOnMap(marker.getPoint(),map);Element.setStyle(infoWindow,{left:(parseInt(infoWindow.style.left)+markerPos[0]-infoWindow.offsetWidth-10)+"px",top:(parseInt(infoWindow.style.top)+markerPos[1]-infoWindow.offsetHeight/2-10)+"px",visibility:'visible'});CosmeticSurgery.push(marker,{dontHide:true,dontHideScrollbars:['region-list-container']});},hideInfoWindow:function(){var infoWindow=$('listing-map-info-window');if(infoWindow.getStyle('visibility')!='hidden'){Element.setStyle(infoWindow,{visibility:'hidden'});CosmeticSurgery.pop();}}};Realius.ListingMap={Model:ModelClass.create(),Presenter:PresenterClass.create(),View:ViewClass.create()};Object.extend(Realius.ListingMap.Presenter.prototype,{initialize:function(args){this.model=args.model;this.view=args.view;},this_subscriptionFinished:function(){this.view.showMap();this.view.moveMapToOriginalPosition();},view_mapPositioned:function(){this.model.readjustMap();},view_zoomClicked:function(){this.model.show();},view_mapClosed:function(){this.model.hide();},model_shown:function(){this.view.showZoomedMapOverlay();},model_hidden:function(){this.view.hideZoomedMapOverlay();}});Object.extend(Realius.ListingMap.Model,{typeControl:function(){if(!this._savedTypeControl){this._savedTypeControl=new Realius.Map.TypeControl();}
return this._savedTypeControl;}});Object.extend(Realius.ListingMap.Model.prototype,{initialize:function(args){this.map=args.map;this.zoomedZIndex=args.zoomedZIndex;this.normalZIndex=args.normalZIndex;},show:function(){with(this){CosmeticSurgery.push();var center=map.getCenter();notify('shown');map.setCenter(center);map.addControl(Realius.ListingMap.Model.typeControl());}},hide:function(){with(this){CosmeticSurgery.pop();var center=map.getCenter();notify('hidden');map.setCenter(center);map.removeControl(Realius.ListingMap.Model.typeControl());}},getMaskZIndex:function(){return this.zoomedZIndex;},getOverlayZIndex:function(){return this.zoomedZIndex+1;},getZoomedMapZIndex:function(){return this.zoomedZIndex+2;},getNormalMapZIndex:function(){return this.normalZIndex;},readjustMap:function(){this.map.checkResize();}});Object.extend(Realius.ListingMap.View.prototype,{initialize:function(args){},subscribe:function(){MessageBus.observe("mapZoomed",this.notify.bind(this,'zoomClicked'));MessageBus.observe("mapRequiresReposition",this.moveMapToOriginalPosition.bind(this));this.forwardEvents('#close-map-target',['click','mapClosed']);},showZoomedMapOverlay:function(args){Realius.showModalDialog({width:900,closeOnClick:false,showDiv:'zoomed-map-overlay'});this._setMapPos('zoomed-map-placeholder');},hideZoomedMapOverlay:function(){with(this){Realius.closeDialog();this.moveMapToOriginalPosition();}},moveMapToOriginalPosition:function(){this._setMapPos('map-placeholder');},showMap:function(){$('map').setStyle({visibility:'visible'});},_setMapPos:function(placeHolder){var map=$('map-container');map.remove();$(placeHolder).appendChild(map);Position.clone(placeHolder,'map-container');Position.clone(placeHolder,'map');this.notify('mapPositioned');}});/* --------- /javascripts/realius-map-controls.js --------- */ 

if(!window.Realius)window.Realius={};if(!Realius.Map)Realius.Map={};Realius.Map.NavigationControl=function(){};Realius.Map.NavigationControl.prototype=new GControl();Object.extend(Realius.Map.NavigationControl.prototype,{initialize:function(map){var container=document.createElement("div");Element.addClassName(container,"realius-map-controls")
var spec=Realius.Map.NavigationControl.buttonSpec(map);spec.each(function(nameAndCommand){Realius.Map.NavigationControl.buildButton(container,nameAndCommand[0],nameAndCommand[1]);});map.getContainer().appendChild(container);return container;},getDefaultPosition:function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(7,7));}});Object.extend(Realius.Map.NavigationControl,{buttonSpec:function(map){return[['zoom-in',function(){map.zoomIn();if(Realius.AjaxMessageBus){Realius.AjaxMessageBus.notify('mapZoomedIn')}}],['zoom-out',function(){map.zoomOut();if(Realius.AjaxMessageBus){Realius.AjaxMessageBus.notify('mapZoomedOut')}}],['pan-up',function(){map.panDirection(0,1);}],['pan-down',function(){map.panDirection(0,-1);}],['pan-left',function(){map.panDirection(1,0);}],['pan-right',function(){map.panDirection(-1,0);}]]},buildButton:function(container,name,command){var element=document.createElement('div');Element.addClassName(element,'control');Element.addClassName(element,name);GEvent.addDomListener(element,"click",command);container.appendChild(element);return element;}});Realius.Map.TypeControl=function(){};Realius.Map.TypeControl.prototype=new GControl();Object.extend(Realius.Map.TypeControl.prototype,{initialize:function(map){var container=document.createElement("div");Element.addClassName(container,"realius-map-type-controls")
map.getMapTypes().each(function(type){Realius.Map.TypeControl.addButtonForMapType(map,container,type);});map.getContainer().appendChild(container);return container;},getDefaultPosition:function(){return new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,7));}});Object.extend(Realius.Map.TypeControl,{addButtonForMapType:function(map,container,mapType){var element=document.createElement('div');Element.addClassName(element,'control');var mapTypeName=mapType.getName().gsub(/\s+/,'');Element.addClassName(element,mapTypeName);GEvent.addDomListener(element,'click',function(){map.setMapType(mapType)});container.appendChild(element);}});
