$(function() {
		
	$('#votePop').fancybox({
		'frameWidth' : 628,
		'frameHeight' : 238,
		'hideOnContentClick' : false,
		'centerOnScroll' : true,
		'overlayShow' : true,
		'overlayOpacity' : 0.75,
		'overlayColor' : '#000'
	});
	
	// Apply iFrame pop up to flipbooks
	$('.flipbooks .title2 a, a.queenFlipbook').each( function() {
		var FlipbookSrc = $(this).attr('href');
		$(this).attr('href', FlipbookSrc+'&skin=/content/skins/flipbook/swf/default.swf');
	}).fancybox({
		'iFrame' : true,
		'iFrameScrolling' : 'no',
		'frameWidth' : 720,
		'frameHeight' : 540,
		'hideOnContentClick' : false,
		'centerOnScroll' : true,
		'overlayShow' : true,
		'overlayOpacity' : 0.75,
		'overlayColor' : '#000'
	}); 
	
	// Apply iFrame pop up to share links
	$('a.shareEmail').fancybox({
		'iFrame' : true,
		'iFrameScrolling' : 'no',
		'frameWidth' : 554,
		'frameHeight' : 361,
		'padding' : 0,
		'hideOnContentClick' : false,
		'centerOnScroll' : true,
		'overlayShow' : true,
		'overlayOpacity' : 0.75,
		'overlayColor' : '#000'
	}); 
	
	$('.level_one_episodes a.vote').click( function() {
	
		// Collect Vote info
		var poll_pollid = $('#pollid').attr('value');
		var poll_question = $('#pollquestion').attr('value');
		var poll_value = $(this).siblings('input').attr('value');
		
		// Hide voting buttons / Display waiting animation
		$pVoting = $('.level_one_episodes p.votingButton');
		$pVoting.hide().css('text-align', 'center').children('input').attr('disabled', 'disabled').parent().html('<img src="/home/images/ajax-loader.gif">').fadeIn();
		
		// Launch Vote
		submitVote(poll_pollid, poll_question, poll_value);
		
		return false;
	});
	
	
});

function submitVote(pollid, question, value) {
	
	var strVote = "cmd=tally&style=XMLResultsCustom3&pollid=" + pollid + "&" + question + "=" + value;
	$.ajax({
			type:"GET",
			cache: false,
			url: "sendVote.jhtml",
			data: strVote,
			dataType: 'json',
			success: function(res){
				$('.level_one_episodes p.votingButton').fadeOut();
				$('a#votePop').click();
			},
			error: function(msg){
				alert("Error: Vote could not be sent poll are currently closed. Please refresh this page.");
			}
	});
}
