jQuery(document).ready(function(){
	jQuery(".tx-jkpoll-pi1 .counterWrapper").hide();
	jQuery(".tx-jkpoll-pi1 .counter").hide();
	
	jQuery(".tx-jkpoll-pi1 .submit").click(function(){
		
		var doSubmit = false;
		jQuery(".tx-jkpoll-pi1 .submitRow").each(function(){
			if (jQuery(this).hasClass('checked')) {
				doSubmit = true;
			}	
		});	
		if (doSubmit == true) {
			tx_jkpoll_pi1processFormData(xajax.getFormValues('mg_poll_ext_form'));
		}
	
	});
	
		
	
	
	

	jQuery('#mg_poll_ext_form .submitRow').mouseover (
		function() {
			jQuery(this).addClass("hover");
	
	
		}
	);
	jQuery('#mg_poll_ext_form .submitRow').mouseout (	
		function () {
			jQuery(this).removeClass("hover");
		}
	);
	
	
	jQuery('#mg_poll_ext_form .submitRow').click(function(){
	
		selected = jQuery(this).children().next().find("input").val();
		
		document.getElementsByName("tx_jkpoll_pi1[answer]")[0].value = selected;
		if (jQuery(this).hasClass('unchecked')) {
			jQuery(this).addClass('checked');
			jQuery(this).removeClass('unchecked');
			jQuery(this).children().next().find("img").attr('src', mg_poll_ext_imagePath + 'checkbox_checked.gif');
			
		} else {
			jQuery(this).addClass('unchecked');	
			jQuery(this).removeClass('checked');	
			jQuery(this).children().next().find("img").attr('src', mg_poll_ext_imagePath + 'checkbox_unchecked.gif');
		}
	  
		jQuery('#mg_poll_ext_form .submitRow').not(jQuery(this)).each(function(){
			jQuery(this).addClass('unchecked');
			jQuery(this).removeClass('checked');
			jQuery(this).children().next().find("img").attr('src', mg_poll_ext_imagePath + 'checkbox_unchecked.gif');
		});
	});
});


function showTheCounter() {
	jQuery("#formResult").hide();
	
	jQuery(".tx-jkpoll-pi1 .counterWrapper").fadeIn(1000, function() {
		initCounter();
		jQuery(".tx-jkpoll-pi1 .counter").fadeIn(1000, function(){
		
		})
	});
	
	setTimeout("fadeOutCounter()", 3500);
	
	
}

function fadeOutCounter() {
	jQuery(".tx-jkpoll-pi1 .counter").fadeOut(750, function () {
		jQuery(".tx-jkpoll-pi1 .counterWrapper").fadeOut(750, function () {
			jQuery(".tx-jkpoll-pi1 #formResult").fadeIn(750, function(){
				animateResults();
			});
			
		});
		
	});
	jQuery(".tx-jkpoll-pi1 .VotingFooter .submit").hide();
}
function animateResults(){
	
	jQuery(".tx-jkpoll-pi1 .VotingResult div.res").each(function(){
	  
      var percentage = jQuery(this).children().val();
	  
	  jQuery(this).css({width: "0%"}).animate({
				width: percentage}, 1000);
  });
}

xajax.doneLoadingFunction = showTheCounter;

