votingStarted = false

function toggleMore()
{
    var txt = $('.mainfo-collapse');
    if (txt.css('height') != 'auto')
    {
        txt.css('height', 'auto');
        $('.mainfo').css('height', 'auto');
        $('.mainfo .text-i > p').removeClass('more').addClass('less').find('a').html('<span />скрыть');
    }
    else
    {
        txt.css('height', '256px');
        $('.mainfo').css('height', '294px');
        $('.mainfo .text-i > p').removeClass('less').addClass('more').find('a').html('<span />подробнее');
    }
    return false;
}


function submitVote() {
    if (votingStarted) return false;
    
    var query = "";
    $("#votingform input.jNiceHidden").each(function(i, item) {
        if ($(item).attr("checked")) query += "&answer=" + $(item).val();
    });
    
    votingStarted = true;

    $(".vote").html('<img src="/images/ajax/vote.gif" alt="..." width="28" height="28" />');

    query = "?vote=" + $("#votingform input[name=question]").val() + query;
    $.getJSON("/json/vote/vote/" + query, processVote);

    return false;
}

function processVote(data) {
    if (data.error) {
        votingStarted = false;
    }
    
    $("#votingform *").remove(); 
    $("#votingform").html('<p class="question">' + data.question + '</p>');
    if (data.message) $("#votingform").append($("<p />").html(data.message));
    
    if (data.cookie) {
        var cookie = ""; cookie = readCookie("votes");
        if (cookie != "" && cookie != null) cookie += "&"; else cookie = "";
        cookie += data.cookie;
        createCookie("votes", cookie, 365);
    }

}

function voteResults(id) {
    $("#vote").addClass("ajax");
    $.getJSON("/json" + voteAction + "?results=" + id, processVote);
    return false;
}

