/**
 * @author anthonysapp
 */
var poll;
var inputs;
var voteBtn;
var flash;
var answer = null;
var errorshowing = false;
var answerTitle = new Array(
		"You clearly have safety on your mind,<br/>but what you should do is...",
		"Nicely done. It's always good to...", "Bad idea. You're best to...");
var answerDesc = new Array(
		"Encourage your friend to cool down with a non-alcoholic drink. Alcohol impairs the ability to make decisions and can compromise motor skills. Drinking and swimming don't mix.",
		"Encourage your friend to cool down with a non-alcoholic drink. Alcohol impairs the ability to make decisions and can compromise motor skills. Drinking and swimming don't mix.",
		"Encourage your friend to cool down with a non-alcoholic drink. Alcohol impairs the ability to make decisions and can compromise motor skills. Drinking and swimming don't mix.");
var positions = new Array( {
	height : 270,
	top : -10
}, {
	height : 250,
	top : 0
}, {
	height : 250,
	top : 0
});
var flashAnswers = new Array(-1, 1, -1);

var ctaPush = {
	title : "Host responsibly this summer.",
	body : "Be a great host. Help ensure your guests have fun and stay safe this summer. And remember, drinking and driving should never be the elephant in the room. Speak up. You could save a life. ",
	button : "images/more_hosting_tips_btn.gif",
	href : "host_with_the_most.html",
	height : 120,
	top : 50
}
function ctaLink(href) {
	$('#animate_window').blur();
	$('#poll_container').blur();
	$('#animate_window').css( {
		display : 'none',
		top : '-349px'
	});
	$('#poll_container').css( {
		top : '-225px'
	});
	window.location = href;
}

function alert() {
}
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">Please enter an answer first!</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);
							$('#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>Here's how others tried to deflate the elephant:</strong>");
							$('#poll_container').css('top',
									positions[answer].top);
							setAnswers();
							$('#poll_container_content').css('opacity', 1);
							$('#continue_button').show();
						}
					}

					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>Here's how others tried to deflate the elephant:</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');
							}
						}
					}
				});

function animateInPoll() {
	$('#animate_container').css( {
		display : 'block',
		top : '129px'
	});
	if (isIE == true) {
		$('#animate_container').css('top', '129px');
		$('#poll_container').css('top', '20px');
	} else {
		$('#poll_container').animate( {
			top : '5px'
		}, 750, 'easeOutCubic');
	}
}

function getMovie(movieName) {
	return document.getElementById(movieName);
}
