$(document).ready(function(){
 	$("a.vote_up").click(function(){
	the_id = $(this).attr('id');
		
	$(this).parent().html("<img src='http://fun.jclevel.com/images/spinner.gif'/>");
	$("span#votes_count"+the_id).fadeOut("fast");		
		
		
		$.getJSON("http://fun.jclevel.com/votes.php?action=vote_up&id="+$(this).attr("id"),
		function(data)
			{			    				
				if(data.error == '0')
				  {
				   $("span#votes_count"+the_id).html(data.num_votes+" голосов(а)");
				   $("span#votes_count"+the_id).fadeIn();		
				   $("span#vote_buttons"+the_id).remove();
				  };
				if(data.error == '1')
				{
				 $("span#votes_count"+the_id).html(data.num_votes+" голосов(а)");				 
				 $("span#votes_count"+the_id).fadeIn();		
				 $("span#vote_buttons"+the_id).remove();   
                 $.jGrowl.defaults.closerTemplate = '<div>Закрыть все окна</div>';				 
				 $.jGrowl("Ваш голос не учтен. С вашего ip - "+data.ip+" голосование проходило.", { header: 'Внимание!', theme: 'manilla', life: 5000});
				};
				
			}
		);	
		
		
	});
	
	$("a.vote_down").click(function(){
	the_id = $(this).attr('id');

	$(this).parent().html("<img src='http://fun.jclevel.com/images/spinner.gif'/>");
	$("span#votes_count"+the_id).fadeOut("fast");	
	
	
		$.getJSON("http://fun.jclevel.com/votes.php?action=vote_down&id="+$(this).attr("id"),			
		  function(data)
			{
				if(data.error == '0')
				  {				   
				   $("span#votes_count"+the_id).html(data.num_votes+" голосов(а)");
				   $("span#votes_count"+the_id).fadeIn();		
				   $("span#vote_buttons"+the_id).remove();
				  };
				if(data.error == '1')
				{
				 $("span#votes_count"+the_id).html(data.num_votes+" голосов(а)");				 
				 $("span#votes_count"+the_id).fadeIn();		
				 $("span#vote_buttons"+the_id).remove();	 
                 $.jGrowl.defaults.closerTemplate = '<div>Закрыть все окна</div>';				 
				 $.jGrowl("Ваш голос не учтен. С вашего ip - "+data.ip+" голосование проходило.", { header: 'Внимание!', theme: 'manilla', life: 5000});
				};				
			}
		);
		
	
	});
});	
