$(document).ready(function(){
	if ($("a.vote_up").length && $("a.vote_down").length) {
		$("a.vote_up").click(function(){
			the_id = $(this).attr('id');
			the_count = parseInt($("span#votes_count"+the_id).text());
			
			$.ajax({
				type: "POST",
				url: "/ajax/voteUp",
				data: "id="+the_id,
				success: function(msg) {
					if (msg.success) {
						$("span#votes_count"+the_id).text(the_count+1);
					} else {
						if (msg.reason == 'login') {
							alert('Please login to vote');
						}
					}
				}
			});
		});
		
		$("a.vote_down").click(function(){
			the_id = $(this).attr('id');
			the_count = parseInt($("span#votes_count"+the_id).text());
			
			$.ajax({
				type: "POST",
				url: "/ajax/voteDown",
				data: "id="+the_id,
				success: function(msg) {
					if (msg.success) {
						$("span#votes_count"+the_id).text(the_count-1);
						$(this).css('color','#333333');
					} else {
						if (msg.reason == 'login') {
							alert('Please login to vote');
						}
					}
				}
			});
		});
	}
});
