$(document).ready(function(){

    $("#dialog_c").dialog({ 
        bgiframe: true,
        modal: true, 
        autoOpen: false,
        title: "Informacja",
        overlay: { 
            opacity: 0.5, 
            background: "#ffcc00" 
        },
        buttons: { 
            "Okay": function(e) { 
                $(this).dialog("close");
                return true;
            }
        }
    });

    $('.hover-star').rating({
        required: true,
        focus: function(value, link){
            var tip = $('#rating-info-hit');
            tip[0].data = tip[0].data || tip.html();
            tip.html('' + value);
        },
        blur: function(value, link){
            var tip = $('#rating-info-hit');
            $('#rating-info-hit').html(tip[0].data || '');
        },
        callback: function(value, link){
            $.post(
                "/ajax/hit_vote", 
                {
                    hit_id: $("#hit_id").val(), 
                    value: value 
                },
                function(data) {
                    if (data.status == "ok")
                    {
                    }
                    else if (data.status == "already_voted")
                    {
                        alert("Już oceniałeś ten przebój.");
                    }
                    else
                    {
                        alert("Jakiś błąd się trafił... Sorry!");
                    }
                    $("#hit-rating").text(data.rating);
                    $("#hit-count").text(data.count);
                },
                "json"
            );
        }
    });
});
