/**
 * Site loader: hide once the page (including images) finishes loading.
 *
 * @package nxt-event-planner
 */
( function () {
	'use strict';

	var hidden = false;

	function nxtEventPlannerHideLoader() {
		if ( hidden ) {
			return;
		}
		hidden = true;

		var loader = document.getElementById( 'nxt-site-loader' );

		if ( ! loader ) {
			return;
		}

		loader.classList.add( 'is-loaded' );

		window.setTimeout( function () {
			if ( loader && loader.parentNode ) {
				loader.parentNode.removeChild( loader );
			}
		}, 600 );
	}

	if ( 'complete' === document.readyState ) {
		nxtEventPlannerHideLoader();
	} else {
		window.addEventListener( 'load', nxtEventPlannerHideLoader );
	}

	// Hard cap: never trap the user behind a slow image/font.
	window.setTimeout( nxtEventPlannerHideLoader, 3000 );
} )();
