function votePost(action,now,grade,post_id) {	
	$('#'+ post_id +' > .now').html(now+grade);
	$('#'+ post_id+' > .plus').hide();
	$('#'+ post_id+' > .minus').hide();	
	$('#'+ post_id).unbind('mouseenter mouseleave');	
	var post_id_int = parseInt(post_id.split('_')[1]);
	var params = {};
	params.grade = grade;
	params.blog_post_id = post_id_int;
	params.user_id = user_id;
	jQuery.get(
		'/gradeblogpost/' + action + '/', 
		params, 
		function(json){}, 
		'json'
	);
}

function drawPostRate(post_id, now, action, israte, auth) {	
	var html='';
	var red='';
	var post_id_int = parseInt(post_id.split('_')[1]);
	
	if (now<0) {
		red=' red';
	}
	
	html = 
		'<div id="'+ post_id +'" class="vote fleft">' + 
			'<div class="plus"><a href="javascript://" onclick="votePost(\''+ action +'\','+ now+', 1, \''+ post_id +'\')">+</a></div>'+
			'<div class="minus"><a href="javascript://" onclick="votePost(\''+ action +'\', '+ now+', -1, \''+ post_id +'\')">&ndash;</a></div>'+
			'<div class="now'+ red+'">'+ now +'</div>'+
		'</div>';
	
	document.write(html);
	
	if ((israte < 1)&&(auth == 1)) {
		$('#'+ post_id).hover(
			function () {
				$('#' + this.id + ' > .plus').animate({"top": "-=18px"}, "fast");
				$('#' + this.id + ' > .minus').animate({"top": "+=19px"}, "fast"); 
			},
			function() {
				$('#' + this.id + ' > .plus').animate({"top": "+=18px"}, "fast");
				$('#' + this.id + ' > .minus').animate({"top": "-=19px"}, "fast"); 
			}
		);
	};
}

function voteCom(action,now,grade,comment_id) 
{
	$('#'+ comment_id +' > .now').html(now+grade);
	$('#'+ comment_id+' > .plus').hide();
	$('#'+ comment_id+' > .minus').hide();
	
	$('#'+ comment_id).unbind('mouseenter mouseleave');
	
	var comment_id_int = parseInt(comment_id.split('_')[1]);
	var params = {};
	params.grade = grade;
	params.comment_id = comment_id_int;
	params.user_id = user_id;
	jQuery.get(
		'/gradecomment/' + action + '/', 
		params, 
		function(json){}, 
		'json'
	);
}
  	

function drawComRate(comment_id, now, action, israte) {
	var html='';
	var red='';
	var comment_id_int = parseInt(comment_id.split('_')[1]);
	
	if (now<0) {
		red=' red';
	}
	
	html = 
		'<div id="'+ comment_id +'" class="vote">' + 
			'<div class="plus"><a href="javascript://" onclick="voteCom(\''+ action +'\','+ now+', 1, \''+ comment_id +'\')">+</a></div>'+
			'<div class="minus"><a href="javascript://" onclick="voteCom(\''+ action +'\', '+ now+', -1, \''+ comment_id +'\')">&ndash;</a></div>'+
			'<div class="now'+ red+'">'+ now +'</div>'+
		'</div>';
	
	document.write(html);
	
	if (israte < 1) {
		$('#'+ comment_id).hover(
			function () {
				$('#' + this.id + ' > .plus').animate({"top": "-=18px"}, "fast");
				$('#' + this.id + ' > .minus').animate({"top": "+=19px"}, "fast"); 
			},
			function() {
				$('#' + this.id + ' > .plus').animate({"top": "+=18px"}, "fast");
				$('#' + this.id + ' > .minus').animate({"top": "-=19px"}, "fast"); 
			}
		);
	};
}

function drawDescriptionRate(comment_id, now, action, israte) {
	var html='';
	var red='';
	var comment_id_int = parseInt(comment_id.split('_')[1]);
	
	if (now<0) {
		red=' red';
	}
	
	html = 
		'<div id="'+ comment_id +'" class="vote">' + 
			'<div class="plus"><a href="javascript://" onclick="voteCom(\''+ action +'\', '+ now+', 1, \''+ comment_id +'\')">+</a></div>'+
			'<div class="minus"><a href="javascript://" onclick="voteCom(\''+ action +'\', '+ now+', -1, \''+ comment_id +'\')">&ndash;</a></div>'+
			'<div class="now'+ red+'">'+ now +'</div>'+
		'</div>';
	
	//alert(html);
	
	//document.write(html);
	$('#descr_block_' + comment_id_int).html(html);
	
	if (israte < 1) {
		$('#'+ comment_id).hover(
			function () {
				$('#' + this.id + ' > .plus').animate({"top": "-=18px"}, "fast");
				$('#' + this.id + ' > .minus').animate({"top": "+=19px"}, "fast"); 
			},
			function() {
				$('#' + this.id + ' > .plus').animate({"top": "+=18px"}, "fast");
				$('#' + this.id + ' > .minus').animate({"top": "-=19px"}, "fast"); 
			}
		);
	};
}
