$(document).ready(function(){
	$("a.vote").click ( function () {
		id = $(this).attr("rel");
        $(this).parent().addClass("value_ok");
		elem = $(this);
		$.getJSON('/news_rate_gate.php?id='+id, {}, function(json){
	        $(elem).html('+'+json.val);
        });

        return false;
	});

	$("a.trust_link").click ( function () {
		id = $(this).attr("rel");
		elem = $(this);
		if ($(elem).parent().hasClass("green"))
			a_elem = $(elem).parent().parent().find("div.red a");
		else
			a_elem = $(elem).parent().parent().find("div.green a");
		$.getJSON('/news_rate_gate.php?id='+id, {}, function(json){
	        $(elem).html(json.val);
        });

        return false;
	});

	$("a.trust_list").click ( function () {
		id = $(this).attr("rel");
		elem = $(this);
		repl = $(elem).parent().parent();
		r_elem = $(elem).parent().find("div.val");
		if ($(elem).parent().hasClass("green")) {
			a_elem = $(elem).parent().parent().find("div.red a");
			red = $(a_elem).html();
			green = 0;
		}
		else {
			a_elem = $(elem).parent().parent().find("div.green a");
			red = 0;
			green = $(a_elem).html();
		}
		$.getJSON('/news_rate_gate.php?id='+id, {}, function(json){
	        $(elem).html(json.val);
	        $(r_elem).html(json.val);
	        if (!red)
	        	red = $(elem).html();
	        else
	        	green=$(elem).html();

        });

        return false;
	});

});

