$(function(){
		$('.rating, .rating_un').width(rating*20);
		//insert stars 
		for(i=1;i<=10;i++) {
			$('.rating').after('<a class="star"></a>');
		}
		//style voting stars
		stars_no = 1;
		 $(".star").each(function (i) {
		   var stars_no = i + 1;
		   $(this).css('left', (i * 20) +'px');
		   $(this).hover(
		   		function() {
		   		  $(this).css('background', 'url(images/stars.gif) 0px -60px no-repeat');
		   		  $(this).prevAll('a').css('background', 'url(images/stars.gif) 0px -60px no-repeat');
		   		},
		   		function() {
		   		  $(this).css('background', 'url()');
		   		  $(this).prevAll('a').css('background', 'url()');
		   		}
		   );
		   //vote
		   $(this).click(
		     	function() {
		     	  	user_rating = stars_no;
		     	  	//remove voting from higher stars
		     	  	$('.rating_user').width(user_rating*20);
		     		$(".stars_user").show();
		     		//copy <a> to lower stars
		     		$('.stars a').css('background', 'url()').insertAfter('.rating_user');
		     		$('.stars a').remove();
		     		//send AJAX request
		     		$.ajax({
					   type: "POST",
					   url: "vote.php",
					   cache: false,
					   data: "id="+id+"&vote="+user_rating,
					   success: function(msg){
					     $("#vote_results").html(msg);
					   }
					 });
		   		}
		   );
      	});
	}
	);

