/* google maps... */
Map =
{
	config : null,
	map : null,

	initialize : function()
	{
		try { element = document.getElementById(Map.config.id); }
		catch(e) { alert('Nie zadeklarowano elementu do osadzenia mapy.'); return; }

		Map.map = new google.maps.Map2(element);

		if(Map.config.address && (! Map.config.latitude || ! Map.config.longitude))
		{
			geocoder = new google.maps.ClientGeocoder();
			geocoder.getLatLng(
				Map.config.address,
				function(point)
				{
					if(! point)
					{
						alert('Nie znaleziono współrzędnych punktu na mapie');
						return;
					}
					Map.setCenter(point);
				}
			);
		}

		if(Map.config.latitude && Map.config.longitude)
			Map.setCenter(
				new google.maps.LatLng(
					Map.config.latitude,
					Map.config.longitude
				)
			);

		Map.map.addControl(new google.maps.SmallMapControl());
	},

	setCenter : function(point)
	{
		Map.map.setCenter(
			point,
			Map.config.level
		);
		Map.map.addOverlay(
			new google.maps.Marker(point)
		);
	},

	onLoad : function ()
	{
		google.load('maps', '2', {'callback' : Map.initialize});
	}
};

try
{
	if(Map.config = MapConfig)
	{
		script = document.createElement('script');
		script.src = 'http://www.google.com/jsapi?key=' + MapConfig.key + '&callback=Map.onLoad';
		script.type = "text/javascript";
		document.getElementsByTagName('head')[0].appendChild(script);
	}
}
catch(e) { alert('Błędnie zadeklarowany obiekt konfiguracji mapy.'); }
