jQuery.fn.defuscate = function( settings ) {
    settings = jQuery.extend({
        link: true,
        find: /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi,
        replace: '$1@$2'
    }, settings);
    return this.each(function() {
        if ( $(this).is('a[@href]') ) {
            $(this).attr('href', $(this).attr('href').replace(settings.find, settings.replace));
            var is_link = true;
        }
        $(this).html($(this).html().replace(settings.find, (settings.link && !is_link ? '<a href="mailto:' + settings.replace + '">' + settings.replace + '</a>' : settings.replace)));
    });
};

$(document).ready(function() {
	$('.rowMois:not(.past)').each(function(){
		if ( $(this).parent().find('tr:last-child').hasClass('past') ) {
			$(this).addClass('past');
		};
	});
	if ($('#representations .rowMois:not(.past)').length > 0) {
		$('#representations .past').hide();
		if ($('#representations .past').length) {
			$('#representations').before('<p style="margin:0 0 0 30px"><a style="font-weight:normal" id="boutonPrec" href="">Afficher les représentations passées</a></p>');
		};
		$('#boutonPrec').toggle(
			function () {
				$('#boutonPrec').html('Masquer les représentations passées');
				$('#representations .past').show();
	     },
	     function () {
				$('#boutonPrec').html('Afficher les représentations passées');
				$('#representations .past').hide();
	     }
		);
	};
	
	$('#historyBack').click(function(){
		history.back();
		return false;
	});
	
	$('.adresse').defuscate();
	
});

