var ready= 0;

$(document).ready(function(){

    if (ready==0)
    {
        // No demon
        $.get('/pl/poll/index/index',null, function(data){
            if (!data) return false;
            var poll = $(data);
            $('#poll_question').text(  poll.find('[for="poll_answers"]').text() );
            poll.find('[for="poll_answers"]').remove();
            $('<input type="image" style="margin-top: 20px;" src="/layouts/tm/img/glosuj.jpg"/>').insertAfter(poll.find('[id="vote_add"]'))
            if (poll.find('[id="vote_add"]').length) {
                poll.find('label').css('white-space', 'normal');
                poll.find('[id="vote_add"]').remove();
                poll.children(':last').addClass('sonda');
            }
            $('#poll').append(poll);
        }, 'html');
    
    	$('#vote_form').livequery(function(){
    		$(this).submit(function(){
    			var value= $(':checked',this).val();
    			var a_url= $(this).attr('action');
    			
    			$.ajax({
    				type: 'post',
    				url: a_url,
    				data: 'poll_answers='+value,
    				dataType: 'html',
    				success: function(t)
    				{
                        $('#vote_form').prev().remove();
                        $('#vote_form').prev().remove();
    					$('#vote_form').parent().append(t);
    				   	$('#vote_form').remove();	
    				}
    			});
    			
    			return false;
    		});
    	});
    }
	ready=1;
	
});

