function igrica(val) {
    var pitanje = $('#pitanje').val();
    var vrednost = $('#vrednost').val();
    
    if (val != null) {
        var vrednostIns = parseInt(vrednost)+parseInt(val);
        $('#vrednost').val(vrednostIns);
        var pitanjeIns = parseInt(pitanje)+1;
        $('#pitanje').val(pitanjeIns);
    } else vrednostIns = 0;
    
    var igrica = {
        type: "post",
        url: "script.php",
        data:{'function': 'igrica', 'pitanje':pitanje},
        dataType: 'json',
        success: function(data) {
//            alert(data);
            var html = "";
            
            if (data == 'KRAJ') {
                html += "Kraj igrice. Ukupna vrednost: "+vrednostIns+"<br /><br /><a href='#' onclick='igrica(null); return false;' >Igraj ponovo</a>";
                prikaz_slajda (vrednostIns);
                $('#pitanje').val(1);
                $('#vrednost').val(0);
            }
            else {
                html += data.ime_igrice+"<br />";
                html += data.ime_pitanja+" / 10<br />";
                $.each(data.odgovor, function(ime, v) {
                    html += "<a href='#' onclick='igrica("+ v +"); return false;' >"+ime+"<a><br />";
                });
                prikaz_slajda (vrednostIns);
            }
            $('#igrica').html(html);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {alert(textStatus);}
    }
    $.ajax(igrica);
    console.log('igrica();');
}


function prikaz_slajda (val) {
    $("#divSlider").show();
    $("#slider-range-min").slider({
        range: "min",
        disabled: true,
        value: val,
        min: 0,
        max: 100,
        slide: function(event, ui) {
            $("#amount").val(ui.value);
        }
    });
    $("#amount").val($( "#slider-range-min").slider("value"));
}
