/**
 * @author anthonysapp
 */
var poll;
var inputs;
var voteBtn;
var flash;
var answer = null;
var errorshowing = false;
var answerTitle = new Array(
		"Il est clair que vous avez la s&eacute;curit&eacute; &agrave; l&rsquo;esprit,<br/>mais ce que vous devriez faire c&rsquo;est...",
		"Bien fait. C&rsquo;est toujours bon de...",
		"Mauvaise id&eacute;e. Vous seriez mieux de...");
var answerDesc = new Array(
		"Incitez votre amie &agrave; se rafra&icirc;chir en prenant une boisson sans alcool. L&rsquo;alcool affecte la capacit&eacute; de prendre des d&eacute;cisions et peut nuire &agrave; la motricit&eacute;. L&rsquo;alcool et la nage ne font pas bon m&eacute;nage.",
		"Incitez votre amie &agrave; se rafra&icirc;chir en prenant une boisson sans alcool. L&rsquo;alcool affecte la capacit&eacute; de prendre des d&eacute;cisions et peut nuire &agrave; la motricit&eacute;. L&rsquo;alcool et la nage ne font pas bon m&eacute;nage.",
		"Incitez votre amie &agrave; se rafra&icirc;chir en prenant une boisson sans alcool. L&rsquo;alcool affecte la capacit&eacute; de prendre des d&eacute;cisions et peut nuire &agrave; la motricit&eacute;. L&rsquo;alcool et la nage ne font pas bon m&eacute;nage.");
var positions = new Array( {
	height : 320,
	top : -30
}, {
	height : 300,
	top : -20
}, {
	height : 300,
	top : -20
});
var flashAnswers = new Array(-1, 1, -1);

var ctaPush = {
	title : "Soyez un h&ocirc;te responsable cet &eacute;t&eacute;.",
	body : "Soyez un h&ocirc;te hors pair. Veillez &agrave; ce que vos invit&eacute;s aient du plaisir en toute s&eacute;curit&eacute; cet &eacute;t&eacute;. Et rappelez-vous que l&rsquo;alcool au volant, c&rsquo;est trop gros pour &ecirc;tre ignor&eacute;. Prenez la parole, vous pourriez sauver une vie.",
	button : "images/more_hosting_tips_btn.gif",
	href : "host_with_the_most.html",
	height : 120,
	top : 50
}
function alert(){}
function ctaLink(href) {

	$('#animate_window').blur();
	$('#poll_container').blur();
	$('#animate_window').css( {
		display : 'none',
		top : '-349px'
	});
	$('#poll_container').css( {
		top : '-225px'
	});
	$('#animate_container').css('overflow', 'hidden');
	window.location = href;
}
function refreshPage() {
	location.reload(true);
}

function cta() {
	if (isIE == false) {
		ctaAnimate();
	} else {
		fillCtaPush();
	}
}
function ctaAnimate() {
	$('#poll_container_content').animate( {
		opacity : '0'
	}, 300, 'easeInSine', function() {
		fillCtaPush(true);
	}).animate( {
		height : ctaPush.height
	}, 300, 'easeOutSine').delay(1000).animate( {
		opacity : 1
	}, 300, 'easeOutSine');

	$('#poll_container').delay(300).animate( {
		top : ctaPush.top
	}, 300, 'easeOutSine');
}
function fillCtaPush(tweening) {
	flash = getMovie('headerContent');
	$('.PDS_Poll').css('display', 'none');
	$('#cta_button').css('display', 'block');
	$('#polldaddy_container').css('display', 'none');
	$('#poll_top_content > h2').html(ctaPush.title);
	$('#poll_top_content > p').html(ctaPush.body)
	$('#cta_button').html(
			"<a onClick=ctaLink('" + ctaPush.href + "')><img src='"
					+ ctaPush.button + "' style='border:none;'/></a>");
	if (tweening != true) {
		$('#poll_container').css('top', ctaPush.top);
		$('#poll_container_content').css('height', ctaPush.height + 5);
	}
	flash.showTryAgainButton();
}
$(document)
		.ready(
				function() {
					$('#continue_button').hide();
					var optionClasses = new Array('option_one', 'option_two',
							'option_three');
					var i = 0;
					$('.pds-input-label').each(function() {
						$(this).addClass(optionClasses[i]);
						i++;
					})

					poll = $('#PDI_container3436122');
					inputs = new Array();
					
					$('.pds-answer-input').each(function() {
						inputs.push($(this));
						$(this).click(function() {
							inputClickHandler($(this));
						});
						
					});

					$('.pds-vote-button').click(function() {
						voteClickedHandler($(this));

					});

					function voteClickedHandler(e) {
						// console.log('voted ' + answer);
						if (answer == null) {
							if ($('.poll_error').length == 0) {
								$('.pds-vote')
										.append(
												"<span class='poll_error'>S'il vous pla&icirc;t, s&eacute;lectionnez une r&eacute;ponse</span>");
							}
							if (errorshowing == true) {
								return;
							}
							errorshowing = true;
							$('.poll_error').hide().fadeIn('slow').delay(5000)
									.fadeOut('slow', function() {
										errorshowing = false;
									});
							return;
						}
						flash = getMovie('headerContent');
						flash.vote_chosen(flashAnswers[answer]);
						if (isIE == false) {
							$('.pds-vote-button').css('display', 'none')
							
							$('#poll_container_content').animate( {
								opacity : '0'
							}, 300, 'easeInSine', setAnswers).animate( {
								height : positions[answer].height
							}, 300, 'easeOutSine').delay(1000).animate( {
								opacity : 1
							}, 300, 'easeOutSine')
							$('#continue_button').delay(2300).fadeIn();
							$('#poll_container').animate( {
								top : positions[answer].top
							}, 300, 'easeOutSine');
						} else {
							$('#poll_top_content > h3').remove();
							$('#poll_container_content').css ('height',positions[answer].height+10 );
							$('#poll_top_content > h2').css('font-weight',
									'bold');
							$('#poll_top_content > h2').html(
									answerTitle[answer]);
							$('#poll_top_content > p').html(answerDesc[answer]);
							$('#answer_blurb')
									.html(
											"<strong>Voici de quelle fa&ccedil;on d&rsquo;autres personnes ont essay&eacute; de d&eacute;gonfler l&rsquo;&eacute;l&eacute;phant :</strong>");
							$('#poll_container').css('top',
									positions[answer].top);
							setAnswers();
							$('#continue_button').show();
							$('#poll_container_content').css('opacity', 1);
						}
					}

					function setAnswers() {
						$('#polldaddy_container').css('margin-top', '10px');
						$('#polldaddy_container').css('width', '409px');
						$('#polldaddy_container_top')
								.css('background',
										"url('images/polldaddy_container_top.gif') no-repeat");
						$('#polldaddy_container_top').css('height', '10px');
						$('#polldaddy_container_middle')
								.css('background',
										"url('images/polldaddy_container_middle.gif') repeat-y");
						$('#polldaddy_container_bottom')
								.css('background',
										"url('images/polldaddy_container_bottom.gif') no-repeat");
						$('#polldaddy_container_bottom').css('height', '10px');
						$('#polldaddy_container_top').css('width', '409px');
						$('#polldaddy_container_middle').css('width', '409px');
						$('#polldaddy_container_bottom').css('width', '409px');

						$('#poll_top_content > h3').remove();
						$('#poll_container_content').css('opacity', '0');
						$('#poll_top_content > h2').css('font-weight', 'bold');
						$('#poll_top_content > h2').html(answerTitle[answer]);
						$('#poll_top_content > p').html(answerDesc[answer])
						$('#answer_blurb')
								.html(
										"<strong>Voici de quelle fa&ccedil;on d&rsquo;autres personnes ont essay&eacute; de d&eacute;gonfler l&rsquo;&eacute;l&eacute;phant :</strong>");

					}
					
					function inputClickHandler(e) {
						var myID = $(e).find('input').attr('id');
						for ( var i = 0; i < inputs.length; i++) {
							var checkID = $(inputs[i]).find('input').attr('id');
							if (myID == checkID) {
								answer = i;
								$(inputs[i]).parent().find('.pds-input-label')
										.addClass('option_selected')

								// $(inputs[i]).parent().find('.pds-input-label').css('backgroundPosition',
								// '0 -28px');
							} else {
								if ($(inputs[i]).parent().find(
										'.pds-input-label').hasClass(
										'option_selected'))
									;
								$(inputs[i]).parent().find('.pds-input-label')
										.removeClass('option_selected');

							}
							$(inputs[i]).parent().find('.pds-input-label')
									.removeClass('option_rollover')
						}
					}
				});

function animateInPoll() {
	$('#animate_container').css( {
		display : 'block',
		top : '126px'
	});
	if (isIE == true) {
		$('#animate_container').css('top', '126px');
		$('#poll_container').css('top', '5px');
		$('#animate_container').css('overflow', 'visible');
	} else {
		$('#poll_container').animate( {
			top : '5px'
		}, 750, 'easeOutCubic', function() {
			$('#animate_container').css('overflow', 'visible');
		});
	}
}

function getMovie(movieName) {
	return document.getElementById(movieName);
}
