

$( document ).ready(function() {
	

	

	$(window).resize(function() {		
		
		
		
	});
	
	$('.v1hspimg_btn').click(function(e){
		
		
		$('.v1hspimg_reveal').hide();
		$('.v1hspimg_btn').css('cursor','pointer');

		var imgID = $(this).attr('id').split('btn_')[1];		
		var hsSec = imgID.split('_')[0];
		var hsItem = imgID.split('_')[1];
	
		var img_sec = '#sec_' + hsSec;
		var totalIcons = $('#sec_' + hsSec + ' .v1hspimg_btn').length;
		//$("#image_leadin_"+hsSec).css("display","none")
		//$("#image_ind_"+hsSec).css("display","block")

		$('#v1hspimg_reveal_'+hsSec+'_'+hsItem).fadeIn(500, function(){
			if(isWeb){
				$(this).focus();	
			}
		});
		
				
		if(Number($(this).attr('data-image-hs')) == 0){
			$(this).attr('data-image-hs',1);
		}
		
		
		
		isV1ImgHsDone(img_sec);		
		
		v1HspImgVisited(hsSec,totalIcons,this);
		
	
		return false;		
	});	
	
	/* added keyboard accessibility */
	$('.v1hspimg_btn').keypress(function (e) {
		if (e.keyCode == 13 || e.keyCode == 32) {
			
			$(this).trigger('click');
		}		
	});	
	
	
	
	$('.v1hspimg_reveal_content img').click(function(e){
		
		$(this).parent().parent().hide();
		
	});
	
	$('.v1hspimg_reveal_content img').keypress(function (e) {
		if (e.keyCode == 13 || e.keyCode == 32) {
			
			$(this).trigger('click');
		}		
	});	

});


function v1HspImgVisited(sec,total,btn){	
	
	for(var i = 1; i!=total+1; i++){
		if(Number($('#v1hspimg_btn_'+sec+'_'+i).attr('data-image-hs')) == 2){
			var imgEle, img, ext
			$('#v1hspimg_btn_'+sec+'_'+i).find('img').each(function(index, element) {
				imgEle = $(this);
				img = $(this).attr('src').split('.')[0];
				ext = $(this).attr('src').split('.')[1];
			});

			if(img.indexOf('_visited') == -1){
				$(imgEle).attr('src', img + '_visited.' + ext);	
			}	
		}
	}	
}


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

function isV1ImgHsDone(img_sec){
	secNum = img_sec.split('_')[1]
	var hotspotDone = 0;
	var clicked = 0;
	$(img_sec).find('.v1hspimg_btn').each(function(index, element) {
				
		var data = Number($(this).attr('data-image-hs'));
		if(data === Number(1)){
			hotspotDone++;
			clicked = Number($('#sec_'+secNum).attr('data-clicked'));
			clicked +=1;
			$('#sec_'+secNum).attr('data-clicked',clicked);
			$(this).attr('data-image-hs','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;
	}
	
}


$('.v1hspimg_btn').attr('data-image-hs',0);