
$(document).ready(function() {
$("[id^=rating_]").each(function () {
	jQuery.data(this, 'default', $(".hover", this).length);
});

$("[id^=rating_]").hover(function() {
	var rate = this;
	
	$("img", this).hover(function () {
		$(".hover",rate).removeClass("hover");
		$(this).addClass("hover");
		$("img",rate).each(function (i) {
			if ($(this).hasClass("hover")) {
				return false;
			} else {
				$(this).addClass("hover");
			}
			
		});

	}, function () {});
}, function () {
	$(".hover", this).removeClass("hover");
	var begin_rate = jQuery.data(this, 'default');
	var def_rate = begin_rate;

	$("img",this).each(function (i) {
		if (begin_rate+2 > i) {
			$(this).addClass("hover");
			begin_rate--;
			
		}
		if(i == def_rate-1) {
		$(this).addClass("hover");
		return false;}
	});
});


	$("[id^=rating_]").children("[class^=star_]").click(function() {

		
		var current_star = $(this).attr("class").split("_")[1];
		var rid = $(this).parent().attr("id").split("_")[1];

		$('#rating_'+rid).load('send.php', {rating: current_star, id: rid});

	});
	

});




