

$( document ).ready(function() {
	

	/*$(window).resize(function() {		
	
	});*/
	
	/* only allow flip back if it is enabled mjb/kgs 03/17/22 */
	if (document.allowFlipBack)
	{	
		$('.flip_card_back').addClass('flip_card_back_active');				
	}	
	
	$('.flip_card_front').click(function(e){
		
	
		var imgID = $(this).parent().parent().attr('id').split('btn_')[1];		
		var imgSec = imgID.split('_')[0];
	
	
		var img_sec = '#sec_' + imgSec;
			
				
		if(Number($(this).parent().parent().attr('data-flip')) == 0){
			$(this).parent().parent().attr('data-flip',1);
		}
		
		
		
		$(this).parent().addClass("flipped");
			
		$(this).attr("aria-hidden", true);
		/* Flip Card Scroll Accessibility Fix 2023 -- */
		$(this).parent().find(".flip_card_back").attr("aria-hidden", true);
		/* 20240130 accessibility 2024 */
		$(this).parent().find(".flip_card_back").find(".flip_start").focus();
		
		/* 20240130 accessibility 2024 */
		$(this).parent().find(".flip_card_back").find('.flip_start').each(function(index, element) {
			$(this).attr("aria-hidden", false);
		});
		/* 20240130 accessibility 2024 */
		$(this).parent().find(".flip_card_back").find('.flip_rest').each(function(index, element) {
			$(this).attr("aria-hidden", false);
		});
		/* -- Flip Card Scroll Accessibility Fix 2023 */
		
		// 20221025 Flipcard link fix
		$(this).parent().find(".flip_card_back").find('a').each(function(index, element) {
			$(this).attr("aria-hidden", false);
			$(this).attr('role','link');
			
			$(this).attr('tabindex',$(this).attr('data-tab'));
		});
		
		// 20221025 Flipcard JAWs fix
		var tabCnt = $(this).attr("tabindex");
		$(this).attr("tabindex",-1);
		/* Flip Card Scroll Accessibility Fix 2023 -- */
		/* 20240130 accessibility 2024 */
		$(this).parent().find(".flip_card_back").attr("data-tab", tabCnt);
		$(this).parent().find(".flip_card_back").attr("tabindex", tabCnt);
		$(this).parent().find(".flip_card_back").attr("aria-hidden", false);
		/* -- Flip Card Scroll Accessibility Fix 2023 */
		
		isFlipDone(img_sec);		
		
		return false;		
	});	
	
	/* 20240130 accessibility 2024 */
	$('.flip_card_back').click(function(e){
		
		if (document.allowFlipBack)
		{
			$(this).parent().removeClass("flipped");
			$(this).attr("aria-hidden", true);
			/* 20240130 accessibility 2024 */
			$(this).find('.flip_start').attr("aria-hidden", true);
			$(this).find('.flip_rest').attr("aria-hidden", true);
			$(this).parent().find(".flip_card_front").attr("aria-hidden", false);
			$(this).parent().find(".flip_card_front").focus();
			/* 20240130 accessibility 2024 */
			$(this).find('.flip_start').attr("aria-hidden", true);
			$(this).find('.flip_start').attr('tabindex',-1);
			$(this).find('.flip_rest').attr("aria-hidden", true);
			$(this).find('.flip_rest').attr('tabindex',-1);

			$(this).find('.flip_content').find('a').each(function(index, element) {
				$(this).attr("aria-hidden", true);
				$(this).attr('tabindex',-1)
			});
			
			var tabCnt = $(this).parent().find(".flip_card_front").attr("data-tab");
			$(this).parent().find('.flip_card_back').attr("tabindex",-1);
			$(this).parent().find(".flip_card_front").attr("tabindex", tabCnt);
		}
		
		return false;		
	});
	
	$('.flip_card_front').keypress(function (e) {
		if (e.keyCode == 13 || e.keyCode == 32) {
			
			$(this).trigger('click');
		}		
	});
	/* 20240130 accessibility 2024 */
	$('.flip_card_back').keypress(function (e) {
		if (e.keyCode == 13 || e.keyCode == 32) {
			
			$(this).trigger('click');
		}		
	});

});


$('.flip_card_back').attr("aria-hidden",true)

/* 
	isFlipDone function 
	
	mark each hotspot as viewed when clicked
	called when hotspot clicked
*/

function isFlipDone(img_sec){
	secNum = img_sec.split('_')[1]
	var hotspotDone = 0;
	var clicked = 0;
	$(img_sec).find('.flip_card').each(function(index, element) {
				
		var data = Number($(this).attr('data-flip'));
		if(data === Number(1)){
			hotspotDone++;
			clicked = Number($('#sec_'+secNum).attr('data-clicked'));
			clicked +=1;
			$('#sec_'+secNum).attr('data-clicked',clicked);
			$(this).attr('data-flip','2');
		}
    });
					
	var totalClicked = Number($('#sec_'+secNum).attr('data-clicked'))
	var totalClicks = Number(document.clickArr[Number(secNum) - 1])
	if(totalClicked == totalClicks){	
		if(isAndroidTablet || isAndroidPhone || isMacChrome){
			document.intComplete = true;
			clearInterval(document.lockinterval)
			document.lockinterval = setInterval(function(){
				che = img_sec
				secNum = img_sec.split('_')[1]
				document.getnear(che);
				isPageComplete(secNum);
				if(($('#sec_'+(parseInt(secNum)+1)).is(':visible') || !$('#right_nav').hasClass('locked')) && document.courseLockedDown == true){
					clearInterval(document.lockinterval)
				} 
			},250)
		}else{
			document.intComplete = true;
			isPageComplete(secNum);
		}
		
		document.intComplete = true;
	
		isPageComplete(secNum);
		isHotSpotScreen = false;
	}
	
}


$('.flip_card').attr('data-flip',0);