$(function () {
    function activateRating(root)
    {       
        root.find(".star").click(function () {
            var self = $(this)
            var form = self.parents(".rating")
            postData = {ajax: 1}
            postData[self.attr("name")] = self.val()
            $.post(form.attr("action"), postData, function (htmlData) {
                form.html(htmlData)
                activateRating(form)
            })
    
            return false
        })
        
        root.find(".star").mouseenter(function () {
            var self = $(this)
            
            self.prevAll(".star").andSelf().removeClass("inactive").addClass("active")
            self.nextAll(".star").removeClass("active").addClass("inactive")
        })
        
        
        root.find(".rating").mouseleave(function () {
            var self = $(this)
            self.find(".star").removeClass("active").removeClass("inactive")
        })
    }
    
    activateRating($(document))
})
