jQuery(document).ready(function($){
								
//$('div.rightColTable table').tablesorter({sortList: [[0,0]], widgets: ['zebra']});

$("a.[rel^='lightbox']").prettyPhoto({counter_separator_label: ' из '});

$('form.pollForm').submit(function(){
var id = $(this).attr('id');
var answer_id = $("input[name='answer_id']:checked").val();

fixHeight();
$('#showResult').hide();
$('#poll'+id).fadeOut('slow', function() {ajaxVote(id, answer_id);});
return false;
							   
});

function fixHeight() {

	var it = $('#pollWrapper').children();
	it.css({height: it.height()+'px'});
}
function unfixHeight() {
$('#pollWrapper').children().css({height: '100%'});
}


$('.viewresults').click(
		function() {
			options = $(this).attr('id').split('-');
			var id = options[1];
			fixHeight();
			$('#poll'+id).fadeOut('slow', function() {ajaxVote(id, 0);});
		}
);

$('.hideresults').live('click',function() {
			options = $(this).attr('id').split('-');
			var id = options[1];
			fixHeight();
			$('#showResult').hide();
			
			$('#pollResult'+id).fadeOut('slow', function(){unfixHeight(); $('#poll'+id).fadeIn()});
		}
);


function animateBars() {
	$('div.votedBar').each(
		function() {
		var percentage = $(this).children().text();
		$(this).css({width: "0%"}).animate({ width: percentage}, 1500);  
			}
						   );
	
		
}

function ajaxVote (id, answer_id) {
		$.post("/poll",
					{poll_id: id, answer_id: answer_id, subaction: 'ajaxVote'}, 
					function (xml) {
						$('#pollResult'+id).
						html($('return', xml).text()).
						after('<div id="showResult" class="poll-navigation"><input type="button" value="Голосовать" class="hideresults" id="hideresults-'+id+'"/></div>').
						fadeIn('slow' ,function(){ 
												unfixHeight(); 
												animateBars();
												});
					}
			);
			return false;
}

animateBars();





								});
