/**
 * @author Santiago Mamone
 */

$(document).ready(function() {
	
	function cambiarVistaPuntos(puntos) {
		var elemPuntos = $('#verEmoticon-valorPuntos');
		elemPuntos.fadeOut('slow', function() {
			elemPuntos.text(puntos);
			elemPuntos.fadeIn('slow');
		});
	}
	
	function leerPuntos() {
		var elemPuntos = $('#verEmoticon-valorPuntos');
		var puntos = parseInt(elemPuntos.text());
		return puntos;
	}
	
	function deshabilitarLinkMeGusta() {
		$('#verEmoticon-linkMeGusta').css('display', 'none');
		$('#verEmoticon-linkMeGustaDeshabilitado').css('display', 'inline');
	}
	
	if ($('#usuario').val() !== '') {
		$('#verEmoticon-linkMeGusta').find('a').click(function(event) {
			var puntos = leerPuntos();
			puntos++;
			
			cambiarVistaPuntos(puntos);
			deshabilitarLinkMeGusta();
			
			$.post($(this).attr('href'), {}, function() {});
			
			event.preventDefault();
			return false;
		});
	}
});
