$j( document ).ready( function() {
    $j('#product-review-table').each(function() {
        var $ratings_input = $j('input.radio', this);
        $ratings_input.last().attr('checked', 'checked');

        $ratings_slider = $j('<label>Rating</label><span class="ratings-slider"><div class="rating-box"><div class="rating nobr" style="width: 100%"></div></div></span>');

        $ratings_slider.mousedown(function(e) {
            $j(this).data('mouse', true);

            e.type = 'mousemove';
            $j(this).trigger(e);
        }).mouseup(function() {
            $j(this).data('mouse', false);
        }).mousemove(function(e) {
            var x = $j(this).data('mouse');
            if (typeof(x) != undefined && x ) {
                e.layerX = e.layerX || ( e.offsetX )
                var percentage = e.layerX / $j(this).width() * 100.0;
                var clamped = (parseInt(percentage / 20) * 20) + 20;
                $j('.rating', this).css('width', clamped + '%');
                var actual_value = (clamped / 20) - 1;
                $ratings_input.eq(actual_value).attr('checked', 'checked');
            }
        }).hover(function() {
            $j(this).data('mouse', false);
        }, function() {
            $j(this).data('mouse', false);
        });

        $j(this).after($ratings_slider).hide();
    });
});
