$(document).ready(function() {
	
    /**
    * @section       Moteur de recherche de recettes
    * @note          Empty field when focused
    */
    if ($('#searchRecipeForm #ingredient1').val() == '') {
        $('#searchRecipeForm #ingredient1').val('Ingrédient 1');
    }
    $('#searchRecipeForm #ingredient1').focus( function(){
        if ($(this).val() == 'Ingrédient 1') {
            $(this).val('');
        }
    }); 
    
    if ($('#searchRecipeForm #ingredient2').val() == '') {
        $('#searchRecipeForm #ingredient2').val('Ingrédient 2');
    }
    $('#searchRecipeForm #ingredient2').focus( function(){
        if ($(this).val() == 'Ingrédient 2') {
            $(this).val('');
        }
    }); 
    
    /**
    * @section       Print button
    * @note          print
    */
    $('a.print').click(function(){
    	window.print();
    	return false;
    });

    
    
	function no_accent (my_string) {
		var new_string = "";
		var pattern_accent = new Array("é", "è", "ê", "ë", "ç", "à", "â", "ä", "î", "ï", "ù", "ô", "ó", "ö");
		var pattern_replace_accent = new Array("e", "e", "e", "e", "c", "a", "a", "a", "i", "i", "u", "o", "o", "o");
		if (my_string && my_string!= "") {
			new_string = preg_replace (pattern_accent, pattern_replace_accent, my_string);
		}
		return new_string;
	}
    
    
    /**
    * @section       Tags
    */
    $('.tagCloud a').click(function(){
    	var tag = no_accent($(this).html().toLowerCase().replace(/ /, '_'));
    	$('body').append('<img src="http://fr.sitestat.com/danone/bledina/s?repas_bebe.recettes_mamans.tag_ingredients"'+ tag +' width="1" height="1">');
    });
    $('#nouveau .manageOverlay').click(function(){
    	$('body').append('<img src="http://fr.sitestat.com/danone/bledina/s?repas_bebe.recettes_mamans.popin.avis" width="1" height="1">');
    });
    $('.actions .manageOverlay').click(function(){
    	$('body').append('<img src="http://fr.sitestat.com/danone/bledina/s?repas_bebe.recettes_mamans.popin.envoyer_ami" width="1" height="1">');
    });
    
    $('#formPopinSendToFriend #bouton_valider').click(function(){
    	$('body').append('<img src="http://fr.sitestat.com/danone/bledina/s?repas_bebe.recettes_mamans.popin.confirmation_envoyer_ami" width="1" height="1">');
    });
    $('#formPopinQuestion #bouton_valider').click(function(){
    	$('body').append('<img src="http://fr.sitestat.com/danone/bledina/s?repas_bebe.recettes_mamans.popin.envoi_avis" width="1" height="1">');
    });
    
});