jQuery(function($) {
	
	//set the centre position using the latitude and longitutde of text
	var centerPosition = $('.campus_address');
	var latitude = centerPosition.find('.geo .latitude').text();
	var longitude = centerPosition.find('.geo .longitude').text();

    // Now initialise the map
    var mapstraction = new Mapstraction('themap','google');
    mapstraction.addControls({
 		zoom: 'small',
		map_type: false
    });

    // Show map centred on Brighton
    mapstraction.setCenterAndZoom(
        new LatLonPoint(latitude,longitude),
        15 // Zoom level appropriate for Brighton city centre
	);				
				
    // Geocode each hcard and add a marker
    $('div.campus_address h2').each(function() {
       
	   var hcard = $(this);
		
		var streetaddress = hcard.find('.street-address').text();
        var postcode = hcard.find('.postal-code').text();
    
		var geocoder = new MapstractionGeocoder(function(result) {
        	var marker = new Marker(result.point);
        	marker.setInfoBubble(
            	'<div class="bubble">' + hcard.html() + '</div>'
        	);
       	 mapstraction.addMarker(marker);
		}, 'google');    
        geocoder.geocode({'address': streetaddress + ', ' + postcode});
    });	
	
	//remove footer text from map
	var mapDiv = $("#themap div").length-2;
	$("#themap div").eq(mapDiv).hide();

});
