$(document).ready(function(){

  $("#voto_positivo a").click(votarPositivo);
  $("#voto_negativo a").click(votarNegativo);  
  
  
	function votarPositivo(){
		valor = $(this).parent().parent().attr('id');
		if(!$.cookie(valor)){
			votarGuarda(valor, 'positivo');
		}else{
			alert ('El usuario ya ha valorado el contenido previamente');
		}
		return false;
	}  
	
	function votarNegativo(){
		valor = $(this).parent().parent().attr('id');
		if(!$.cookie(valor)){
			votarGuarda(valor, 'negativo');
		}else{
			alert ('El usuario ya ha valorado el contenido previamente');
		}
		return false;
	} 
	
	function votarGuarda(id, tipo){
		$.ajax({
			async:true,
			type: "POST",
			dataType: "html",
			url:"include/proceso_votacion.php",
			data: "id=" + id + "&tipo=" + tipo,
			success: votarMostrar

		}); 		
	} 
function votarMostrar(datos){
	id = (datos).split('@')[0];
	pos = (datos).split('@')[1];
	neg = (datos).split('@')[2];
	tot = (datos).split('@')[3];
	
	$("#positivo_" + id).html('+'+pos);
	$("#negativo_" + id).html('-'+neg);
	$("#total_" + id).html(tot+' Votos');
	
	$.cookie(id, '1');
}
  
});
