/* Rutiny pro mapu vykopírovány do samostatného souboru
 *   (magická chyba 80004004 posr.... prohlížeče)
 */

    function initMap() {
      if (GBrowserIsCompatible()) {
        mapfield = new GMap2(document.getElementById("mapfield"));
        mapfield.setCenter(startPosition, 5);
	/* */
	mapfield.addControl(new GLargeMapControl());
	mapfield.addControl(new GMapTypeControl());
	mapfield.enableDoubleClickZoom();
	mapfield.enableContinuousZoom();
	GEvent.addListener(mapfield, 'dragend', sendMarkersRequest);
	GEvent.addListener(mapfield, 'zoomend', sendMarkersRequest);
	sendMarkersRequest();
      }
    }
    function sendMarkersRequest() {
	bounds = mapfield.getBounds();
	sw = bounds.getSouthWest(); ne = bounds.getNorthEast();
	/* */
	args = 'BBOX='+sw.lng().toString()+','+ sw.lat().toString()+','+
	               ne.lng().toString()+','+ ne.lat().toString();
	GDownloadUrl('http://www.cestovatel.cz/kml/clanky-handler.kml?w=1&'+args, updateMarkers);
    }
    function clickFactory(marker) {
	return function() {
		marker.openInfoWindowHtml('<div style="width: 350px"><p style="font-size: 120%; font-weight:bold">' + marker.name + '</p>' + marker.description + '</div>');
	}
    }
    function updateMarkers(data) {
	var xml = GXml.parse(data).documentElement;
	locations = xml.getElementsByTagName("Placemark");
	mapfield.clearOverlays();
	if (locations.length) {
		for (i = 0; i < locations.length; i++) {
			now = locations[i];
			point = now.getElementsByTagName("Point")[0];
			coords = point.getElementsByTagName("coordinates")[0].childNodes[0].nodeValue;
			coords = coords.split(",");
			name = now.getElementsByTagName("name")[0].childNodes[0].nodeValue;
			description = now.getElementsByTagName("description")[0].childNodes[0].nodeValue; 
			point = new GLatLng(parseFloat(coords[1]), parseFloat(coords[0]));
			marker = new GMarker(point, name);
			mapfield.addOverlay(marker);	
			marker.description = description;
			marker.name = name;
			marker.bindInfoWindowHtml('<div style="width: 350px"><p style="font-size: 120%; font-weight:bold">' + marker.name + '</p>' + marker.description + '</div>');
			/*GEvent.addListener(marker, "click", 
				clickFactory(marker));*/
		}
	}
    }

/* příšerně žluťoučký kůň, ty koňu
 */

