// JavaScript Document

      $(document).ready(function() {
	 $(".mapLink").prepend("Click to Show "); 
     $(".mapLink").css({ 'cursor' : 'pointer'}); 
	});
	  
	  
jQuery(function() {	
// First create a div to host the map
	var themap = jQuery('<div id="themap"></div>').css({
		'width': '90%',
		'height': '400px'
	    }).insertAfter('.mapLink');

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

    // Geocode each hcard, center on geolocation and add a marker
$('.vcard').each(function() {
        var hcard = $(this);
    
        var latitude = hcard.find('.geo .latitude').text();
        var longitude = hcard.find('.geo .longitude').text();
    	var title = hcard.find('h2').html();
    	var address = hcard.find('.adr').html();
		var streetaddress = hcard.find('.street-address').text();
		var postcode = hcard.find('.postal-code').text();
		var mapaddress =  streetaddress + ',' + postcode ;
	
	// ======== Add a "directions" link ======
//	var directions = '<a href="http://maps.google.com/maps?saddr=&daddr=' + mapaddress + '" target ="_blank" class="directionsLink">Click for Directions</a>';
// Removed becasue we manually add a link for driving directions to main address
		
	mapstraction.setCenterAndZoom(
   	new LatLonPoint(latitude, longitude),
		15 // Zoom level appropriate for city centre
	);
	
	 var marker = new Marker(new LatLonPoint(latitude, longitude));
        marker.setInfoBubble(					 
            '<div class="bubble">' + title + '<br />' + address  + /* // directions linnk removed // + '<br />' + directions + */'</div>'
        );
        mapstraction.addMarker(marker);
	//	marker.openBubble(); // this seems to create the map on load resulting in the marker being off screen on slide dwown

    });
//  });
$('#themap').hide();
$('.mapLink').click(function() {
$('#themap').slideToggle('normal');
});
});