$(document).ready(function() {

    $("a").filter(function() {
	return this.hostname && this.hostname !== location.hostname;
    }).attr('target', '_blank');

    Cufon.replace('h2');
    Cufon.replace('span.date');

    //Cufon.replace('p');

    $('body > ul').shuffle();

    $('ul#twitter').innerfade({
	animationtype: 'fade',
	speed: 750,
	timeout: 3000, 
	type: 'random_start',
	containerheight: '1em'
    });
    $('ul#twitter').css({
	'visibility' : 'visible'
    });

});

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

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

    // Centrer la carte sur la Cantine
    mapstraction.setCenterAndZoom(
	new LatLonPoint(48.87091822646468, 2.342780828475952),
	16 // Zoom level
	);

    // Geocoder
    jQuery('.vcard').each(function() {
	var hcard = jQuery(this);

	var streetaddress = hcard.find('.street-address').text();
	var postcode = hcard.find('.postal-code').text();
	var city = hcard.find('.locality').text();


	var geocoder = new MapstractionGeocoder(function(result) {
	    var marker = new Marker(result.point);
	    marker.setInfoBubble(
		'<div class="bubble">' + hcard.html() + '</div>'
		);
		
	    mapstraction.addMarker(marker);
	    marker.openBubble();
	}, 'google');

	geocoder.geocode({
	    'address': streetaddress + ', ' + postcode +', ' + city
	});
	
    });
    
});