// JavaScript Document


var map;
var markers = [];

$(document).ready(function() {
						  
	if (GBrowserIsCompatible()) {
		// Initialize the map.
		map = new GMap2(document.getElementById("Map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(54.059849,-2.790432), 14);

		$.ajax({type:"GET",url:"/Scripts/MarkerPins.php",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);
				   
					GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowHtml(html);
					});

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

			error:function(XMLHTTPRequest,textStatus,errorThrow){
				alert("There was an error retrieving the marker information.");
			}});
	}
   
});

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