jQuery(function($) {
    // First create a div to host the map
    var themap = $('<div id="themap"></div>').css({
        'width': '100%',
        'height': '500px'
    }).insertBefore('#shops');

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

    // Show map centred on Brighton
    mapstraction.setCenterAndZoom(
        new LatLonPoint(-26.902476886279807, 134.736328125),
        4 // Zoom level appropriate for Australia centred
    );

    // Geocode each hcard 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 custom = hcard.find('.geo .marker').text();
			
        var marker = new Marker(new LatLonPoint(latitude, longitude));
		
		if(custom == "Yes")
		{
			marker.setLabel("Wholesale Bait Shop");
			
			marker.setIcon('images/blue_MarkerW.png');
			
		}
		else
		{
		
		marker.setLabel("Retail Bait Shop");
			
		marker.setIcon('images/darkgreen_MarkerR.png');
		
		}
		
        marker.setInfoBubble(
            '<div class="bubble">' + hcard.html() + '</div>'
        );
        mapstraction.addMarker(marker);
    });
});

