// not invented here !
// idea by simonwillison.net
// found at http://24ways.org/2007/unobtrusively-mapping-microformats-with-jquery

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

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

    // Show map centred on Germany
    mapstraction.setCenterAndZoom(
        new LatLonPoint(51, 11),
        6 // Zoom level appropriate for Germany
    );


	// Create Googlelink
	$('.vcard').each(function() {
        var hcard = $(this);
    
        var street_address = encodeURI( hcard.find('.street-address').text() );
        var postal_code    = encodeURI( hcard.find('.postal-code').text() );
        var locality       = encodeURI( hcard.find('.locality').text() );

		hcard.append( $('<p class="googlelink"><a href="http://maps.google.de/maps?f=q&hl=de&q=' + street_address + '+' + postal_code + '+' + locality + '">In Google Maps &ouml;ffnen</a></p>') );
        
    });

    // 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 marker = new Marker(new LatLonPoint(latitude, longitude));
        marker.setInfoBubble(
            '<div class="bubble">' + hcard.html() + '</div>'
        );
        mapstraction.addMarker(marker);
    });
});

