jQuery.fn.rating = function( rating_class , number_of_stars , callback ) {
    return this.each( function () {
        $(this).addClass( rating_class ).append( "<span class=\"bg\" />" );

        if( callback )
        {
            var w = $(this).addClass( "change" ).width();
            var _this = this;

            for( var cn = 1; cn<=number_of_stars; cn++ )
            {
                var s = document.createElement( "span" );
                s.className = "rating";
                s.rating_value = cn;
                s.style.left = "" + ( ( cn - 1 ) * ( w / number_of_stars ) ) + "px";
                s.appendChild( document.createTextNode( "" + cn ) );
                this.appendChild( s );

                $(s).click( function() { callback.apply( _this , [ this.rating_value ] ); } );

                $(s).hover(
                    function () { $(this).addClass( "hover_rating" ); } ,
                    function () { $(this).removeClass( "hover_rating" ); }
                );
            }
        }

        $(this).append( "<span class=\"value\" />" );
        this.number_of_stars = number_of_stars;
    } );
}

jQuery.fn.set_rating = function( value ) {
    return this.each( function () {
        var w = $(this).width();

        $(this).children( ".bg" ).css( "width" , "" + ( w * 1.0 * value / this.number_of_stars ) + "px" );

        if( value == 0 )
            $(this).children( ".value" ).html( "--.--" );
        else
            $(this).children( ".value" ).html( Math.round( value * 100 ) / 100 );
    } );
}

