/* document ready = vanilla JS */
document.addEventListener("DOMContentLoaded", () => {

	/* video modal functionality */
	let video_el = document.getElementById('video-callout--video');
	let video_modal_el = document.getElementById('video-modal');
	let video_embed_el = document.getElementById('video-iframe');
	let video_target_el = document.getElementById('video-target-wrap');

	/* clear the src on modal close */
	/** 
	 * NOTE: this is so the video re-starts 
	 * and doesn't play while modal is closed 
	 */
	if (video_modal_el) {
		video_modal_el.addEventListener('hidden.bs.modal', function (e) {
			video_target_el.innerHTML = '';
		});
	}

	/* on click set the src dynamically to stop and restart videos */
	if (video_el) {
		video_el.onclick = function (e) {
			e.preventDefault();
			let vid_src = video_el.getAttribute('data-video-id');
			let vid_markup = '<iframe class="video-iframe" id="video-iframe" src="https://www.youtube.com/embed/' + vid_src + '?rel=0&modestbranding=1&autohide=1&showinfo=0&controls=0&autoplay=1" width="560" height="315" frameborder="0" allowfullscreen></iframe>';
			video_target_el.innerHTML = vid_markup;
		}
	}
});
