// A function to create the marker and set up the event window
// Dont try to unroll this function. It has to be here for the function closure
// Each instance of the function preserves the contends of a different instance
// of the "marker" and "html" variables which will be needed later when the event triggers.
function createMarker(point,html) {
	var marker = new GMarker(point);
	if(html)
	{
		GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
		});
	}
	return marker;
}

function createMiniMarker(point,html)
{
	var icon = new GIcon();
	icon.image = "/gfx/markers/mm_20_green.png";
	icon.shadow = "/gfx/markers/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);

	var marker = new GMarker(point, icon);
	if(html)
	{
		GEvent.addListener(marker, "click", function()
		{
			marker.openInfoWindowHtml(html);
		});
		GEvent.addListener(marker, "dblclick", function()
		{
			PutMarker('', point);
		});
	}

	return marker;
}

function showMiniMarkers(miniMarker)
{
	var miniBounds = new GLatLngBounds();
	var point;
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(52.119999,19.401855),5);
	map.addControl(new GSmallMapControl());
	
	for(var i=0;i<miniMarker.length;i++)
	{
		map.addOverlay(miniMarker[i]);
		miniBounds.extend(miniMarker[i].getLatLng());
	}

	if(miniMarker.length>0)
	{
		var center = miniBounds.getCenter();
		var zoom=map.getBoundsZoomLevel(miniBounds);
		if(zoom>12)
			zoom=12;

		if(zoom!=5)
		{
			//jesli mamy miec widok calej Polski (zoom 5), to nie przesuwamy go,
			//tylko zostawiamy Polske w centrum mapy
			map.setZoom(zoom);
			map.setCenter(center);
		}
	}
}
