function fmtvote( x ) {
	if ( x>0 ) {
		return x+".0/5.0";
	} else {
		return "";
	}
}
var clicked=false;
$(document).ready(function(){
	$("ul#starrating a")
	.hover(function(){
		var vote = $(this).attr("className").match( /\d+$/ );
		if ( !clicked )
			$("div#ratingstatus").html( fmtvote(vote) );
	},function(){
		if ( !clicked )
			$("div#ratingstatus").html( fmtvote( $("div#ratingstatus").attr("rel") ) );
	})
	.click(function(){
		$(this).blur();
		clicked=true;
		var mid = $("ul#starrating").attr("className").match( /\d+$/g );
		var vote = $(this).attr("className").match( /\d+$/ );

		$("div#ratingstatus").html( "submitting vote.." );
		$.post("/ajax", { mid: mid, vote: vote, action: "vote" }, function(data){
			if ( data == "-1" ) {
				$("div#ratingstatus").html( "you must be logged in to rate" );
			} else {
				$("div#ratingstatus").html( "vote registered, thank you" );
				$("li#currentrating").css("width", ( ( parseInt(data) ) * 16 )+'px' );
			}
		} );
	});		
});
