function Pag(current,total,lNum){var T=this;T.setContainer=function(c){T.c=c};T.onPageClick=function(p){alert(p)};T.exec=function(){var lo,l2,l=current-Math.floor(lNum/2);if(l<1){l=1}T.c.innerHTML="";for(var i=l>1?0:1;i<=lNum;i++,l++){if(i==0){l2=1;l--}else{l2=l}lo=document.createElement("a");if(l2==current){lo.className="current"}else{eval("lo.onclick=function(){T.onPageClick("+l2+")}")}lo.innerHTML=l2;lo.href="javascript:void(0)";T.c.appendChild(lo);if(i==0){T.c.innerHTML+=" ..."}if(l2>=total){break}}}}var map={currentUrl:document.location.href,dataCache:{},history:[],setData:function(a){this.data=a;if(!this._init){this.zoomLimits={maxIn:2,maxOut:2};this.clouds={};this.sf=getObjId("ffIndexSearch");this._init=true}this._setPager();this.lastGo=-1;this.resPage=1;if(!a.totalCounter||a.totalCounter==0||!a.currentCounter||a.currentCounter==0){getObjId("listContainer").innerHTML='<li class="noOffer"><span>Brak ogłoszeń spełniających kryteria wyszukiwania</span></li>';hideObj("listContainerMask");return true}this._fillContainer();return true},_setPager:function(){var b=this.data;if(!b.totalPages||b.totalPages<=1){hideObj("pagContainer");return}showObj("pagContainer");var a=new Pag(b.currentPage,b.totalPages,5);a.setContainer(getObjId("pagContainer"));a.onPageClick=function(c){map.resPage=c;buildAdvSearch(map.sf,DOMAIN)};a.exec()},_fillContainer:function(){this.list={container:getObjId("listContainer")};var tmp=getObjId("list_"+this.data.mapLevel.levelAlias);getObjId("selectList").innerHTML=this.data.mapLevel.levelName;var newRow,elements,el,data;this.list.container.innerHTML="";for(var i=0;i<this.data.list.length;i++){data=this.data.list[i];newRow=tmp.cloneNode(true);newRow.removeAttribute("id");elements=newRow.getElementsByTagName("*");for(var j=0;j<elements.length;j++){el=elements[j];el.removeAttribute("id");switch(el.className){case"iNumIco":el.src=STATIC_SERVER+"/gfx/map/ico_"+(i+1)+".png";el.alt="";break;case"number":el.innerHTML=i+1;break;case"aGo":el.href="javascript:void(0)";break;default:if(el.className&&el.className!=""&&data[el.className]){el.innerHTML=data[el.className]}break}}if((i&1)){newRow.className="grey"}eval("newRow.onclick = function(){map.go("+i+")}");this.list.container.appendChild(newRow)}},_setCenter:function(){var n=this.zoomByAcc(this.data.accuracy),j;if(this.data.centerPoint){this.center={lat:this.data.centerPoint.lat,lng:this.data.centerPoint.lng};this.map.setCenter(new GLatLng(this.center.lat,this.center.lng),n)}else{var o,a,l=[],h=new GLatLngBounds;if(this.data.list.length==0){return}for(var e=0;e<this.data.list.length;e++){o=this.data.list[e];l[e]={lat:o.lat,lng:o.lng,id:e};h.extend(new GLatLng(o.lat,o.lng))}j=this.map.getBoundsZoomLevel(h);a=h.getCenter();if(j>n){n=Math.min(n+this.zoomLimits.maxIn,j)}else{if(j+this.zoomLimits.maxOut>=n){n=j}else{var m,f,k,c=0,d=0;while(j+this.zoomLimits.maxOut<n){for(var g=0;g<=1;g++){if(g==0){l.sort(function(p,i){return p.lat-i.lat});c=0}else{l.sort(function(p,i){return p.lng-i.lng});d=0}m=k=0;for(var e=0;e<l.length;e++){k=(e==0||e==l.length-1)?0.01:1;m+=k;if(g==0){c+=l[e].lat*k}else{d+=l[e].lng*k}}}a=new GLatLng(c/m,d/m);l.sort(function(p,i){return(new GLatLng(p.lat,p.lng)).distanceFrom(a)-(new GLatLng(i.lat,i.lng)).distanceFrom(a)});delete h;h=new GLatLngBounds;l.pop();for(var e=0;e<l.length;e++){h.extend(new GLatLng(l[e].lat,l[e].lng))}a=h.getCenter();j=this.map.getBoundsZoomLevel(h)}n=j}}this.map.setCenter(a,n)}},_addMarkers:function(){var b;for(var a=0;a<this.data.list.length;a++){b=this.data.list[a];this._addMarker(a)}},go:function(a){if(this.list.active){this.list.active.className=this.list.active.className.replace(/\s*active/,"")}if(this.lastGo==a){this.map.closeInfoWindow();this.map.returnToSavedPosition();this.lastGo=-1;return}this.lastGo=a;var h="cloud_"+this.data.mapLevel.levelAlias;if(!this.clouds[h]){this.clouds[h]=getObjId(h)}this.cloud=this.clouds[h];var e,g,f=this.cloud.getElementsByTagName("*");for(var d=0;d<f.length;d++){e=f[d];g=this.data.list[a];switch(e.className){case"aGoNew":e.href="javascript:void(0)";e.onclick=function(){map.goNew(a)};break;case"adURL":e.href=g[e.className];e.target="_blank";break;case"listPhoto":e.src=g.lImg.src;e.title=g.adTitle;break;default:if(g[e.className]){e.innerHTML=g[e.className]}break}}this.list.container=getObjId("listContainer");this.list.active=this.list.container.childNodes[a];this.list.active.className+=" active";if(this.data.mapLevel.levelAlias=="offer"&&false){h="cloud_description";if(!this.clouds[h]){this.clouds[h]=getObjId(h)}this.cloudDesc=this.clouds[h];f=this.cloudDesc.getElementsByTagName("*");for(var d=0;d<f.length;d++){e=f[d];g=this.data.list[a];switch(e.className){case"adURL":e.href=g[e.className];e.target="_blank";break;default:if(g[e.className]){e.innerHTML=g[e.className]}break}}this.data.list[a].m.openInfoWindowTabs([new GInfoWindowTab("oferta",this.cloud)])}else{if(this.data.mapLevel.levelAlias=="offer"){var b=this.data.list[a].m.getLatLng();map.map.setCenter(new GLatLng(b.lat()+0.0015,b.lng()),15)}this.data.list[a].m.openInfoWindowTabs([new GInfoWindowTab("Oferta",this.cloud)])}},goNew:function(a){switch(this.data.mapLevel.levelAlias){case"region":this.sf.regionAlias.value=this.data.list[a].regionAlias;buildAdvSearch(this.sf,DOMAIN);break;case"city":this.sf.cityName.value=this.data.list[a].cityName;buildAdvSearch(this.sf,DOMAIN,"l="+this.data.list[a].cityDuplicateAlias);break;case"specifyCity":this.sf.regionAlias.value=this.data.list[a].regionAlias;this.sf.cityName.value=this.data.list[a].cityName;buildAdvSearch(this.sf,DOMAIN,"l="+this.data.list[a].cityDuplicateAlias);break;case"":break}},_addMarker:function(a){var b=this.data.list[a];ico=new GIcon();ico.shadow=STATIC_SERVER+"/gfx/map/icoShadow.png";ico.image=STATIC_SERVER+"/gfx/map/ico_"+(a+1)+".png";ico.iconSize=new GSize(22,33);ico.iconAnchor=new GPoint(10,33);ico.shadowSize=new GSize(37,34);ico.infoShadowAnchor=new GPoint(18,25);ico.infoWindowAnchor=new GPoint(9,13);b.m=new GMarker(new GLatLng(b.lat,b.lng),{icon:ico});b.lImg=new Image();b.lImg.src=b.listPhoto||this.data.dict.noPhoto;this.map.addOverlay(b.m);GEvent.addListener(b.m,"click",function(){map.go(a)})},initMap:function(){google.load("maps","2",{callback:map.gLoaded})},gLoaded:function(){if(!map.gMapLoaded){map.map=new google.maps.Map2(document.getElementById("map"));map.map.addControl(new GSmallMapControl());map.gMapLoaded=true}else{map.map.clearOverlays()}map.map.enableContinuousZoom();map._setCenter();map._addMarkers();map.map.savePosition();hideObj("listContainerMask");setTimeout(function(){hideObj("mapContainerMask")},1000)},zoomByAcc:function(b){var c={9:15,8:15,7:15,6:14,5:13,4:12,3:12,2:9,1:6};return c[b]||12},loadPage:function(c,d){if(!d){c=c.replace(/&p=[0-9]+/,"")+(this.resPage<=1?"":"&p="+this.resPage)}getObjId("mapUrl").innerHTML=getObjId("mapUrl").href=c;if(this.dataCache[c]){if(!d){this.history.push(map.currentUrl);showObj("backButton");this.currentUrl=c}if(this.setData(this.dataCache[c])){this.gLoaded()}return}if(self.location.host!="www."+DOMAIN){self.location.href=c}var b=new AJAX(encodeURI(c));b.setPostVar("ajaxRequest","");showObj("listContainerMask");showObj("mapContainerMask");b.onRequestComplete(function(a){var e=AJAX.http2obj(a);map.dataCache[c]=e;if(!d){map.history.push(map.currentUrl);showObj("backButton");map.currentUrl=c}if(map.setData(e)){map.gLoaded()}});b.execute()},prev:function(){var a=this.history.pop();if(a){if(this.history.length==0){hideObj("backButton")}this.loadPage(a,true)}else{hideObj("backButton")}}};
