function xmr_media_lazyload_add_handler(element) {
	element.addEventListener('play', (event) => {
		let content = element.querySelector("noscript");
		if (content) {
			element.innerHTML = content.innerHTML;
		}
	});
}
function xmr_media_lazyload_initialize() {
	new Promise((resolve, reject) => {
		// Figure out what to load.
		let elements = document.querySelectorAll(".block-media > [data-lazyload]");
		let stack = Array.from(elements);
		console.debug("Lazily loading " + stack.length + " elements...");

		// Add a lazyloading handler to all entries.
		for (let el of stack) {
			xmr_media_lazyload_add_handler(el);
		}

		resolve();
	});
}

(function() {
	'use strict';

	// Support for Mobile Devices
	document.querySelector("#navigation-toggle").addEventListener("click", (ev) => {
		document.querySelector("#header #navigation").classList.toggle("open");
	});

	// Lazily load Media
	xmr_media_lazyload_initialize();
})();
