$('form.rating').ready(function(){
    $('input.rating-submit').hide();
    $('ul.rating li select.choose-rating').each(
        function(n,slc){
            li = $(slc).parents()[0];
            $(li).stars({ 
                inputType: "select",
                split:2,
                oneVoteOnly:true,
                callback:function(ui, type, value) {
                   form = ui.element.parents('form' )[0];
                   film_id = $(form).find('input[name="film_id"]')[0];
                   $.post( location.href,{'user_rating':value, 'film_id':film_id.value }, function(resp){
                   
                   var current_rating = $(form).find('li.current')[0];
                   $(current_rating).stars("select",resp );
                   // If this film is unrated so far...
                   var message = $(form).find('li.current em')[0];
                   if (message) {
                           $(message).html('<strong>Thanks!</strong>');
                   } else {
                       // update the numbers of votes
                       var current_count = $(form).find('span.vote-count')[0];
                       var with_brackets = current_count.firstChild.nodeValue;
                       var number = parseInt(with_brackets.replace('(','').replace(')',''));
                       var incremented = number + 1;
                       current_count.innerHTML= '('+incremented +')';
                   }
                   } );
                   

                }
        });

    
    });
        $('ul.rating li select.current-rating').each(
            function(n,slc) {
            li = $(slc).parents()[0];
                $(li).stars({ 
                    inputType: "select",
                    split:2
                });
            });
});