var map;
var markers = [];
function initialize() {
  var myOptions = {
    zoom: 7,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false,
    panControl: true,
    panControlOptions: {
        position: google.maps.ControlPosition.TOP_RIGHT
    },
    zoomControl: true,
    zoomControlOptions: {
        style: google.maps.ZoomControlStyle.LARGE,
        position: google.maps.ControlPosition.RIGHT_TOP
    },
    scaleControl: false,
    streetViewControl: false
  };
   	  map = new google.maps.Map(document.getElementById("map"), myOptions);
      map.setCenter(new google.maps.LatLng(52,19.322205));
     drop();
}

	function drop()
	{
		$.ajax({
		 	 url: "/points",
			dataType:"json",
		 	success: function(data){
		 		$.each(data,function(i,el){
		 			 setTimeout(function() {      addMarker(el.lat,el.long,el.id)     }, i * 10);
		 		});
		  }
		});
	}


  function addMarker(lat,long,id) {
  	var marker;
    markers.push(marker = new google.maps.Marker({
      position: new google.maps.LatLng(lat,long),
      map: map,
      draggable: false,
      animation: google.maps.Animation.DROP
    }));
    
     google.maps.event.addListener(marker, 'click', function() {
		  $.each(markers,function(i,el){el.setAnimation(null);})
	      marker.setAnimation(google.maps.Animation.BOUNCE);
     	aload(id);
    });
  }
  
function aload(id)
{
	$.ajax({
		 	 url: "/miasto/"+id,
			dataType:"html",
		 	success: function(data){
		 		$('#dialog').html(data);
		 		$('#dialog').dialog({width:768,height:500});
		  }
		});
}

