
//icons
var theIcon = new GIcon(); 
theIcon.image = 'googlemap/icons/icon.png';
theIcon.shadow = 'googlemap/icons/iconShadow.png';
theIcon.iconSize = new GSize(24, 24);
theIcon.iconAnchor = new GPoint(12, 24);
theIcon.shadowSize = new GSize(50, 25);
theIcon.infoWindowAnchor = new GPoint(18, 24);

//	declare global variables
var map, cluster;

function initialize() {
	if (GBrowserIsCompatible()) {
		map=new GMap2(document.getElementById('map'));

		
		GDownloadUrl("googlemap/data_xml.php?n=0", function(data) {
			var xml = GXml.parse(data);
			var marker, markersArray=[];
			var markers = xml.documentElement.getElementsByTagName("marker");
			
			
			for (var i = 0; i < markers.length; i++) {
				var theName = markers[i].getAttribute("name");
				var theHtml = markers[i].getAttribute("infoWindowHtml");
				//var theCenterPoint = new GLatLng(parseFloat(markers[i].getAttribute("lat"))+0.0045, parseFloat(markers[i].getAttribute("lng"))+0.005);
				
								marker=newMarker(new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))), i, theHtml, theIcon, theName);
								markersArray.push(marker);
			}

			var cluster=new ClusterMarker(map, { markers:markersArray } );
			cluster.fitMapToMarkers();

			function newMarker(markerLocation, markerId, theHtml, theIcon, theName) {
				var marker=new GMarker(markerLocation,{ icon:theIcon,title: theName });
				GEvent.addListener(marker, 'click', function() {
					marker.openInfoWindowHtml(theHtml);
				});
				return marker;
			}
			function newSingleMarker(markerLocation, markerId, theHtml, theIcon, theName) {
				var marker=new GMarker(markerLocation,{ icon:theIcon,title: theName });
				marker.openInfoWindowHtml(theHtml);
				return marker;
			}
			//alert('endLoadXML');
			fCloseLoadingBox();
		});
		
	map.setCenter(new GLatLng(46.79, 8.35), 8);
		map.savePosition();
		map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
	}
}
