
/**
 * @author anthonysapp
 */
var poll;
var inputs;
var voteBtn;
var flash;
var answer = null;
var errorshowing = false;
var answerTitle = new Array(
		"He may like the company, but you shouldn't let him drive. Remember...",
		"It's nice of you to make him feel welcome, but you shouldn't let him drive. Remember...", "That's the right call. And remember...");
		
var answerDesc = new Array(
		"If you feel awkward asking for a friend's keys, enlist someone else's help. Sometimes there's strength in numbers.",
		"If you feel awkward asking for a friend's keys, enlist someone else's help. Sometimes there's strength in numbers.",
		"If you feel awkward asking for a friend's keys, enlist someone else's help. Sometimes there's strength in numbers.");

var positions = new Array( {
	height : 260,
	top : 0
}, {
	height : 260,
	top : 0
}, {
	height : 260,
	top : 0
});


var flashAnswers = new Array(1, 1,- 1);

var ctaPush = {
	title : "Host responsibly this Halloween.",
	body : "Be a great host. Help make sure your friends have fun and stay safe this fall. 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 : 125,
	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() {
					
					/* fade in poll placeholder image*/					
					$('#headerContent img').delay(3400).fadeIn(500);

	  
					$('#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');					
					//poll = $('#PDI_container3466034');
					//poll = $('#PDI_container3770010');					
					poll = $('#PDI_container3954068');										
					
					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);
}



