$.fn.rating = function(counter){

	object = $(this).attr('alt');
	returnHTML = '';

	for(ss=1; ss<=counter; ss++)
	{
		returnHTML += '<div class="star" value="'+ss+'"></div>';
	}


	$(this).html(returnHTML);
	$(this).children('.star').mouseover(function() { 
		value = $(this).attr('value');
	
		$(this).parent().children().each(function(i) {
			if(i+1 <= value)
			$(this).css('backgroundPosition', '100% 0px');
		})	
		
		return false;
	});

	$(this).children('.star').mouseout(function() { 
		value = $(this).attr('value');
	
		$(this).parent().children().each(function(i) {
			$(this).css('backgroundPosition', '0px 0px');
		})	
		
		return false;
	});


	$(this).children('.star').click(function() { 
		value = $(this).attr('value');
	
		$(this).parent().children().unbind('mouseout').unbind('mouseover').unbind('click');
		$(this).parent().parent().before('<p class="voted">Zapisywanie...</p>').prev().fadeOut('slow');
		
		$.ajax({   
			type: "POST",   
			url: "/extras/rating.php",  
			data: 'rating='+value+'&object='+object,   
			success: function(html)
			{  
				$('.stars').fadeOut().parent().before().html('<span class="name">Ocena:</span> '+html);
			}
				 
		});

		return false;
	});
	
}