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(){

	$("#contactForm").submit(function(){
		var champsObligatoires = [ "prenom", "nom", "email", "commentaire" ];
		var error = false;
		$.each(champsObligatoires, function(i){
			if($("#"+this).val() == ""){
				error = true;
				$("#"+this).fadeOut("fast", function(){
					$(this).css({"background-color":"#ff6"}).fadeIn("fast");
				});
			}
		});
		if(error == true){
			return false;
		}
	});
	
	
	$(".adresse").defuscate();
	
	$(".tooltip")
	  .prepend('<a href="#" rel="close"><img style="padding:2px 2px 0 0;float:right" src="/images/b-close.png" alt="close" /></a>')
	  .css({"width":"200px","position":"absolute","background-color":"white","margin":"0 0 0 408px","padding":"3px 5px","border":"1px solid #999"})
	  .hide()
	;
  
	$(".tooltipButton").click(function(e){
		$(".tooltip").hide();
		var tPosX = e.pageX-10;
		var tPosY = e.pageY-10;
	  var id = $(this).attr("href");
	  $(id).show();
	  $(id).css({"top":tPosY});
	  return false;
	});

	$("a[rel=close]").click(function(e){
	  $(this).parent().hide();
	  return false;
	});
	
  $.gaTracker('UA-1176812-1');

});
