
var map;
var infowindow;
var xml = http_base+'/en/associations.xml';

$(document).ready(function() {
	initializeMap();
});

function initializeMap() {
	var options = {
		zoom: 3,
		center: new google.maps.LatLng(57, -90),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map = new google.maps.Map(document.getElementById("map"), options);

	$.get(xml, {}, function(data) {
		$(data).find("association").each(function() {
		
			var latlng = new google.maps.LatLng(
				parseFloat($('latitude', this).text()),
				parseFloat($('longitude', this).text())
			);
			var marker = new google.maps.Marker({position: latlng, map: map});
			
			var body = '<div id="infowindow">'+
				'<h1>'+$('branch', this).text()+'</h1>'+
				'<p>'+
				$('address', this).text()+'<br>'+
				$('city', this).text()+', '+$('province', this).text()+'<br>'+
				$('postal_code', this).text()+'<br>'+
				'<a target="_blank" href="http://'+$('url', this).text()+'">'+
				$('url', this).text()+'</a>'+
				'</p>'+
				'</div>';

			google.maps.event.addListener(marker, 'click', function() {
				if (infowindow) infowindow.close();
				infowindow = new google.maps.InfoWindow({content: body});
				infowindow.open(map, marker);
			});
			
	 });
	});
}

