$(document).ready(function(){
	/* LOCATION MAP */
	var map;
	var markers = [];

	if (GBrowserIsCompatible()) {
		// Initialize the map.
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(-41.3, 173.0), 5);

		//$.ajax({type:"GET",url:"http://localhost:8888/weathermaster/js/locations.xml",dataType:"xml",
		$.ajax({type:"GET",url:"http://www.weathermaster.co.nz/js/locations.xml",dataType:"xml",

			success:function(data,textStatus) {
				$("marker",data).each(function() {
					// Attributes for each marker.
           			var lat = parseFloat($(this).attr("lat"));
           			var lng = parseFloat($(this).attr("lng"));
           			var point = new GLatLng(lat,lng);
           			var html = $("html",this).text();

           			// Create the marker.
           			var marker = new GMarker(point);
	            	var addressShow = false;
					
			        GEvent.addListener(marker, "click", function() {
						// marker.openInfoWindowHtml(html);
						if (!addressShow) {
							$("#address").css("display","block");
						};
						$("#address").html(html)
			        });


					map.addOverlay(marker);
				});
			},

		error:function(XMLHTTPRequest,textStatus,errorThrow){
			alert("Can not find XML data.");
		}});
	}
	
});

$(document.body).unload(function() {
	if (GBrowserIsCompatible()) {
		GUnload();
	}
});



