// JavaScript Document


	var map, ctrl;
	var icons=[];
	var bounds;

	
    function initialize() {
		
    	if (GBrowserIsCompatible()) {
	  
			map = new GMap2(document.getElementById("mini_map"));
			map.disableDoubleClickZoom();
			map.disableContinuousZoom();
			map.disableScrollWheelZoom();
			ctrl = new GSmallMapControl();
			map.addControl(ctrl);
	
			var center = new GLatLng( 53.140747, 23.167419 );
			map.setCenter( center , 14);
			
			bounds = new GLatLngBounds();
			map.setZoom(14);
			GEvent.addListener(map, "zoomend", function() {
				
				if (document.getElementById("typ").value!=2 )
				{	
						//map.setCenter(marker.getPoint(), 14); 
						

				}
			});
			
    	}
    }

	var baseIcon = new GIcon();
	baseIcon.image = "http://www.jaz-bud2.csk.pl/images/domek.png";
	baseIcon.shadow = "";
	baseIcon.iconSize = new GSize(30, 30);
	baseIcon.shadowSize = new GSize(32, 19);
	baseIcon.iconAnchor = new GPoint(6, 20);
	baseIcon.infoWindowAnchor = new GPoint(5, 1);

	function ikonka(type) {
		   	var color;
		   	if ((typeof(type)=="undefined") || (type==null)) { 
		   		color = "mieszkania"; 
		   	} 
		   	else if (type==1) { 
		   		color = "domy";	
		   	}
			else if (type==2) { 
		   		color = "mieszkania";	
		   	}
			else if (type==3) { 
		   		color = "dzialki";	
		   	}
			else if (type==4) { 
		   		color = "lokale";	
		   	}
			else if (type==5) { 
		   		color = "magazyny";	
		   	}
			else if (type==6) { 
		   		color = "siedliska";	
		   	}
			else
			{
				color = type;
			}
			
		   	if (!icons[type]) {
		    	var icon = new GIcon(baseIcon);
		    	icon.image = "http://www.jaz-bud2.csk.pl/images/domek.png";
				icon.shadow = "";
		    	icons[type]=icon;
		   	} 
		   	return icons[type];
	}
	
	function createMarker(point,icontype) {
		
	  	var icon = ikonka(icontype);
        var marker = new GMarker(point,icons[icontype]);
		marker.type = icontype;//color of marker
		bounds.extend(point);

    	return marker;
		
	}
	
	var lat = document.getElementById("lat").value;
	var lng = document.getElementById("lng").value;
	var point = new GLatLng(lat , lng);
	var typ = document.getElementById("typ").value;
	
	if (lat!="" && lng!="" && lat!=0 && lng!=0)
	{
		initialize();
		var marker = createMarker(point,typ);
		map.addOverlay(marker);
		if (document.getElementById("typ").value==2 )
		{
			map.setCenter(marker.getPoint(), 15);
		}
		else
		{
			map.setCenter(marker.getPoint(), 14);
		}
	}
	
	
	
	
	
