var starSize = 30;
var submitPath = "./SubmitRating.axd";

$(document).ready( function(){ setup(); });

function setup(){
	$('li.star-holder').click( selectStar );
	
	try{
		$.each( votes, function( id, votes ){ 
			$('#' + id ).children('#1').setVoted( votes );
		});
	} catch( e ){};
}

function selectStar(){
	$(this).setVoted( $(this).attr('id') );
	$(this).submitVote();
}

jQuery.fn.extend({
	setVoted: function( number ){
		$(this).siblings('.current-rating').css( 'width', (number * starSize) + "px" );
		$(this).siblings('.current-rating').css( 'background', 'transparent url(./assets/images/star_rating.gif) repeat scroll left center' );
		$(this).parent().children('.star-holder').unbind( 'click', selectStar );
		$(this).parent().children().html('&nbsp;');
	},
	submitVote: function(){
		$.ajax({type: "POST", url: submitPath, data: "GID=" + $(this).parent().attr( 'id' ) + "&V=" + $(this).attr( 'id' )});
	}
});