/**
 * VOTE Functions
 * 
 * @package RadioPetrov.com  
 */ 
 
$(document).ready(function() {

	// Odeslání hlasu ankety.
	$('.bot_opinion_but').click(function() {
		var pollId = $(this).attr('id').replace(/bot_opinion_but_/i, '');
		$.get('/vote.php', 
				{	type: $('#bot_opinion_type_'+pollId).val(), 
					id: pollId, 
					vote: $("*[@name=bot_opinion_rad_"+pollId+"]:checked").val(),
					flash: '0' },
				function(xml) {
					// Zpracování XML odpovědi.
					var vote = xml.getElementsByTagName('vote');
					var result = xml.getElementsByTagName('result');
					var message = xml.getElementsByTagName('message');
					var percent = xml.getElementsByTagName('percent');
					var width = xml.getElementsByTagName('width');
					
					if(result[0].firstChild.data == '1') {
						/*
						// Zvýšení počtu hlasů u hlasované možnosti o 1
						$('#bot_opinion_r_'+vote[0].firstChild.data).attr('innerHTML', Number($('#bot_opinion_r_'+vote[0].firstChild.data).attr('innerHTML')) + 1);
						*/
						
						// Změna procent u jednotlivých možností
						for(i = 0; i < percent.length; i++) {
							$('#bot_opinion_p_'+percent[i].attributes.getNamedItem('id').value).html(percent[i].firstChild.data);
						}						
						
						// Změna šířek "ukazatelů" možností
						for(i = 0; i < width.length; i++) {
							$('#bot_opinion_l_'+width[i].attributes.getNamedItem('id').value).css({'width': width[i].firstChild.data + 'px'});
						}
						
						// Zakázat elementy hlasování
						$("*[@name=bot_opinion_rad_"+pollId+"]").attr('disabled', true);
						$("*[@name=bot_opinion_but_"+pollId+"]").css({'display': 'none'});
						
						// Zpráva
						alert(message[0].firstChild.data);
					} else {
						alert(message[0].firstChild.data);
					}
				}
		);		
		
	});
	
});