$(function()
{
	$('.actions.vote').click(function() 
	{
		var blog = $('.slug_blog').attr('title');

		if ($(".actions.vote").hasClass('i_like_it')) {
			$.ajax({
				url: '/vote/' + blog,
				type: "POST",
	            dataType: 'json',
	            cache: false,
	            beforeSend: function(data) {
	    			$(".actions.vote .text").innerHTML = "";	
	    			$(".actions.vote .score").hide();
        			$(".actions.vote").removeClass('i_like_it');					
        			$(".actions.vote").addClass('i_already_like_it');		    			
	    			$(".actions.vote .loader").show();
	    		},
	            success: function(data) {
	            	$("#blog_score_texte").innerHTML = "";
	            	$(".actions.vote .loader").hide();
	            	if (null != data.score) {
	        			$(".actions.vote .text").html('<p>Merci d\'avoir voté</p>');
	        			$(".actions.vote .score").html(data.score);
	        			$(".actions.vote .score").show();
	                } else {
	                	$(".actions.vote .score").html('error');
	                	$(".actions.vote .score").show();
	                }
	            }
			});	
		}
		return false;
	});
});
