function initialize(lat,lng,zoom) {
  var myOptions = {
    zoom: zoom,
    center: new google.maps.LatLng(lat,lng),
    mapTypeControl: true,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
	navigationControl: true,
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
    mapTypeId: google.maps.MapTypeId.TERRAIN
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"),
                                myOptions);

  setMarkers(map, beaches);
}

/**
 * Data for the markers consisting of a name, a LatLng and a zIndex for
 * the order in which these markers should display on top of each
 * other.
 */
  var image1 = new google.maps.MarkerImage('images/schron1.png',
      // This marker is 32 pixels wide by 32 pixels tall.
      new google.maps.Size(22, 22),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(11, 11));
  var image = new google.maps.MarkerImage('images/schron.png',
      // This marker is 32 pixels wide by 32 pixels tall.
      new google.maps.Size(22, 22),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(11, 11));
var marker = new Array(); 
function setMarkers(map, locations) {
  // Add markers to the map

  // Marker sizes are expressed as a Size of X,Y
  // where the origin of the image (0,0) is located
  // in the top left of the image.

  // Origins, anchor positions and coordinates of the marker
  // increase in the X direction to the right and in
  // the Y direction down.


  var shadow = new google.maps.MarkerImage('images/beachflag_shadow.png',
      // The shadow image is larger in the horizontal dimension
      // while the position and offset are the same as for the main image.
      new google.maps.Size(37, 32),
      new google.maps.Point(0,0),
      new google.maps.Point(0, 32));
      // Shapes define the clickable region of the icon.
      // The type defines an HTML <area> element 'poly' which
      // traces out a polygon as a series of X,Y points. The final
      // coordinate closes the poly by connecting to the first
      // coordinate.
  var shape = {
      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
      type: 'poly'
  };

for(var index in locations) {

   var beach = locations[index];
    var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
     marker[index] = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image,
        shape: shape,
        title: beach[0],
        zIndex: beach[3]
    });

		updateMarker(marker[index],beach); 


  }
}

function updateMarker(marker,beach) { 
  google.maps.event.addListener(marker, 'mouseover', function() {

	marker.setIcon(image1);
   if(beach[4][1]) document.getElementById('prawa').innerHTML = '<h4>'+beach[0]+'</h4><div class="thumbnail"><img src="thumb.php?plik='+beach[4][0]+'"></div><div class="thumbnail"><img src="thumb.php?plik='+beach[4][1]+'"></div>'; 
	else  document.getElementById('prawa').innerHTML = '<h4>'+beach[0]+'</h4><div class="thumbnail"><img src="thumb.php?plik='+beach[4][0]+'"></div>'; 
  });
  google.maps.event.addListener(marker, 'click', function() {
  window.location.href=beach[5];
  });

  google.maps.event.addListener(marker, 'mouseout', function() {
	marker.setIcon(image);
    document.getElementById('prawa').innerHTML = '<h4>Mapa interaktywna</h4><div style="margin-top:15px;margin-left:10px;margin-right:10px;text-align:left;font-size:13px;">Po najechaniu na wybrane schronisko wyświetli się skrócona galeria zdjęć oraz możliwość wejścia na stronę danego schroniska.</div>'; 
  });
}
