	var map = null;
    
    var geocoder = null;
	
	var mmgr = null;
	
	var area = null;
	
	// Polska:
	var defaultCenterW = 51.919438;
	var defaultCenterL = 19.145136;

	var preciseLocations = new Array(1);
	var impreciseLocations	= new Array(1);
	
	var index = 0;

	function Shop(city,street,nr,postCode,loc1,loc2,phone,latitude,longitude, mon, tue, wed, thu, fri, sat, sun) {
		this.city = city;
		this.street = street;
		this.nr = nr;
		this.postCode = postCode;
		this.loc1 = loc1;
		this.loc2 = loc2;
		this.phone = phone;
		this.latitude = latitude;
		this.longitude = longitude;
		this.mon = mon;
		this.tue = tue;
		this.wed = wed;
		this.thu = thu;
		this.fri = fri;
		this.sat = sat;
		this.sun = sun;
	}
	
	
	
	// wstepna inicjalizacja danych:
	impreciseLocations[0] = new Shop("", "", "", "", "", "", "", "", "1", "", "", "", "", "", "", "");// nie spelnia warunku: if(impreciseLocations[i].latitude.blank() == true && impreciseLocations[i].longitude.blank() == true)
	preciseLocations[0] = new Shop("", "", "", "", "", "", "", "", "1", "", "", "", "", "", "", ""); // nie spelnia warunku: if(preciseLocations[i].latitude.blank() == false && preciseLocations[i].longitude.blank() == false)
	
	
	function initialize()  
	{  
	    if(GBrowserIsCompatible())  // sprawdzamy, czy przeglai?1darka jest kompatybilna  
	    {  
			
			// tworzymy nowy obiekt mapy, i umieszczamy go w elemencie blokowym o ID "map"  
	        map = new GMap2(document.getElementById('map'));
	        
			// obszar widocznosci markerow
			area = new GLatLngBounds();
			
			// po dodaniu kazdego markera dostosowanie zoom'u i srodka mapy
			GEvent.addListener(map, "addoverlay", function() {
				  resizeMap();
			});
			
			// ustawienie domyslnego srodka
			map.setCenter(new GLatLng(defaultCenterW, defaultCenterL),6);

			// dodanie kontrolki trybu wyswietlania
			map.addControl(new GMapTypeControl());

			// dodanie kontrolki sterowania zoomem
			map.addControl(new GLargeMapControl());  

			geocoder = new GClientGeocoder();

			// dodanie markerow
			setMarkers(preciseLocations, impreciseLocations);
			
			// dodanie skali
			map.addControl(new GScaleControl());  

	    }  
	}
	

	/* funkcja odpowiedzialna za dopasowanie parametrow mapy (center, zoom) do aktualnego obszaru */
	function resizeMap(){
		
		// wyciai?1gamy zoom
		var zoom = map.getBoundsZoomLevel(area);
		
		// wyciai?1gamy srodek obszaru
		var centerPoint = area.getCenter();
		
		// centrujemy do tego punktu i poziomu zoom
		map.setCenter(centerPoint,zoom);
	}


	
	/* ustawienie srodka mapy */
	function setCenter(address) {
		if (geocoder) {
	        geocoder.getLatLng(
	          address,
          function(point) {
		    if (!point) {
				alert(address + " not found");
		    } else {
		    	area.extend(point);
				map.setCenter(point, 6);
            }
          }
		);
      }
	}



	/* dodawanie markerow do mapy */
	function setMarkers(preciseLocations, impreciseLocations) {
		
		var ikona1 = new GIcon();				
		ikona1.image = "/images/shopsearch/map_pin.png";
		ikona1.shadow = "/images/shopsearch/map_pin_shadow.png";				
		ikona1.iconSize = new GSize(71, 35);
		ikona1.infoWindowAnchor = new GPoint(42,5);
		ikona1.iconAnchor = new GPoint(35, 35);
		ikona1.shadowSize = new GSize(71, 35);
		
		// zaznaczenie drogerii, dla kti?1rych okreslono dokladne polozenie geograficzne:
		for (i=0; i<preciseLocations.length; i++) {
			
			if(preciseLocations[i].latitude.blank() == false && preciseLocations[i].longitude.blank() == false) {
			
				var precisePoint = new GLatLng(preciseLocations[i].latitude, preciseLocations[i].longitude);;
				area.extend(precisePoint);
				var preciseMarker = new GMarker(precisePoint, ikona1);
				map.addOverlay(preciseMarker);
				preciseMarker.bindInfoWindowHtml(createInfoWindowHtml(preciseLocations[i]));;
			}
		}

		index = 0;

		// zaznaczenie drogerii, dla kti?1rych nie okreslono dokladnego polozenia geograficznego:
		if (geocoder) {
		
			
				
			for (i=0; i<impreciseLocations.length; i++) {
			
				if(impreciseLocations[i].latitude.blank() == true && impreciseLocations[i].longitude.blank() == true) {
					
					var address = impreciseLocations[i].city + ", " + impreciseLocations[i].street;
					
					var city_location = "" + impreciseLocations[i].city;
					
					// probujemy wyszukac po nazwie miasta i nazwie ulicy:
					geocoder.getLatLng(
						address,
						function(point) {
						    if (!point) { // wyszukiwanie po nazwie miasta i nazwie ulicy nie powiodlo sie
					          	
					          	// probujemy wyszukac tylko po nazwie miasta
								geocoder.getLatLng(
									city_location,
									function(secondChancePoint) {
									    if (!secondChancePoint) {
								          	
								          	index++;
		    								
									    } else {
									    	area.extend(secondChancePoint);
											var marker = new GMarker(secondChancePoint, ikona1);
											map.addOverlay(marker);
											marker.bindInfoWindowHtml(createInfoWindowHtml(impreciseLocations[index]));
											index++;
										}
									}
								);			          
		     
						    } else {
						    	area.extend(point, ikona1);
								var marker = new GMarker(point, ikona1);
								map.addOverlay(marker);
								marker.bindInfoWindowHtml(createInfoWindowHtml(impreciseLocations[index]));
								index++;
							}
						}
					);
				}
			}

	     }

	}



	
	/* funkcja odpowiedzialna za stworzenie html'a do pokazania w chmurce */
	function createInfoWindowHtml(loc){

		var infoHtml = '<div class="infoWind" style="width: 290px; height: 175px;">';
		if(loc.nr.blank() == false) {
			infoHtml += '<h3>Drogeria Rossmann nr ' + loc.nr + '</h3>';
		}	

		infoHtml += '<div class="details">';
		
		if(loc.postCode.blank() == false && loc.city.blank() == false) {
			infoHtml += '<p>' + loc.postCode + " " + loc.city + '</p>';
		}
		else {
			if(loc.postCode.blank() == true && loc.city.blank() != false) {
				infoHtml += '<p>' + loc.city + '</p>';
			}
		}
		
		if(loc.street.blank() == false) {
			infoHtml += '<p>ul. ' + loc.street + '</p>';
		}
		
		if(loc.loc1.blank() == false) {
			if(loc.loc2.blank() == false) {
				// wyswietlamy obie lokalizaje
				infoHtml += '<p>' + loc.loc1 + ", " + loc.loc2 + '</p>';
			}	else {
				// wyswietlamy tylko I lokalizaje:
				infoHtml += '<p>' + loc.loc1 + '</p>';
			}
		} else {
			
			if(loc.loc2.blank() == false) {
				// wyswietlamy tylko II lokalizaje:
				infoHtml += '<p>' + loc.loc2 + '</p>';
			} else {
				 // nie wyswietlamy zadnej lokalizaji
			}
		}
		
		
		if(loc.phone.blank() == false) {
			infoHtml += '<br/><p>tel. ' + loc.phone + '</p>';
		}
			
		infoHtml += '<br/>';
	
		infoHtml += '<div class="box_drogerie_calendar_title" style="width:290px;">Godziny otwarcia:</div>';
		infoHtml += '<div class="box_drogerie_calendar_days" style="width:290px;">';
			
			infoHtml += '<div class="day_box">';
				infoHtml += '<div class="day_name_box">Pn</div>';
				infoHtml += '<div class="day_hours_box">' + loc.mon + '</div>';
			infoHtml += '</div>';

			infoHtml += '<div class="day_box">';
				infoHtml += '<div class="day_name_box">Wt</div>';
				infoHtml += '<div class="day_hours_box">' + loc.tue + '</div>';
			infoHtml += '</div>';

			infoHtml += '<div class="day_box">';
				infoHtml += '<div class="day_name_box">Śr</div>';
				infoHtml += '<div class="day_hours_box">' + loc.wed + '</div>';
			infoHtml += '</div>';

			infoHtml += '<div class="day_box">';
				infoHtml += '<div class="day_name_box">Cz</div>';
				infoHtml += '<div class="day_hours_box">' + loc.thu + '</div>';
			infoHtml += '</div>';
			
			infoHtml += '<div class="day_box">';
				infoHtml += '<div class="day_name_box">Pt</div>';
				infoHtml += '<div class="day_hours_box">' + loc.fri + '</div>';
			infoHtml += '</div>';

			infoHtml += '<div class="day_box">';
				infoHtml += '<div class="day_name_box">So</div>';
				infoHtml += '<div class="day_hours_box">' + loc.sat + '</div>';
			infoHtml += '</div>';

			infoHtml += '<div class="day_box">';
				infoHtml += '<div class="day_name_box">Nd</div>';
				infoHtml += '<div class="day_hours_box">' + loc.sun + '</div>';
			infoHtml += '</div>';
			
		infoHtml += '</div>';


		
		infoHtml += '</div></div>';

		return infoHtml;
	}

	function showAddress(address) {
		if (geocoder) {
	        geocoder.getLatLng(
	          address,
          function(point) {
		    if (!point) {
              alert(address + " not found");
		    } else {				
			  map.setCenter(point, 6);
              var marker = new GMarker(point);
		      map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
		    }
          }
		);
      }
	}