function loadMapa(a){if(mapaLoaded==false){initialize(a)}}var regionesBusquedas={Brasil:{Value:31,Nombre:"Brasil"},Uruguay:{Value:32,Nombre:"Uruguay"},Argentina:{Nombre:"Argentina"}};var markers=new Array();function updateMarkersIcons(){for(indx=0;indx<markers.length;indx++){mark=markers[indx];if(Login.IsFavorito(mark.aviso.idVisibilidad)){mark.normalImage=mark.parameters.IconFavorito;mark.mouseOverImage=mark.parameters.IconFavoritoOver;mark.setImage(mark.normalImage)}else{mark.normalImage=mark.parameters.Icon;mark.mouseOverImage=mark.parameters.IconOver;mark.setImage(mark.normalImage)}}}function initialize(d){map=new GMap2(document.getElementById("MapCanvas"));var a=new GLatLngBounds();var j;var c;var f;markers=new Array();map.removeInfoWindow=function(){if(this.lastInfoWindow!=null){this.removeOverlay(this.lastInfoWindow);this.lastInfoWindow=null}};var h=1;var b=0;var g=0;$.each(avisos,function(){if(g==this.longitud&&b==this.latitud){this.longitud=this.longitud-parseFloat(0.00015*h);h++}else{g=this.longitud;b=this.latitud}});$.each(avisos,function(){f=new CustomMarker(this,a);markers.push(f);map.addOverlay(f,{zIndexProcess:getZIndex});Login.AddHandler(updateMarkersIcons)});map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());var e=new GClientGeocoder();if(markers.length==0){e.getLocations(getRegionBusqueda(d),function(l){var n=l.Placemark[0].ExtendedData.LatLonBox;var k=new GLatLng(n.south,n.west);var m=new GLatLng(n.north,n.east);boundsRegion=new GLatLngBounds(k,m);map.setCenter(boundsRegion.getCenter());map.setZoom(map.getBoundsZoomLevel(boundsRegion))})}else{map.setCenter(a.getCenter());map.setZoom(map.getBoundsZoomLevel(a))}mapaLoaded=true;return false}function getRegionBusqueda(a){switch(a){case regionesBusquedas.Brasil.Value:return regionesBusquedas.Brasil.Nombre;case regionesBusquedas.Uruguay.Value:return regionesBusquedas.Uruguay.Nombre;default:return regionesBusquedas.Argentina.Nombre}}function CustomInfoWindow(d,b,a,c){this.latlng=d;this.element=b;this.offsetY=a;this.offsetX=c;this.divTopMargin=10;this.divLeftMargin=10}CustomInfoWindow.prototype=new GOverlay();CustomInfoWindow.prototype.initialize=function(b){this.div=$(this.element).clone();this.div.css({position:"absolute"}).appendTo(b.getPane(G_MAP_FLOAT_PANE));this.map=b;var a=["mousedown","mouseup","dblclick","DOMMouseScroll","onmousewheel","contextmenu","click","mousemove","mousewheel","singlerightclick"];for(i=0;i<a.length;i++){GEvent.bindDom(this.div.get(0),a[i],this,this.onClick)}this.redraw(true)};CustomInfoWindow.prototype.onClick=function(b){try{b.stopPropagation()}catch(a){window.event.cancelBubble=true}};CustomInfoWindow.prototype.remove=function(){this.div.remove()};CustomInfoWindow.prototype.copy=function(){return new CustomInfoWindow(this.latlng,this.element)};CustomInfoWindow.prototype.redraw=function(b){if(!b){return}var a=this.map.fromLatLngToDivPixel(this.latlng);this.div.css({left:a.x-this.div.width()+this.offsetX,top:a.y-this.div.height()+this.offsetY});this.map.ensureElementVisibility(this.div[0])};function CustomMarker(f,d){this.inOver=false;this.aviso=f;this.parameters=markersParameters[f.tipoDestaque];this.normalImage=this.parameters.Icon;this.overImage=this.parameters.IconOver;this.offsetFactor=0.7;var b=new GLatLng(f.latitud,f.longitud);d.extend(b);if(Login.IsFavorito(this.aviso.idVisibilidad)){this.normalImage=this.parameters.IconFavorito;this.overImage=this.parameters.IconFavoritoOver}var e=new GIcon(G_DEFAULT_ICON);e.image=this.normalImage;e.iconSize=new GSize(this.parameters.IconWidth,this.parameters.IconHeight);var a=Math.ceil(this.parameters.IconHeight*this.offsetFactor);var c=Math.ceil(this.parameters.IconWidth*this.offsetFactor);e.imageMap=[0,0,a,0,a,c,0,c];this.inheritFrom=GMarker;this.inheritFrom(b,{icon:e,zIndexProcess:getZIndex})}CustomMarker.prototype=new GMarker(0,0);CustomMarker.prototype.initialize=function(a){this.map=a;GMarker.prototype.initialize.call(this,a);GEvent.bindDom(this,"mouseover",this,this.onMouseOver);GEvent.bindDom(this,"mouseout",this,this.onMouseOut);GEvent.bindDom(this,"click",this,this.onClick)};CustomMarker.prototype.onMouseOver=function(){if(this.inOver){return}this.inOver=true;this.setImage(this.overImage);this.showToolTip()};CustomMarker.prototype.onMouseOut=function(){if(!this.infoWindow){this.setImage(this.normalImage);this.hideToolTip();this.inOver=false}};CustomMarker.prototype.onClick=function(){this.showInfoWindow()};CustomMarker.prototype.showInfoWindow=function(){closeMapItem();this.hideToolTip();if(!this.infoWindow){this.infoWindow=new CustomInfoWindow(this.getLatLng(),$("#divPreview_"+this.aviso.idVisibilidad)[0],this.parameters.TopCorrection,this.parameters.RightCorrection)}this.map.addOverlay(this.infoWindow);currentMarker=this};CustomMarker.prototype.closeInfoWindow=function(){if(this.infoWindow){this.map.removeOverlay(this.infoWindow);this.infoWindow=null;currentMarker=null;this.onMouseOut()}};CustomMarker.prototype.showToolTip=function(){var c=$("#toolTipTemplate").clone();this.toolTip=c[0];var b=Math.ceil(this.parameters.IconWidth*this.offsetFactor);var d=Math.ceil(this.parameters.IconHeight*this.offsetFactor)*-1;var a=this.map.fromLatLngToDivPixel(this.getLatLng());c.css({left:a.x-c.width()+b,top:a.y-c.height()+d});c.children(".text").text(this.aviso.tipoPropiedad+" en "+this.aviso.tipoOperacion);if(this.aviso.ambientes){c.children(".text").append("<br />").append(this.aviso.ambientes).append(this.aviso.ambientes>1?" ambientes":" ambiente")}c.children(".precio").text(this.aviso.precio);this.map.getPane(G_MAP_FLOAT_PANE).appendChild(this.toolTip);c.show();this.map.ensureElementVisibility(this.toolTip)};CustomMarker.prototype.hideToolTip=function(){if(this.toolTip){this.map.getPane(G_MAP_FLOAT_PANE).removeChild(this.toolTip);this.toolTip=null}};CustomMarker.prototype.getZIndex=function(){return this.aviso.tipoDestaque};function getZIndex(a){return a.aviso.tipoDestaque}var currentMarker=null;GMap2.prototype.ensureElementVisibility=function(d){var b=$(d);var a=b.position();var f=this.getBounds();var c=this.fromLatLngToDivPixel(f.getSouthWest());var e=this.fromLatLngToDivPixel(f.getNorthEast());var h=0;var g=0;if(c.x>a.left){h=c.x-a.left}if(a.left+b.outerWidth(true)>e.x){h=e.x-(a.left+b.outerWidth(true))}if(e.y>a.top){g=e.y-a.top}if(a.top+b.outerHeight(true)>c.y){g=c.y-(a.top+b.outerHeight(true))}if(h!=0||g!=0){this.panBy(new GSize(h,g))}};function closeMapItem(){if(currentMarker!=null){currentMarker.closeInfoWindow()}};
