function affdefi_err(message){
        $("#erreur_vote").css('display','block');
}

function hidedefi_err(){
        $("#erreur_vote").css('display','none');
}

//FONCTION DE CLIGNOTEMENTS
$.fn.clignote = function(){
   	this.fadeIn(50).fadeOut(50).fadeIn(50).fadeOut(50).fadeIn(50).fadeOut(50).fadeIn(50).fadeOut(50).fadeIn(50).fadeOut(50).fadeIn(50).fadeOut(50).fadeIn(50).fadeOut(50).fadeIn(50).fadeOut(50).fadeIn(50);
}


$(document).ready(function() {
				
	$("#plus").live("click",function(e){
                e.preventDefault();

                $.ajax({
                        type: "POST",
                        data: "defi_id=" + $("#plus").attr("val") + "&note=1",
                        url: "/ajax/defi/defi_note.php",
                        dataType : "json",
                        error: function(msg, string){
                                return false;
                        },
                        success: function(data, status){
                                if(typeof(data.retour) != 'undefined')
                                {
                                        if (data.retour == "0")
                                        {
						hidedefi_err();
						$("#nb_plus").html(data.score).clignote();
                                        }
					else
                                        {
                                                affdefi_err(data.error);
                                        }
                                }
                        }
                });

                return false;
        });	

	$("#moins").live("click",function(e){
                e.preventDefault();

                $.ajax({
                        type: "POST",
                        data: "defi_id=" + $("#moins").attr("val"),
                        url: "/ajax/defi/defi_note.php",
                        dataType : "json",
                        error: function(msg, string){
                                return false;
                        },
                        success: function(data, status){
                                if(typeof(data.retour) != 'undefined')
                                {
                                        if (data.retour == "0")
                                        {
						hidedefi_err();
						$("#nb_moins").html(data.score).clignote();
                                        }
					else
                                        {
                                                affdefi_err(data.error);
                                        }
                                }
                        }
                });

                return false;
        });	

	$("#mp_meilleur").live("click",function(e){
		e.preventDefault();
	
		$.ajax({
			type: "POST",
			data: "mp=" + $("#mp_meilleur").attr("val") + "&mp_id=" + $("#mp_meilleur").attr("val2"),
			url: "/ajax/defi/lien_mp.php",
			dataType : "json",
			error: function(msg, string){
				return false;
			},
			success: function(data, status){
			 	if(typeof(data.retour) != 'undefined')
				{
			 		if (data.retour == "0")
					{
						$("#exploit_media").load("/defis/exploit_media.php", {'di': $("#mp_meilleur").attr("val2")});
						$("#mp_meilleur").html("<span>Les meilleurs </span>");
						$("#mp_nouveau").html(" Les nouveaux");
					}
				}
			}
		});

		return false;
	});

	$("#mp_nouveau").live("click",function(e){
		e.preventDefault();
	
		$.ajax({
			type: "POST",
			data: "mp=" + $("#mp_nouveau").attr("val") + "&mp_id=" + $("#mp_nouveau").attr("val2"),
			url: "/ajax/defi/lien_mp.php",
			dataType : "json",
			error: function(msg, string){
				return false;
			},
			success: function(data, status){
			 	if(typeof(data.retour) != 'undefined')
				{
			 		if (data.retour == "0")
					{
						$("#exploit_media").load("/defis/exploit_media.php", {'di': $("#mp_nouveau").attr("val2")});
						$("#mp_meilleur").html("Les meilleurs ");
						$("#mp_nouveau").html("<span> Les nouveaux</span>");
					}
				}
			}
		});

		return false;
	});

/*	$(".tagrech").live("click",function(e){
		w = $(this).text();
		$("#recherche_val").val(w);
		$("#recherche_type").val(5);
		$("#recherche").submit();
      return false;
	});*/
});
