	function XX() { console.log ("X MAKRS THE SPOT"); }
	function X(what) { console.log (what); }
	/* Function to get device info */ function devinfo(arg = null) {
		var userAgent = navigator.userAgent; var info = {};
		info["OS"] = ""; info["browser"] = ""; info["dev"] = "";
		if (1 + 1 == 2) { /* OS */
			if			(/Windows/.test(userAgent)) { info["OS"] = "Windows"; }
			else if	(/Linux/.test(userAgent)) { info["OS"] = "Linux"; }
			else if	(/Mac/.test(userAgent)) { info["OS"] = "MacOS"; }
			else if	(/Android/.test(userAgent)) { info["OS"] = "Android"; }
			else if	(/iOS/.test(userAgent)) { info["OS"] = "iOS"; }
			else 		{ info["OS"] = "Unknown"; }
		}
		if (1 + 1 == 2) { /* Browser */
			if			(/Chrome/.test(userAgent)) { info["browser"] = "Google Chrome"; }
			if	(/Firefox/.test(userAgent)) { info["browser"] = "Mozilla Firefox"; }
			if	(/Safari/.test(userAgent)) { info["browser"] = "Apple Safari"; }
			if	(/Edge/.test(userAgent) || /Edg/.test(userAgent)) { info["browser"] = "Microsoft Edge"; }
			if	(/Opera/.test(userAgent) || /OPR/.test(userAgent)) { info["browser"] = "Opera"; }
			if	(/IE/.test(userAgent)) { info["browser"] = "Internet Explorer"; }
			else		{ info["browser"] = "Unknown"; }		
		}
		if (1 + 1 == 2) { /* Dev */
			if			(/Mobile/.test(userAgent)) { info["dev"] = "Mobile Device"; }
			else if	(/Tablet/.test(userAgent)) { info["dev"] = "Tablet"; }
			else		{ info["dev"] = "Desktop"; }		
		}
		/* if (arg == voices) {
			if ('speechSynthesis' in window) { // Wait for the voices to be loaded
				speechSynthesis.onvoiceschanged = function() {
					var voices = speechSynthesis.getVoices(); // Fetch available voices
					var voicesList = $('.surahtitle'); // Display voices in the DOM
					voices.map(function(voice, index) {
						if (voice.lang == "en-US") {
							var voiceOption = $('<p style="color:grey; text-align: left;">').text('[' + index + '] - def [' + voice.default + '] - lclsrv [' + voice.localService + '] - ' + voice.name); 
							voicesList.append(voiceOption); 
						}
					});
				};
			}
			var voices = speechSynthesis.getVoices(); // Fetch available voices
			var voicesList = $('.surahtitle'); // Display voices in the DOM
			voices.map(function(voice, index) {
				if (voice.lang == "en-US") {
					var voiceOption = $('<p style="color:grey; text-align: left;">').text('[' + index + '] - def [' + voice.default + '] - lclsrv [' + voice.localService + '] - ' + voice.name); 
					voicesList.append(voiceOption); 
				}
			});
		} */
		return info;
	}
	/* Function to find substring inside string */ function stringIsIn(main, substring) { 
		return main.indexOf(substring) !== -1; 
	}
	/* Screenshot function of dom-to-image script */ function getScreenShot( divname ) {
		var node = document.querySelector( divname );
		function filter(node) { if (node.classList) return !node.classList.contains("capture"); return true; }
		domtoimage.toBlob( node, { quality: 1, scale: 2, dpi: 2, cacheBust: true })
		.then(function (blob) { navigator.clipboard.write([ new ClipboardItem( Object.defineProperty({}, blob.type, { value: blob, enumerable: true }) ) ])
		.then(function() { $( "div.othermeanings" ).empty(); $( "div.othermeanings" ).append( '<div class="hintpop">Verse saved to clipboard.</div>' ); document.getElementById("othermeanings").style.display = "block"; });
		});
	}
	/* Make TTS better by phonetics */ function ttsReplace(textToRead) { 
		var textToRead = textToRead.replace(/\[\ (\d*\ \:\ \d*)\ \]/gm, '');
		var textToRead = textToRead.replace(/—/gm, ',');
		var textToRead = textToRead.replace(/\b(?:The|the)\s+One\b/g, "God");
		var textToRead = textToRead.replace(/Rabb/gm, 'Rubb');
		var textToRead = textToRead.replace(/bani/gm, 'bunny');
		var textToRead = textToRead.replace(/Fir'oun/gm, 'phir-oun');
		var textToRead = textToRead.replace(/\//gm, ', or, ');
		var textToRead = textToRead.replace(/Essa/gm, 'Eessa');
		var textToRead = textToRead.replace(/Nooh/gm, 'Nooooohhhh ');
		var textToRead = textToRead.replace(/malaikati/gm, 'malaaE katti');
		var textToRead = textToRead.replace(/Saleh/gm, 'Ssaaalaayh');
		
		return textToRead;
	}
	/* Get Data of element */ function elmntdta(e) {
		var ele = {
			'class' : e.className,
			'id' : e.id,
			'root' : e.dataset.root,
			'controlID' : e.dataset.controlid
		};
		return ele;
	}
	/* Function: Speak a word */ function say(word) {
		const say = new SpeechSynthesisUtterance(word);
		say.onend = $('body').data('playing', "stopped");
		say.voice = speechSynthesis.getVoices()[0];
		window.speechSynthesis.speak(say);
	}
	/* Check translations On/Off on Load More */ $("input:checkbox[id^=switchtranslate_]").each(function( ) { 
		if ( $(this).prop('checked') ) { var thisis = $(this).attr('id').substring(16); $('.trans_' + thisis ).css('display', 'block'); } 
	});
	/* Set Reader Mode On | Off for Reload */ $("input:checkbox[id=readermode]").each(function( ) {
		if ( $(this).prop('checked') ) { $(".vrscntnr").css("display", "none"); $(".reader").css("display", ""); $(".playpausestop").css("display", ""); }
		else { $(".vrscntnr").css("display", ""); $(".reader").css("display", "none"); $(".playpausestop").css("display", "none"); }
	});
	/* Remove all repeating Arabic-Root elements */ $(document).ready(function() {
		var unqroots = {};
		$('div.all_roots [data-root]').each(function() { 
			var rootval = $(this).attr('data-root'); 
			if (unqroots[rootval]) { $(this).remove(); } else { unqroots[rootval] = true; }
		});
	});
	/* Set Fonts Large or Regular */ $("input:checkbox[id^=fntsz_]").each(function( ) {
		if ( $(this).prop("checked") ) {
			if ( $(this).attr('id') == "fntsz_arblarge" ) { $('div.ayaatcntnr .arabicfont').css('font-size', '40px'); }
			else if ( $(this).attr('id') == "fntsz_englarge" ) { $('div.wrds .englishfont').css('font-size', '25px'); $('div.engline .englishfont').css('font-size', '25px'); }
		}
		else {
			if ( $(this).attr('id') == "fntsz_arblarge" ) { $('div.ayaatcntnr .arabicfont').css('font-size', '30px'); }
			else if ( $(this).attr('id') == "fntsz_englarge" ) { $('div.wrds .englishfont').css('font-size', '20px'); $('div.engline .englishfont').css('font-size', '20px'); }
		}
	});	

	$(document).on('click', function(event) {
		var thist1 = $(event.target); // for CSS stuff 
		var thist2 = event.target; // for data stuff
		var ele = elmntdta(event.target);
		//X(ele);

		if ( ele['class'] == "ayaatcntnr" ) { /* Close options menu */
			$("#optionspanel").css("right", "-320px");
		}
		if ( stringIsIn(ele['class'], "arabicfont ") ) { /* Display root meanings */
			$('[id^="root_"]').css('display', 'none'); $("#root_" + ele['root']).css('display', 'block');	
		}
		if ( ele['id'] == "switchorientation" ) { /* Switch orientation LTR <-> RTL */
			if( $('#switchorientation').prop('checked') ) { $(".ayaatcntnr").addClass("orientationrtl"); } else { $(".ayaatcntnr").removeClass("orientationrtl"); }
		}
		if ( ele['id'] == "switchtype" ) { /* Switch type of display: Sentence | Word2Word*/
			if( $('#switchtype').prop('checked') ) { $(".wrdcntnr").css("display", "inline-block"); $(".arbline").css("display", "none"); $(".engline").css("display", "none"); } else { $(".wrdcntnr").css("display", "none"); $(".arbline").css("display", "block"); $(".engline").css("display", "block"); }
		}
		if ( ele['id'] == "menu" ) { /* Show Options Menu */
			if( $("#optionspanel").css('right') == '-320px' ) { $("#optionspanel").css("right", "10px"); $("#menu").css('color', 'green'); }
			else { $("#optionspanel").css("right", "-320px"); $("#menu").css('color', '#03b17b'); }
		}
		if ( ele['class'] == "capture" ) { /* Screenshot the Verse visible DIV state */
			var parent = thist1.parents("div.vrscntnr").attr("id");
			var divname = '#' + parent;
			getScreenShot( divname );
			if (confirm('Also save image as file?')) { window.saveAs(blob, divname + ".png"); }
		}
		if ( ele['class'] == "playthis" ) { /* TTS: Only single verse Play/Stop */
			if( $('body').data('playing') == "stopped" ) { 
				$('body').data('playing', "playing");
				var targetParagraphId = thist1.data("target"); // Get the data-target value to identify the associated paragraph
				var textToSpeak = $("." + targetParagraphId).text(); // Get the text from the associated paragraph
				textToSpeak = ttsReplace(textToSpeak);
				var utterance = new SpeechSynthesisUtterance(textToSpeak);
				if (devinfo()["OS"] == "Windows" && devinfo()["browser"] == "Google Chrome") { voiceis = 0; }
				else if (devinfo()["OS"] == "Windows" && devinfo()["browser"] == "Mozilla Firefox") { voiceis = 0; }
				else { voiceis = 0; }
				utterance.lang = 'en-US';				
				utterance.voice = speechSynthesis.getVoices()[voiceis];
				speechSynthesis.speak(utterance);
				utterance.onend = function() { $('body').data('playing', "stopped"); };
			}
			else { $('body').data('playing', "stopped"); window.speechSynthesis.cancel(); }
		}
		if ( stringIsIn(ele['class'], "playall") ) { /* TTS: Play all visible verses in Clear Reading mode */
			if($('body').data('playing') == "stopped") {
				var allreads = [];
				$("#allreads").remove();
				$("#toreadnw").remove();
				$('.reader').each(function() { allreads.push($(this).data('index')); });
				$('body').append($('<input id="allreads" type="hidden">').val(allreads));
				if ( $("#prevreads").val() !== undefined ) { 
					var prevreads = $("#prevreads").val();
					var nowonpg = String(allreads).split(',').map(function(item) { return parseInt(item, 10); });
					var toreadnw = allreads.filter(function(value) { return !prevreads.includes(value); });
					if (toreadnw == "") { toreadnw = allreads; }
				}
				else { var toreadnw = allreads; }
				$('body').append($('<input id="toreadnw" type="hidden">').val(toreadnw));
				function readElements(index) { 
					if (index < toreadnw.length) {
						$('body').data('playing', "playing");
						var currentNumber = toreadnw[index];
						var currentElement = $('.reader[data-index="' + currentNumber + '"]');
						var elementOffset = currentElement.offset().top;
						var middleOfPage = (($(window).height() - currentElement.height()) / 2) - 100; // Calculate the middle of the page
						$('html, body').animate({ scrollTop: elementOffset - middleOfPage }, 1000); // Adjust the duration (e.g., 1000 milliseconds) as needed
						$('.reader').css("background-color", "");
						currentElement.css('background-color', '#303030'); // Highlight current element
						var textToSpeak = ttsReplace(currentElement.text()); // Get text of current element
						// TTS speak the current text
						var utterance = new SpeechSynthesisUtterance(textToSpeak);
						if (devinfo()["OS"] == "Windows" && devinfo()["browser"] == "Google Chrome") { voiceis = 0; }
						else if (devinfo()["OS"] == "Windows" && devinfo()["browser"] == "Mozilla Firefox") { voiceis = 0; }
						else { voiceis = 0; }
						utterance.lang = 'en-US';
						utterance.voice = speechSynthesis.getVoices()[voiceis];
						speechSynthesis.speak(utterance);
						utterance.onend = function() { currentElement.css('background-color', ''); /* Continue with the next element */ readElements(index + 1);  };
					}
					else { $('body').data('playing', "stopped"); }
				}
				readElements(0); // Start reading from the first element
				$("#prevreads").remove(); 
				$('body').append($('<input id="prevreads" type="hidden">').val(allreads)); 
			}
			else if($('body').data('playing') == "paused") { $('body').data('playing', "playing"); window.speechSynthesis.resume(); }	
		}
		if ( stringIsIn(ele['class'], "pauseall") ) { /* TTS: Pause the above */
			if($('body').data('playing') == "playing") { $('body').data('playing', "paused"); window.speechSynthesis.pause(); }
		}
		if ( stringIsIn(ele['class'], "stopall") ) { /* TTS: Stop the above */
			if($('body').data('playing') == "playing") {  $('body').data('playing', "stopped"); window.speechSynthesis.cancel(); }
		}
		if ( ele['id'] == "readericon" ) { /* Switch between Reader Mode and Normal Mode */
			if( !$('#readermode').prop('checked') ) { $(".vrscntnr").css("display", "none"); $(".reader").css("display", ""); $(".playpausestop").css("display", ""); }
			else { $(".vrscntnr").css("display", ""); $(".reader").css("display", "none"); $(".playpausestop").css("display", "none"); }
		}
		if ( ele['id'] == "fntsz_englarge" ) { /* Set Fonts Large or Regular */
			var engels = 'div.wrds .englishfont, div.engline .englishfont, article.reader, .ajaxsearchtrans .translationtext, #mysentences .aresult';
			if ($("#" + ele['id']).prop('checked') ) { $(engels).css('font-size', '25px'); $("#mysentences .aresult").css('line-height', '35px'); }
			else { $(engels).css('font-size', '20px'); $("#mysentences .aresult").css('line-height', '25px'); }
		}
		if ( ele['id'] == "fntsz_arblarge" ) { /* Set Fonts Large or Regular */
			if ($("#" + ele['id']).prop('checked') ) { $('div.ayaatcntnr .arabicfont').css('font-size', '40px'); }
			else { $('div.ayaatcntnr .arabicfont').css('font-size', '30px'); }
		}
		if ( stringIsIn(ele['class'], "arrow") ) {
			var target = ele['controlID'];
			var cssMap = {
				"typeset": { "up": "63px", "down": "27px" },
				"orientset": { "up": "80px", "down": "27px" },
				"trans_English": { "up": "194px", "down": "27px" },
				"trans_Urdu": { "up": "164px", "down": "27px" },
				"chfontsize": { "up": "100px", "down": "27px" },
				"unqsrch": { "up": "100%", "down": "35px" },
				"mysentences": { "up": '100%', "down": "35px" },
				"adhocsrch": { "up": '100%', "down": "35px" },
				"trdtrnslt": { "up": '100%', "down": "35px" }
			};
			if (target in cssMap) { 
				var heights = cssMap[target]; var targetSelector = "[data-control='" + target + "']";
				if (stringIsIn(ele['class'], "arr-down")) { $(thist2).removeClass('arr-down').addClass('arr-up'); $(targetSelector).css("height", heights.up); }
				else { $(thist2).removeClass('arr-up').addClass('arr-down'); $(targetSelector).css("height", heights.down); }
			}
		}
	});

	$(window).scroll(function() { if ( $(this).scrollTop() > 50 ) { $('[id^="root_"]').css('display', 'none'); } });

	/* $(document).on('mouseover', function(event) { }); $(document).on('mouseout', function(event) { }); */