function findImagesArray(marker){for(var i in marker){if(eval("typeof marker."+i)=="object"){try{if(eval("typeof marker."+i+"[0].src")!="undefined"){return i}}catch(e){}}}return""}function processZIndex(c,a){if(c.zindex){return c.zindex}else{return GOverlay.getZIndex(c.getPoint().lat())}}function GxMarkerNamespace(){var d=(document.layers);var a=(document.getElementById&&!document.all);var h=false;var g=(document.all&&!window.opera);window.likesDXFilters=h;window.ie=g;var c=(navigator.appName.indexOf("Opera")!=-1);var f=(navigator.userAgent.indexOf("Safari")!=-1);function e(i,l,k,o,n,j){this.inheritFrom=GMarker;this.inheritFrom(i,{icon:l,zIndexProcess:processZIndex});if(typeof k!="undefined"){this.setTooltip(k)}if(!n){this.target="_blank"}else{this.target=n}this.clickURL=o;this.imagesArray="";this.oldImagePath="";if(j){this.hoverIcon=j}this.events=new Array()}e.prototype=new GMarker(new GLatLng(1,1));e.prototype.setTooltip=function(i){this.tooltip=new Object();this.tooltip.contents=i};e.prototype.showHighlight=function(){if(!this.hoverIcon){return}if(this.imagesArray.length==0){this.imagesArray=findImagesArray(this)}if(this.imagesArray.length!=""){if(this.oldImagePath.length==0){this.oldImagePath=this[this.imagesArray][0].src}if(g&&h){this[this.imagesArray][0].style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+this.hoverIcon.image+'")'}else{this[this.imagesArray][0].src=this.hoverIcon.image}this[this.imagesArray][0].style.zIndex=4999;this.redraw(true)}};e.prototype.removeHighlight=function(){if(!this.hoverIcon){return}if(this.imagesArray.length==0){this.imagesArray=findImagesArray(this)}if(this.imagesArray.length>0){if(g&&h){this[this.imagesArray][0].style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+this.oldImagePath+'")'}else{this[this.imagesArray][0].src=this.oldImagePath}this.oldImagePath="";this[this.imagesArray][0].style.zIndex=4997;this.redraw(true)}};e.prototype.initialize=function(i){try{GMarker.prototype.initialize.call(this,i);this.events.unshift(GEvent.bind(this,"mouseover",this,this.onMouseOver));this.events.unshift(GEvent.bind(this,"mouseout",this,this.onMouseOut));this.events.unshift(GEvent.bind(this,"click",this,this.onClick));this.map=i}catch(j){console.error(j)}};e.prototype.remove=function(i){GMarker.prototype.remove.call(this);if(this.tooltipObject){document.body.removeChild(this.tooltipObject)}this.removeEvents();this.map=null};e.prototype.onInfoWindowOpen=function(){this.hideMouseOver();GMarker.prototype.onInfoWindowOpen.call(this)};e.prototype.onClick=function(){if(this.clickURL){window.open(this.clickURL,this.target)}};e.prototype.onMouseOver=function(){if(this.timeout){clearTimeout(this.timeout)}this.showMouseOver()};e.prototype.onMouseOut=function(){var i=this;this.timeout=setTimeout(function(){i.hideMouseOver()},100)};e.prototype.showMouseOver=function(){var p=this.map.getBounds();if(this.tooltip){if(typeof this.tooltipObject=="undefined"){this.tooltipObject=document.createElement("div");this.tooltipObject.style.display="none";this.tooltipObject.style.position="absolute";this.tooltipObject.style.padding="0";this.tooltipObject.style.margin="0";this.tooltipObject.style.zIndex=50000;this.tooltipObject.innerHTML='<div class="markerTooltip">'+this.tooltip.contents+"</div>";var k=this;$(this.tooltipObject).hover(function(u){if(k.timeout){clearTimeout(k.timeout)}},function(u){k.hideMouseOver()});document.body.appendChild(this.tooltipObject)}if(p.contains(this.getPoint())){var r=this.map.fromContainerPixelToLatLng(new GPoint(0,0),true);var o=this.map.fromLatLngToDivPixel(r);var l=this.map.fromLatLngToDivPixel(this.getPoint());var q=new GPoint(l.x-o.x,l.y-o.y);var n=findPos(this.map.getContainer());this.tooltipObject.style.left="-1000px";this.tooltipObject.style.top="-1000px";this.tooltipObject.style.display="block";var j=(this.tooltip.contents.indexOf("loc_pin_flag")>=0)?true:false;var i=q.x-this.getIcon().iconAnchor.x+n[0];if(j){i-=((this.getIcon().iconSize.width/2)-6)}else{if(i>(document.body.offsetWidth/2)){i-=this.tooltipObject.offsetWidth}else{i+=this.getIcon().iconSize.width}}this.tooltipObject.style.left=i+"px";var t=q.y-this.getIcon().iconAnchor.y+n[1];if(j){t-=((this.getIcon().iconSize.height*2)+1)}else{if((q.y+this.map.getContainer().offsetTop)>(this.map.getContainer().offsetHeight/2)){t-=this.tooltipObject.offsetHeight}else{t+=this.getIcon().iconSize.height}}this.tooltipObject.style.top=t+"px";if(j&&this.locPinTimeout){window.clearTimeout(this.locPinTimeout)}}this.showHighlight()}};e.prototype.hideMouseOver=function(){if(typeof this.tooltipObject!="undefined"){if(this.tooltip.contents.indexOf("loc_pin_flag")>=0){Yelp.tooltipHolder=this.tooltipObject;this.locPinTimeout=window.setTimeout('Yelp.tooltipHolder.style.display = "none";Yelp.tooltipHolder=null;',2000)}else{this.tooltipObject.style.display="none"}}this.removeHighlight()};e.prototype.removeEvents=function(){while(this.events.length>0){GEvent.removeListener(this.events.shift())}};e.prototype.unload=function(){this.removeEvents();this.tooltipObject=null;this.tooltip=null;this.imagesArray="";this.map=null;this.hoverIcon=null};function b(j){var i=j||window;i.GxMarker=e}b()}GxMarkerNamespace();function MarkerLight(b,a){this.latlng=b;this.options={};jQuery.extend(this.options,a)}MarkerLight.prototype=new GOverlay();MarkerLight.prototype.initialize=function(b){var a=this;var c=document.createElement("div");c.style.position="absolute";c.style.cursor="pointer";if(this.options.text){c.innerHTML=this.options.text}if(this.options.title){c.setAttribute("title",this.options.title)}GEvent.addDomListener(c,"click",function(d){GEvent.trigger(a,"click")});b.getPane(G_MAP_MARKER_PANE).appendChild(c);this.map_=b;this.div_=c};MarkerLight.prototype.remove=function(){this.div_.parentNode.removeChild(this.div_)};MarkerLight.prototype.copy=function(){return new MarkerLight(this.latlng,this.options)};MarkerLight.prototype.redraw=function(a){if(!a){return}var b=this.map_.fromLatLngToDivPixel(this.latlng);if(this.options.width){this.div_.style.width=this.options.width_+"px"}if(this.options.height){this.div_.style.height=(this.options.height)+"px"}this.div_.style.left=(b.x)+"px";this.div_.style.top=(b.y)+"px"};MarkerLight.prototype.getZIndex=function(a){return GOverlay.getZIndex(marker.getPoint().lat())-a.clicked*10000};MarkerLight.prototype.getPoint=function(){return this.latlng};MarkerLight.prototype.setStyle=function(a){for(s in a){this.div_.style[s]=a[s]}};MarkerLight.prototype.setImage=function(a){this.div_.style.background='url("'+a+'")'};function loadingControl(){}loadingControl.prototype=new GControl();loadingControl.prototype.initialize=function(b){var a=$('<div class="maploading"><div><img src="/img/loading.gif"> Загрузка ...</div></div>').get(0);b.getContainer().appendChild(a);return a};loadingControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(0,0))};var markerpin=null;var baseIcon=new GIcon(G_DEFAULT_ICON);baseIcon.shadow="/i/map/shadow.png";baseIcon.iconSize=new GSize(27,37);baseIcon.shadowSize=new GSize(29,37);baseIcon.iconAnchor=new GPoint(14,37);baseIcon.infoWindowAnchor=new GPoint(27,7);var MapUtils={createIcon:function(b){var a=new GIcon(baseIcon);if(b){a.image="/i/map/"+b+".png"}else{a.image="/i/map/0.png"}return a},createHoverIcon:function(b){var a=new GIcon(baseIcon);a.image="/i/map/"+b+"h.png";return a},createTooltipMarker:function(e){var a=new GLatLng(e.lat,e.lng);var d,b=null;if(e.selected){d=MapUtils.createIcon(null)}else{d=MapUtils.createIcon(e.id);b=MapUtils.createHoverIcon(e.id)}var c=MapUtils.createPopupHTML(e);clickURL=e.click_url;m=new GxMarker(a,d,c,clickURL,"",b);if(e.zindex){m.zindex=e.zindex}return m},createPopupHTML:function(b){var a="";a+='<div class="gray-photo"><img src="'+b.photo_url+'"></div>';preloadImage(b.photo_url);a+='<div class="info">';a+="<h4>"+b.name+"</h4>";if(b.reviews){a+='<div class="rating"><div class="'+b.ratingclass+'"></div><em>'+b.reviews+" отзывов</em></div>"}if(b.address){a+='<div class="address">'+b.address+"</div>"}if(b.description){a+="<p>"+b.description+"</p>"}a+='<div class="clear"></div></div>';return a}};var AjaxMap=Class.extend({construct:function(h,f){this.options={center_lat:55.74643,center_lng:37.62405,zoom:10,control_large:false,control_small:true,control_type:false,control_scale:false,control_wheel:false,control_loading:true,select_pin:false,overlays:[],onDataLoad:false};this._markers=[];this._polylines=[];this._map=null;this._reload_timer=null;this._markerpin=null;this._onstatechange=false;this._overlays=[];var e=this;jQuery.extend(this.options,f);$("#"+h).show();this._map=new GMap2($("#"+h).get(0));GEvent.bind(this._map,"load",this,this.onMapLoad);GEvent.bind(this._map,"zoomend",this,this.onChangeBounds);GEvent.bind(this._map,"moveend",this,this.onChangeBounds);if(this.options.control_loading){this._map.addControl(new loadingControl())}if(this.options.control_large){this._map.addControl(new GLargeMapControl())}if(this.options.control_small){this._map.addControl(new GSmallMapControl())}if(this.options.control_type){this._map.addControl(new GMapTypeControl())}if(this.options.control_scale){this._map.addControl(new GScaleControl())}if(this.options.control_wheel){this._map.enableScrollWheelZoom()}this._map.setCenter(new GLatLng(this.options.center_lat,this.options.center_lng),this.options.zoom);if(this.options.markers){this.addMarkers(this.options.markers)}if(this.options.polylines){for(var g in this.options.polylines){var d=new GPolyline.fromEncoded({color:"#FF0000",weight:10,points:f.polylines[g].points,levels:f.polylines[g].levels,zoomFactor:2,numLevels:18});this._map.addOverlay(d);this._polylines.push(d)}}if(this.options.select_pin){var b=$("#"+this.options.select_pin).val();if(b){var c=b.match(/\((.+?),(.+?)\)/);this.mapSetPin("#"+this.options.select_pin,new GLatLng(c[1],c[2]))}GEvent.addListener(this._map,"dblclick",function(i,a){if(i){}else{e.mapSetPin("#"+e.options.select_pin,a)}})}},setCenter:function(c,a,b){this._map.setCenter(new GLatLng(c,a),b)},setZoom:function(a){this._map.setZoom(a)},onMapLoad:function(){},onChangeBounds:function(){},reload:function(){if(this._onstatechange){return}var a=this.url();var b=this;if(!a||!this.options.onDataLoad){return}this.onStartLoading();jQuery.ajax({type:"GET",url:a,dataType:"xml",success:function(c){b.onEndLoading();if(b.options.onDataLoad){b.options.onDataLoad(c)}},error:function(c,f,d){b.onEndLoading()}})},onStartLoading:function(){this._onstatechange=true;$(".maploading").show();this.showOverlays()},onEndLoading:function(){this._onstatechange=false;$(".maploading").hide();this.hideOverlays()},url:function(){return null},addMarkers:function(c){for(var a in c){var b=this.createMarker(c[a]);this._map.addOverlay(b);this._markers[c[a].id]=b}},createMarker:function(a){return MapUtils.createTooltipMarker(a)},removeAllMarkers:function(a){for(var b=0;b<this._markers.length;b++){if(Utils.defined(this._markers[b])){this._map.removeOverlay(this._markers[b])}}this._markers=null;this._markers=[]},removeAllPolylines:function(){for(var a=0;a<this._polylines.length;a++){if(Utils.defined(this._polylines[a])){this._map.removeOverlay(this._polylines[a])}}this._polylines=null;this._polylines=[]},markerShowTooltip:function(a){if(a<0||a>this._markers.length){return}if(Utils.defined(this._markers[a].showMouseOver)){this._markers[a].showMouseOver()}},markerHideTooltip:function(a){if(a<0||a>this._markers.length){return}if(Utils.defined(this._markers[a].hideMouseOver)){this._markers[a].hideMouseOver()}},getMap:function(){return this._map},mapSetPin:function(b,a){var c=this;this.mapRemovePin();$(b).val(a.toString());this._markerpin=new GMarker(a,{draggable:true,icon:MapUtils.createIcon(0)});GEvent.addListener(this._markerpin,"dragend",function(){$(b).val(c._markerpin.getPoint().toString())});this._map.addOverlay(this._markerpin)},mapRemovePin:function(){if(this._markerpin){this._map.removeOverlay(this._markerpin);this._markerpin=null;return true}return false},mapIsSetPin:function(){return this._markerpin!=null},showOverlays:function(){for(var b=0;b<this.options.overlays.length;b++){var a=this.options.overlays[b];if(this._overlays[a]){this.removeOverlay(a)}this.addOverlay(a)}},hideOverlays:function(){for(var b=0;b<this.options.overlays.length;b++){var a=this.options.overlays[b];if(this._overlays[a]){this.removeOverlay(a)}}},addOverlay:function(b){var c=$(b).width();var a=$(b).height();this._overlays[b]=$('<div><img src="/img/loading.gif"></div>').appendTo(b).css({borderWidth:0,margin:0,padding:0,position:"absolute",top:0,left:0,width:c,height:a,background:"#fff",opacity:0.4,zIndex:100})},removeOverlay:function(a){if(this._overlays[a]){$(this._overlays[a]).remove();this._overlays[a]=null}}});var ViewPlaceMap=AjaxMap.extend({construct:function(b,a){this.construct.$.construct.call(this,b,jQuery.extend(a,{onDataLoad:$R(this,"draw"),overlays:["#vpother"]}));this.options.markers=[this.options.markers[0]];$("#mapreload span").bind("click",{self:this},this._onMapReloadClick)},url:function(){var c=this._map.getBounds();var d=c.getSouthWest().toUrlValue()+","+c.getNorthEast().toUrlValue();var a=this._map.getCenter().toUrlValue();var e="/ajax/mapplaces/?type=viewplace&id="+this.options.placeid+"&center="+a+"&zoom="+this._map.getZoom()+"&bounds="+d;return e},draw:function(data){$("#vpother").html($(data).find("htmlbody").text());var map_options=null;try{eval($(data).find("code").text())}catch(e){alert(e)}this.removeAllMarkers();this.removeAllPolylines();if(this.options.markers){this.addMarkers(this.options.markers)}if(map_options){if(map_options.center_lat){this.setCenter(map_options.center_lat,map_options.center_lng,map_options.zoom)}var points=[];if(map_options.markers){this.addMarkers(map_options.markers)}if(map_options.polylines){for(var p in map_options.polylines){var encodedPolyline=new GPolyline.fromEncoded({color:"#FF0000",weight:10,points:map_options.polylines[p].points,levels:map_options.polylines[p].levels,zoomFactor:2,numLevels:18});this._map.addOverlay(encodedPolyline);this._polylines.push(encodedPolyline)}}}},_onMapReloadClick:function(b){var a=b.data.self;a.reload()}});Sosedi.MapApp=Class.extend({construct:function(a){this.options={};jQuery.extend(this.options,a);this._map=new BigMap("map",{control_large:true,control_small:false,control_type:true,control_wheel:true,control_scale:true,control_loading:false,center_lat:55.74643,center_lng:37.62405,zoom:10})}});var BigMap=AjaxMap.extend({construct:function(b,a){this.construct.$.construct.call(this,b,jQuery.extend(a,{onDataLoad:$R(this,"draw")}));this._reloadTimer=null;this._imageWindow=null;this._map.addControl(new BigMap_loadingControl())},url:function(){var c=this._map.getBounds();var d=c.getSouthWest().toUrlValue()+","+c.getNorthEast().toUrlValue();var a=this._map.getCenter().toUrlValue();var e="/ajax/bigmap/?type=image&center="+a+"&bounds="+d+"&zoom="+this._map.getZoom();return e},draw:function(data){var map_options=null;try{eval($(data).find("code").text())}catch(e){alert(e)}this.removeAllMarkers();this.removeAllPolylines();if(map_options){var points=[];if(map_options.markers){this.addMarkers(map_options.markers)}if(map_options.polylines){for(var p in map_options.polylines){var encodedPolyline=new GPolyline.fromEncoded({color:"#FF0000",weight:10,points:map_options.polylines[p].points,levels:map_options.polylines[p].levels,zoomFactor:2,numLevels:18});this._map.addOverlay(encodedPolyline);this._polylines.push(encodedPolyline)}}}},onChangeBounds:function(){var a=this;this.onChangeBounds.$.onChangeBounds.call(this);if(a._reloadTimer){clearTimeout(a._reloadTimer);a._reloadTimer=null}this._reloadTimer=setTimeout(function(){a.reload()},1500)},onStartLoading:function(){this.onStartLoading.$.onStartLoading.call(this);$("#loadingCtrl").show()},onEndLoading:function(){this.onEndLoading.$.onEndLoading.call(this);$("#loadingCtrl").hide()},createMarker:function(b){var c=this;var d='<div><img src="'+b.photo_url+'"></div>';var a=new MarkerLight(new GLatLng(b.lat,b.lng),{title:b.name,text:d});GEvent.addListener(a,"click",function(){c._showBigImage(b)});return a},_showBigImage:function(a){var c=this;if(!this._imageWindow){this._imageWindow=new autoPop({modal:true})}this._imageWindow.setContent('<div style="padding: 5px; text-align: center"><img src="/i/loading.gif" alt="Загружаем фото" style="vertical-align: middle"> Загружаем фото ...</div>');this._imageWindow.display({anchor:"center"});var b=new Image();$(b).load(function(){c._imageWindow.destroy();c._imageWindow=new autoPop({modal:true,width:b.width+14});c._imageWindow.setContent('<div style="padding: 5px 5px 0 5px;"><a href="'+a.click_url+'" target="_blank"><img src="'+b.src+'"></a></div>');c._imageWindow.display({anchor:"center"})});b.src=a.photobig_url}});function BigMap_loadingControl(){}BigMap_loadingControl.prototype=new GControl();BigMap_loadingControl.prototype.initialize=function(b){var a=$('<div id="loadingCtrl"><img src="/i/loading.gif"> Загружаем объекты ...</div>').get(0);b.getContainer().appendChild(a);return a};BigMap_loadingControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(80,0))};