

$( 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);
		$(this).parent().find(".flip_card_back").find(".flip_content").focus();
		
		$(this).parent().find(".flip_card_back").find('.flip_content').each(function(index, element) {
			$(this).attr("aria-hidden", false);
			$(this).attr('tabindex',$(this).attr('data-tab'));
			//20220418 FlipCard fix for JAWs
			if (document.allowFlipBack){
				$(this).attr('role','button');
			}
		});
		/* -- 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 -- */
		//$(this).parent().find(".flip_card_back").attr("tabindex", tabCnt);
		$(this).parent().find(".flip_card_back").attr("data-tab", tabCnt);
		$(this).parent().find(".flip_card_back").attr("tabindex", -1);
		/* -- Flip Card Scroll Accessibility Fix 2023 */
		
		isFlipDone(img_sec);		
		
		return false;		
	});	
	
	/* Flip Card Scroll Accessibility Fix 2023 -- */
	$('.flip_content').click(function(e){

		
		if (document.allowFlipBack)
		{
			//20220418 FlipCard fix for JAWs
			$(this).parent().parent().removeClass("flipped");

			$(this).attr("aria-hidden", true);
			$(this).parent().parent().find(".flip_card_front").attr("aria-hidden", false);
			$(this).parent().parent().find(".flip_card_front").focus();
			
			//20220418 FlipCard fix for JAWs
			//$(this).parent().parent().find(".flip_card_back").find('.flip_content').each(function(index, element) {
				$(this).attr("aria-hidden", true);
				$(this).attr('tabindex',-1)
			//});

			// 20221025 Flipcard link fix
			$(this).find('a').each(function(index, element) {
				$(this).attr("aria-hidden", true);
				$(this).attr('tabindex',-1)
			});
			
			//20220418 FlipCard fix for JAWs
			var tabCnt = $(this).parent().parent().find(".flip_card_front").attr("data-tab");//$(this).attr("tabindex");
			$(this).attr("tabindex",-1);
			$(this).parent().parent().find(".flip_card_front").attr("tabindex", tabCnt);
		}
		
		return false;		
	});	
	/* -- Flip Card Scroll Accessibility Fix 2023 */
	
	$('.flip_card_front').keypress(function (e) {
		if (e.keyCode == 13 || e.keyCode == 32) {
			
			$(this).trigger('click');
		}		
	});
	$('.flip_content').keypress(function (e) { /* Flip Card Scroll Accessibility Fix 2023 */
		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);