$(document).ready(function(){
    $(".vote_submit").click(function(){
        var voteitem = $(this).parents(".add_bck_vote");
        var id = voteitem.find("input[type=hidden]").val();
        var v = "";
        voteitem.find("input[type=radio]").each(function(){
          if($(this).attr("checked") == true) {
               v = $(this).val();
          }
        });
        var url = voteitem.find(".vote_title").attr("url");
        $.get(url, {action:"vote", id:id, val:v}, function(data){
            if(data['key'] == "success") {
                voteitem.find(".votecontent2").html(data['value']);
                alert("Sie haben erfolgreich abgestimmt.");
                $(".vote_result").click();
            } else if(data == "error") {
                alert("Bitte wählen Sie eine Antwort.");
            } else if(data == "repeat"){
                alert("Ihre Stimme wurde bereits gezählt.");
            }
        }, "json");

        return false;
    });
    $(".vote_result").click(function(){
        $(this).css("display", "none");
        var voteitem = $(this).parents(".add_bck_vote");       
        voteitem.find(".vote_submit").css("display", "none");
        voteitem.find(".vote_close").css("display", "block");
        voteitem.find(".votecontent1").css("display", "none");
        voteitem.find(".votecontent2").css("display", "block");
        return false;
    });
    $(".vote_close").click(function(){
        $(this).css("display", "none");
        var voteitem = $(this).parents(".add_bck_vote");
        voteitem.find(".vote_submit").css("display", "block");
        voteitem.find(".vote_result").css("display", "block");
        voteitem.find(".votecontent1").css("display", "block");
        voteitem.find(".votecontent2").css("display", "none");
        return false;
    });

});



