if(typeof P4=="undefined"||!P4){var P4={}
}if(typeof P4.maps=="undefined"||!P4.maps){P4.maps={}
}if(typeof P4.created=="undefined"||!P4.created){P4.created={};
P4.created.shops=0
}P4.maps.focusLatLng=function(F,C,G){var E,D,B,A;
E=13;
D=new GIcon(G_DEFAULT_ICON);
D.image=P4.maps.i18n.resourceLocation+"/_img/new_content/kropka.png";
D.shadow="";
D.iconSize=new GSize(15,15);
D.iconAnchor=new GPoint(7,7);
B=new GMarker(new GLatLng(F,C),{icon:D,title:G});
if(this.lastAddedMarker!==null){this.map.removeOverlay(this.lastAddedMarker)
}this.map.addOverlay(B);
this.lastAddedMarker=B;
A=function(){var H='<span style="font-size: 14px"><strong>'+P4.maps.i18n.adres+":</strong></span><br/><br/>"+G;
B.openInfoWindowHtml(H)
};
A();
GEvent.addListener(B,"click",A);
this.map.setCenter(new GLatLng(F,C),E)
};
P4.maps.start=function(){$("#query").autocomplete("url",{minChars:3})
};
P4.maps.submitSearch=function(){$("#searchForm").submit()
};
P4.maps.searchAddress=function(A){A=A+" pl";
this.geocoder.getLocations(A,function(F){var B,E,D,C,G;
if(F.Status.code==G_GEO_SUCCESS){D=P4.maps.filterResults(F.Placemark);
if(D.length>0){B=["<ul>"];
for(C=0;
C<D.length;
C++){E=D[C].Point.coordinates;
B.push('<li class="title"><a href="#" style="font-size:10px" onclick="P4.maps.focusLatLng(');
B.push(parseFloat(E[1]));
B.push(",");
B.push(parseFloat(E[0]));
B.push(",'");
G=P4.maps.getDisplayAddress(D[C]);
B.push(G);
B.push("'); return false;");
B.push('">');
B.push(G);
B.push("</a></li>")
}B.push("</ul>");
$("#searchResults").html(B.join(""));
E=D[0].Point.coordinates;
P4.maps.focusLatLng(E[1],E[0],P4.maps.getDisplayAddress(D[0]))
}else{$("#searchResults").html('<span class="no_result">'+P4.maps.i18n.brakRezultatow+"</span>")
}}else{$("#searchResults").html('<span class="no_result">'+P4.maps.i18n.brakRezultatow+"</span>")
}})
};
P4.maps.getDisplayAddress=function(B){var C,A;
A="";
if(B.AddressDetails!==undefined&&B.AddressDetails.Country!==undefined){C=B.AddressDetails.Country;
if(C.AdministrativeArea!==undefined&&C.AdministrativeArea.SubAdministrativeArea!==undefined){if(C.AdministrativeArea.SubAdministrativeArea.Locality!==undefined&&C.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare!==undefined&&C.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName!==undefined){A+=C.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName
}if(C.AdministrativeArea.SubAdministrativeArea.Locality!==undefined&&C.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName!==undefined){if(A){A+=", "
}A+=C.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName
}}if(C.AdministrativeArea!==undefined&&C.AdministrativeArea.AdministrativeAreaName!==undefined){if(A){A+=", "
}A+=C.AdministrativeArea.AdministrativeAreaName
}if(A){return A
}else{return B.address
}}else{return B.address
}};
P4.maps.filterResults=function(C){var A,B;
A=[];
for(B=0;
B<C.length;
B++){if(C[B]===undefined||C[B].Point===undefined||C[B].Point.coordinates===undefined){continue
}if(C[B].AddressDetails===undefined||C[B].AddressDetails.Country===undefined){continue
}if(C[B].AddressDetails.Country.CountryNameCode=="PL"){A[A.length]=C[B]
}}return A
};
P4.maps.createP4Marker=function(F,H,G,C,E,A){var D,B;
D=new GIcon(G_DEFAULT_ICON);
D.image=E;
D.shadow="";
D.iconSize=new GSize(12,20);
D.iconAnchor=new GPoint(6,20);
B=new GMarker(new GLatLng(F,H),{icon:D,title:G});
GEvent.addListener(B,"click",function(){B.openInfoWindowHtml(C)
});
if(A){GEvent.addListener(B,"infowindowopen",function(){P4.maps.highlightShop(A);
P4.maps.addedShops[A].windowOpened=true
});
GEvent.addListener(B,"infowindowclose",function(){P4.maps.unhighlightShop(A);
P4.maps.addedShops[A].windowOpened=false
})
}return B
};
P4.maps.createShops=function(){var G,D,I,F,H,B,C,A,E;
I=P4.maps.shops;
C=[];
A=[];
for(G=0;
G<I.length;
G+=1){F=I[G];
H="";
if(F.full_name!==""){H+='<span style="font-size: 14px"><strong>'+F.full_name+"</strong></span><br/><br/>";
B=F.full_name
}else{B=F.shops[0].name
}for(D=0;
D<F.shops.length;
D+=1){H+='<span style="font-size: 12px"><strong>'+F.shops[D].name+"</strong></span><br/>";
H+=F.shops[D].opened+"<br/>tel: "+F.shops[D].phone+"<br/><i>"+F.shops[D].items+"</i><br/><br/>"
}H+='<span style="font-size: 11px">'+F.address+"<br/>"+F.code+" "+F.town+"</span>";
if(F.playonline==="true"){E=this.createP4Marker(F.lat,F.lng,B,H,P4.maps.i18n.resourceLocation+"/_img/new_maps/mm_20_purple.png",G);
C.push(E)
}else{E=this.createP4Marker(F.lat,F.lng,B,H,P4.maps.i18n.resourceLocation+"/_img/new_maps/mm_20_white.png",G);
A.push(E)
}P4.maps.addedShops[G]=E
}iconOnline=new GIcon(G_DEFAULT_ICON);
iconOnline.image=P4.maps.i18n.resourceLocation+"/_img/new_maps/marker_purple.png";
iconOnline.shadow="";
iconOnline.iconSize=new GSize(20,34);
iconOnline.iconAnchor=new GPoint(10,34);
P4.maps.clusterOnline=new ClusterMarker(this.map,{markers:C,clusterMarkerIcon:iconOnline,intersectPadding:5,clusterMarkerTitle:P4.maps.i18n.clusterMarkerTitle});
P4.maps.clusterOnline.refresh();
iconOthers=new GIcon(G_DEFAULT_ICON);
iconOthers.image=P4.maps.i18n.resourceLocation+"/_img/new_maps/marker_white.png";
iconOthers.shadow="";
iconOthers.iconSize=new GSize(20,34);
iconOthers.iconAnchor=new GPoint(10,34);
P4.maps.clusterOthers=new ClusterMarker(this.map,{markers:A,clusterMarkerIcon:iconOthers,intersectPadding:5,clusterMarkerTitle:P4.maps.i18n.clusterMarkerTitle});
P4.maps.clusterOthers.refresh()
};
P4.maps.hideShops=function(){P4.maps.clusterOnline.removeMarkers();
P4.maps.clusterOthers.removeMarkers();
P4.maps.updateShopsList()
};
P4.maps.showShops=function(){P4.maps.createShops();
P4.created.shops=1;
P4.maps.updateShopsList()
};
P4.maps.createShopDiv=function(E,F){var C=null;
for(j=0;
j<E.shops.length;
j++){var A='<div class="sklepInfo font11 lokalizacja-'+F+'" id="sklep-'+F+"-"+j+'"><div class="wpSklepInfoIMG"></div><div class="wpSklepInfoText ciemnySzary">';
var B=E.shops[j];
A+='<strong class="fiolet fontBig">'+P4.maps.i18n.placowki+": "+B.name+"</strong><br/>";
if(E.full_name!==""){A+='<strong class="fontMedium">'+E.full_name+"</strong><br/>"
}A+=E.address+"<br/>"+B.phone+"<br/>"+B.opened.split(",").join("<br/>")+'<br/><span class="fiolet">'+P4.maps.i18n.coKupisz+"</span><br/>"+B.items+"<br/>";
A+='</div><div class="cl"></div></div>';
var D=$(A);
D.click(function(){GEvent.trigger(P4.maps.addedShops[F],"click")
});
if(C){C=C.add(D)
}else{C=D
}}return C
};
P4.maps.updateShopsList=function(){var A=0;
var B=0;
$("#shopsList").empty();
if(P4.maps.shopsVisible){if(P4.maps.map.getZoom()>=11){jQuery.each(P4.maps.addedShops,function(C){if(P4.maps.isMarkerVisible(this)){var D=P4.maps.shops[C];
B++;
$("#shopsList").append(P4.maps.createShopDiv(D,C));
if(P4.maps.addedShops[C].windowOpened){P4.maps.highlightShop(C)
}}else{A++
}})
}else{$("#shopsList").append('<div class="zoomNeeded fontBig">'+P4.maps.i18n.musiszPrzyblizyc+"</div>")
}}};
P4.maps.highlightShop=function(A){$(".lokalizacja-"+A).addClass("highlightedShop")
};
P4.maps.unhighlightShop=function(A){$(".lokalizacja-"+A).removeClass("highlightedShop")
};
P4.maps.Controls=function(){};
P4.maps.Controls.prototype=new GControl();
P4.maps.Controls.prototype.refresh=function(){var A,B;
A=this.map.getCurrentMapType();
B=function(C,D){C.className=(A==D)?"active":"inactive"
};
B(this.buttons.normal,G_NORMAL_MAP);
B(this.buttons.satellite,G_SATELLITE_MAP);
B(this.buttons.hybrid,G_HYBRID_MAP)
};
P4.maps.Controls.prototype.initialize=function(D){var A,B,C;
A=document.createElement("div");
A.id="map_controls";
B=function(F){var G,E;
G=document.createElement("div");
for(E in F){G[E]=F[E]
}A.appendChild(G);
return G
};
C=P4.maps.i18n;
this.buttons={homeVoice:B({innerHTML:C.zasiegDomowy,title:C.pokazUkryjZasiegHomeVoice,className:P4.maps.i18n.showHomeVoice==1?"active":"inactive",id:"toggleHomeVoiceOverlay"}),voiceCoverage:B({innerHTML:C.zasiegVoice,title:C.pokazUkryjZasiegVoice,className:P4.maps.i18n.showPlay==1?"active":"inactive",id:"toggleVoiceOverlay"}),coverage:B({innerHTML:C.zasieg,title:C.pokazUkryjZasieg,className:P4.maps.i18n.showPlayOnline==1?"active":"inactive",id:"toggleOverlay"}),shops:B({innerHTML:C.sklepy,title:C.pokazUkryjSklepy,className:P4.maps.i18n.showShops==1?"active":"inactive",id:"toggleShops"})};
D.getContainer().appendChild(A);
this.map=D;
return A
};
P4.maps.Controls.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(5,5))
};
P4.maps.isMarkerVisible=function(A){var B=P4.maps.map.getBounds();
return B.containsLatLng(A.getLatLng())&&!A.isHidden()
};
P4.maps.initialize=function(){this.lastAddedMarker=null;
this.map=new GMap2(document.getElementById("map_area"));
this.map.setCenter(new GLatLng(52,19),6);
this.map.addControl(new GLargeMapControl());
this.map.addControl(new GScaleControl());
this.geocoder=new GClientGeocoder();
var A=new P4.maps.Controls();
this.map.addControl(A);
this.map.setMapType(G_NORMAL_MAP);
this.map.enableScrollWheelZoom();
this.map.enableContinuousZoom();
GEvent.addListener(this.map,"maptypechanged",function(){A.refresh()
});
GEvent.addListener(this.map,"tilesloaded",P4.maps.updateShopsList);
this.feed=new GGeoXml(decodeURIComponent(P4.maps.i18n.zasiegTest));
this.feedVoice=new GGeoXml(decodeURIComponent(P4.maps.i18n.zasiegVoiceTest));
this.feedHomeVoice=new GGeoXml(decodeURIComponent(P4.maps.i18n.zasiegHomeVoice));
if(P4.maps.i18n.showPlay==1){this.addVoiceOverlay()
}if(P4.maps.i18n.showPlayOnline==1){this.addOverlay()
}if(P4.maps.i18n.showHomeVoice==1){this.addHomeVoiceOverlay()
}};
P4.maps.addOverlay=function(){this.map.addOverlay(this.feed)
};
P4.maps.removeOverlay=function(){this.map.removeOverlay(this.feed)
};
P4.maps.addVoiceOverlay=function(){this.map.addOverlay(this.feedVoice)
};
P4.maps.removeVoiceOverlay=function(){this.map.removeOverlay(this.feedVoice)
};
P4.maps.addHomeVoiceOverlay=function(){this.map.addOverlay(this.feedHomeVoice)
};
P4.maps.removeHomeVoiceOverlay=function(){this.map.removeOverlay(this.feedHomeVoice)
};
$(document).ready(function(){$("#query").focus();
if(new GBrowserIsCompatible()){P4.maps.initialize();
if(P4.maps.i18n.showPlay==0){$("#toggleVoiceOverlay").toggle(function(){this.className="active";
P4.maps.addVoiceOverlay()
},function(){this.className="inactive";
P4.maps.removeVoiceOverlay()
})
}else{$("#toggleVoiceOverlay").toggle(function(){this.className="inactive";
P4.maps.removeVoiceOverlay()
},function(){this.className="active";
P4.maps.addVoiceOverlay()
})
}if(P4.maps.i18n.showHomeVoice==0){$("#toggleHomeVoiceOverlay").toggle(function(){this.className="active";
P4.maps.addHomeVoiceOverlay()
},function(){this.className="inactive";
P4.maps.removeHomeVoiceOverlay()
})
}else{$("#toggleHomeVoiceOverlay").toggle(function(){this.className="inactive";
P4.maps.removeHomeVoiceOverlay()
},function(){this.className="active";
P4.maps.addHomeVoiceOverlay()
})
}if(P4.maps.i18n.showPlayOnline==0){$("#toggleOverlay").toggle(function(){this.className="active";
P4.maps.addOverlay()
},function(){this.className="inactive";
P4.maps.removeOverlay()
})
}else{$("#toggleOverlay").toggle(function(){this.className="inactive";
P4.maps.removeOverlay()
},function(){this.className="active";
P4.maps.addOverlay()
})
}if(P4.maps.i18n.showShops==0){P4.maps.shopsVisible=false;
$("#toggleShops").toggle(function(){this.className="active";
P4.maps.shopsVisible=true;
P4.maps.showShops()
},function(){this.className="inactive";
P4.maps.shopsVisible=false;
P4.maps.hideShops()
})
}else{$("#toggleShops").toggle(function(){this.className="inactive";
P4.maps.shopsVisible=false;
P4.maps.hideShops()
},function(){this.className="active";
P4.maps.shopsVisible=true;
P4.maps.showShops()
})
}var A=function(){$("#searchForm").submit();
return false
};
$("#searchImg").click(A);
$("#searchButton").click(A);
$("#searchForm").submit(function(){jQuery.getScript("/maps/search?q="+encodeURIComponent($("#query").val()));
return false
})
}});
$(document).ready(function(){if(P4.maps.i18n.showShops==1){setTimeout(function(){P4.maps.createShops();
P4.maps.shopsVisible=true;
P4.maps.updateShopsList()
},1000);
P4.created.shops=1
}});