var googleMapsApiInitialized=false;var searchMap=Class.create();searchMap.prototype={map:null,mapID:"searchMap",markers:new Array(),searchForm:null,delaySearchTimeout:null,showAddressTimeout:null,searchDisabled:false,searchEnabled:true,mapMoved:false,mapNavigation:false,addressInput:null,exactMarkerImage:"/images/2012012701/pl_PL/0/tmpMarkerGreen.png",unexactMarkerImage:"/images/2012012701/pl_PL/0/tmpMarkerGray.png",exactMultiMarkerImage:"/images/2012012701/pl_PL/0/tmpMarkerGreen.png",unexactMultiMarkerImage:"/images/2012012701/pl_PL/0/tmpMarkerGray.png",dataUrl:"?mod=maps&act=search",initialize:function(a){this.searchForm=a},load:function(){if(GBrowserIsCompatible()&&this.map==null){this.map=new GMap2(document.getElementById(this.mapID));this.map.getPane(G_MAP_FLOAT_SHADOW_PANE).style.display="none";this.loadControls();this.map.enableScrollWheelZoom();new GKeyboardHandler(this.map)}},loadControls:function(){this.map.addControl(new GMapTypeControl(1));this.map.addControl(new GLargeMapControl());_mPreferMetric=true;this.map.addControl(new GScaleControl(100));this.map.addControl(new GOverviewMapControl(new GSize(180,120)))},show:function(c,a,b){this.load();this.map.setCenter(new GLatLng(c,a));this.map.setZoom(b);GEvent.addListener(this.map,"zoomend",function(){this.closeInfoWindow();if(this.searchDisbled){this.searchDisbled=false}this.clearInfoMarkers();setTimeout(function(){this.delaySearch(500)}.bind(this),1);this.mapNavigation=true}.bind(this));GEvent.addListener(this.map,"moveend",function(){if(!this.searchDisabled){this.delaySearch()}else{this.mapMoved=true}this.mapNavigation=true}.bind(this));GEvent.addListener(this.map,"movestart",function(){clearTimeout(this.delaySearchTimeout);this.mapNavigation=true}.bind(this));GEvent.addListener(this.map,"drag",function(){this.closeInfoWindow();this.mapNavigation=true}.bind(this));this.search()},delaySearch:function(a){if(!this.isInteger(a)){a=1000}clearTimeout(this.delaySearchTimeout);this.delaySearchTimeout=setTimeout(this.search.bind(this),a)},isInteger:function(a){if(a){return parseInt(a,10)===a}return false},search:function(){clearTimeout(this.delaySearchTimeout);var a=document.getElementById("statusbar");a.style.display="block";new Ajax.Request(this.dataUrl,{asynchronous:true,method:"get",parameters:Form.serialize(this.searchForm)+this.getBounds(),onSuccess:function(e){this.clearInfoMarkers();if(e.responseJSON.markers.length==1&&this.map.getZoom()<7&&!this.mapNavigation){b=e.responseJSON.markers[0];this.map.setCenter(new GLatLng(b.lat,b.lng));this.map.setZoom(11);this.mapNavigation=false}else{var b;var d;for(var c=0;c<e.responseJSON.markers.length;c++){b=e.responseJSON.markers[c];b.id=b.id+"";this.addInfoMarker(b,e.responseJSON.mode,e.responseJSON.notExact)}}this.mapNavigation=false}.bind(this),onComplete:function(){var b=document.getElementById("statusbar");b.style.display="none"}})},delayShowAddress:function(){delay=1000;clearTimeout(this.showAddressTimeout);this.showAddressTimeout=setTimeout(this.showAddress.bind(this),delay)},showAddress:function(){if(!$(this.addressInput)){return}var a=$(this.addressInput).value;var b=new GClientGeocoder();if(b){b.getLocations(a,function(c){if(c.Status.code==200){coordinates=c.Placemark[0].Point.coordinates;point=new GLatLng(coordinates[1],coordinates[0]);accuracy=c.Placemark[0].AddressDetails.Accuracy;a=c.Placemark[0].address;if(accuracy==8){zoom=16}else{if(accuracy>=6){zoom=14}else{if(accuracy>=4){zoom=11}}}this.map.setCenter(point,zoom)}}.bind(this))}},getBounds:function(){var a=this.map.getBounds();var b="&latFrom="+a.getSouthWest().lat()+"&lngFrom="+a.getSouthWest().lng()+"&latTo="+a.getNorthEast().lat()+"&lngTo="+a.getNorthEast().lng();return b},prepareInfo:function(c,a,b){},addInfoMarker:function(place,mode,notExact){if(this.markers[place.id]){return false}info=this.prepareInfo(mode,place,notExact);lng=place.lng;lat=place.lat;var otxMarker=new GIcon();if(info.multi&&place.exact){otxMarker.image=this.exactMultiMarkerImage}else{if(info.multi&&!place.exact){otxMarker.image=this.unexactMultiMarkerImage}else{if(!info.multi&&place.exact){otxMarker.image=this.exactMarkerImage}else{otxMarker.image=this.unexactMarkerImage}}}otxMarker.shadow="/images/2012012701/pl_PL/0/tmpMarkerShadow.png";otxMarker.iconSize=new GSize(35,46);otxMarker.shadowSize=new GSize(51,19);otxMarker.iconAnchor=new GPoint(17,46);otxMarker.infoWindowAnchor=new GPoint(13,3);var marker=new GMarker(new GLatLng(lat,lng),{icon:otxMarker});this.markers[place.id]={marker:marker,info:info};this.map.addOverlay(marker);GEvent.addListener(marker,"mouseover",function(){this.searchEnabled=false;this.openInfoWindow(place.id)}.bind(this,marker));GEvent.addListener(marker,"mouseout",function(){this.searchEnabled=true;this.closeInfoWindow(place.id)}.bind(this,marker));GEvent.addListener(marker,"infowindowopen",function(){this.searchDisabled=true;this.infoWindowVisible=true}.bind(this));GEvent.addListener(marker,"infowindowclose",function(){this.infoWindowMarker=null;this.searchDisabled=false;this.infoWindowVisible=false;if(this.mapMoved&&!this.searchDisabled&&this.searchEnabled){this.search();this.mapMoved=false}}.bind(this));GEvent.addListener(marker,"click",function(){this.closeInfoWindow(place.id);if(this.map.getZoom()<10){this.map.setZoom(10)}else{this.map.setZoom(this.map.getZoom()+1)}}.bind(this));GEvent.addListener(marker,"dblclick",function(){this.closeInfoWindow(place.id);if(this.markers[place.id]){if(this.markers[place.id].info.toEval){eval(this.markers[place.id].info.toEval)}else{window.open(this.markers[place.id].info.link,"_blank")}}}.bind(this))},infoWindowMarker:null,infoWindowTimeout:null,infoWindowVisible:false,openInfoWindow:function(b,a){if(this.infoWindowMarker!=b||!this.infoWindowVisible){this.closeInfoWindow();this.infoWindowMarker=b;if(!a){a=500}this.infoWindowTimeout=setTimeout(function(){if(this.markers[this.infoWindowMarker]){this.markers[this.infoWindowMarker].marker.openInfoWindow(this.markers[this.infoWindowMarker].info.div)}clearTimeout(this.infoWindowTimeout)}.bind(this),a)}},closeInfoWindow:function(a){clearTimeout(this.infoWindowTimeout);if(this.infoWindowMarker&&(!a||a!=this.infoWindowMarker)&&this.markers[this.infoWindowMarker]){this.markers[this.infoWindowMarker].marker.closeInfoWindow();this.infoWindowMarker=null}},clearInfoMarkers:function(){this.map.clearOverlays();this.markers=new Array()},showResults:function(c,a,d){this.setFormValue("objSearchQuery_City_ID",d?d:0);this.setFormValue("objSearchInvestment_City_ID",d?d:0);var b=this.map.getBounds();this.setFormValue("objSearchQuery_LatFrom",c?c:b.getSouthWest().lat());this.setFormValue("objSearchQuery_LatTo",c?c:b.getNorthEast().lat());this.setFormValue("objSearchQuery_LngFrom",a?a:b.getSouthWest().lng());this.setFormValue("objSearchQuery_LngTo",a?a:b.getNorthEast().lng());this.setFormValue("objSearchInvestment_LatFrom",c?c:b.getSouthWest().lat());this.setFormValue("objSearchInvestment_LatTo",c?c:b.getNorthEast().lat());this.setFormValue("objSearchInvestment_LngFrom",a?a:b.getSouthWest().lng());this.setFormValue("objSearchInvestment_LngTo",a?a:b.getNorthEast().lng());this.setFormValue("searchMapSubmit","true");this.searchForm.submit()},setFormValue:function(b,a){if($(b)){$(b).value=a}else{this.searchForm.appendChild(new Element("input",{id:b,name:b,type:"hidden",value:a}))}},showLocalization:function(a){$("objSearchInvestment_Address").value=a;this.showAddress()}};
