$(document).ready(function() {
    $(".javascript-on").css({ display: "block" });
});
function goAddress() {
    if ($('select#address')[0].options[$('select#address')[0].selectedIndex].value) { location.href='http://' + $('select#address')[0].options[$('select#address')[0].selectedIndex].value }
}
function doVote() {
    var action = '/json/vote';
    if ($("form#vote_form input[type=radio]:checked").val()) {
        $("#vote_form .ajax").show();
        $.getJSON(action + '?process=1&vote=' + $("form#vote_form input[type=radio]:checked").val(), null, buildVoteResults);
    }
}
function buildVoteResults(data) {
    $("#vote_form .ajax").hide();
    if (!(data.thanks || data.vote_answers)) return;
    $("#vote_form").remove();
    
    if (data.thanks) {
        $("<p />").html("Спасибо, Ваш голос принят").appendTo("#poll");
        return;
    }
    
    var div = $("<div />").appendTo("#poll");
    $('#poll').addClass('poll_result');
    $.each(data.vote_answers, function(i,item) 
    {
        $("<h4 />").html(item.answer).appendTo(div);
        $("<div />").attr({ "class": "result "+(item.best ? 'res_red' : ''), "style":"width:"+(item.per_ans < 18 ? '18' : item.per_ans)+"%" }).html('<div><div><div><img src="/images/spacer.gif" width="1" height="1" alt="" /></div></div></div>').appendTo(div);
        $("<p />").html(item.per_ans+"% ("+item.cnt_ans+")").appendTo(div);
    });
}

