

$(document).ready(function() {
  	relabelClassroomCertificate();
});

$(document).ajaxComplete(function () {
  	relabelClassroomCertificate();
});

//#0017994
function relabelClassroomCertificate() {
	if (!$(".ClassroomViewer") || $(".ClassroomViewer").length == 0) return false;

	var overallCertificates = $('.clsClassroomOverallCertificate');

	if (!overallCertificates || overallCertificates.length == 0) return false;
	
	overallCertificates.map(function () { return $(this).html($(this).html().replace('Overall Classroom Certificate', 'Overall Conference Certification Steps')); })
}

$.magnificPopup.instance.open = function(data) {
	if (!data.hasOwnProperty('callbacks')) {
		data.callbacks = {}
	}

	if (!data.callbacks.hasOwnProperty('open')) {
		data.callbacks.open = function () {
			setTimeout(appendSciptInPopup, 3000);
		}
	}
	
    $.magnificPopup.proto.open.call(this,data);
};

function appendSciptInPopup() {
	var iFrame = $('.mfp-iframe');
	if(!iFrame || iFrame.length == 0) return false;

	iFrame.contents().find('body').append('<script type=\"text\/javascript\">\r\n\t$(document).ready(function() {\r\n\t\tif (typeof(parent.relabelQuizInsidePopup) === \'function\') parent.relabelQuizInsidePopup();\r\n\t});\r\n\r\n\t$(document).ajaxComplete(function () {\r\n\t\tif (typeof(parent.relabelQuizInsidePopup) === \'function\') parent.relabelQuizInsidePopup();\r\n\t});\r\n\t\r\n\tif (typeof(parent.relabelQuizInsidePopup) === \'function\') parent.relabelQuizInsidePopup();\r\n<\/script>');
	
	iFrame.on('load', function () { appendSciptInPopup() });
}

function relabelQuizInsidePopup() {
	var iFrame = $('.mfp-iframe');
	if(!iFrame || iFrame.length == 0) return false;
	
	var quizCollapase = iFrame.contents().find('.collapse[data-value^="Quiz"]');
	if(!quizCollapase || quizCollapase.length == 0) return false;
	
	quizCollapase.map(function () {
		var $this = $(this);
		if(!$this || $this.length == 0) return false;
		
		var elementSelectors = ['strong:contains(quiz history)', 'a:contains(retake quiz)'];

		elementSelectors.map(function (elementSelector) {
			var element = $this.find(elementSelector);
			if(!element || element.length == 0) return false;
			
			element.text(element.text().replace('Quiz', 'Attestation'));
		});
	});
}



$("body").on("click",".MyClassroomTab .ViewerTab",function(){
    setTimeout(function(){ reloadFlipSnackIfrme()},1000);
});


function reloadFlipSnackIfrme(){
	var iframe = $("iframe[src*='cdn.flipsnack.com/']:visible");
	$(iframe).attr("src", $(iframe).attr("src"));
}