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

function hidemedia_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() {
				
	$("#cool").live("click",function(e){
                e.preventDefault();

                $.ajax({
                        type: "POST",
                        data: "media_id=" + $("#cool").attr("val") + "&note=1",
                        url: "/ajax/media/media_note.php",
                        dataType : "json",
                        error: function(msg, string){
                                return false;
                        },
                        success: function(data, status){
                                if(typeof(data.retour) != 'undefined')
                                {
                                        if (data.retour == "0")
                                        {
						$("#nb_cp").html(data.score).clignote();
						hidemedia_err();
                                        }
					else
					{
						if (data.retour == "2")
						{
							window.location = "/login.php";
						}
						else
							affmedia_err(data.error);
					}
                                }
                        }
                });

                return false;
        });

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

                $.ajax({
                        type: "POST",
                        data: "media_id=" + $("#bof").attr("val"),
                        url: "/ajax/media/media_note.php",
                        dataType : "json",
                        error: function(msg, string){
                                return false;
                        },
                        success: function(data, status){
                                if(typeof(data.retour) != 'undefined')
                                {
                                        if (data.retour == "0")
                                        {
						$("#nb_cp").html(data.score).clignote();
						hidemedia_err();
                                        }
					else
					{
						if (data.retour == "2")
						{
							window.location = "/login.php";
						}
						else
							affmedia_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/media/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("/exploits/exploit_media.php", {'ei': $("#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/media/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("/exploits/exploit_media.php", {'ei': $("#mp_nouveau").attr("val2")});
						$("#mp_meilleur").html("Les meilleurs ");
						$("#mp_nouveau").html("<span> Les nouveaux</span>");
					}
				}
			}
		});

		return false;
	});

});

