﻿$(function() {
    $('.stars li').click(function() {

        $this = $(this);
        $parent = $this.parent();

        var score = $this.attr('score');
        var id = $parent.attr('id');
        $.getJSON('/contenttools/rate', { ratingKey: id, score: score },
            function(response) {
                if (response != false) {
                    $parent.children().remove();
                    for (var i = 1; i <= 5; i++) {
                        if (i <= response)
                            $parent.append($.format('<li score="{0}">*</li>', response));
                        else
                            $parent.append($.format('<li class="empty" score="{0}">*</li>', i));
                    }
                }
                else {
                    location.href = '/giris?redirectUrl=' + location.href;
                }
            }
        );
    });
});