//use strict;

import * as Farapp from './fara.js';

let landing = new RegExp(/(https?:\S+\/$|index.html$)/);

if (landing.test(window.location.href)) {
    window.addEventListener('load', () => {
        Farapp.sliderBg();
    });
}

if (!window.location.href.includes('video')) {
    document.addEventListener('readystatechange', () => {
        Farapp.activeNav();
        Farapp.menuKeys();
        Farapp.mobileNav();
    });

    window.addEventListener('scroll', event => {
        Farapp.navOnScroll();
    });
}
/**
 * For itinerario.html...
 * @todo What about the interactive map?!?
 */
if (window.location.href.includes('itinerario')) {
    let vidLinks = document.querySelectorAll('.open-vid');
    vidLinks.forEach(a => {
        a.addEventListener('click', () => {
            Farapp.openVideo(a);
        });
    });
    /**
     * Add anchors to sections
     */
    document.addEventListener('readystatechange', () => {
        Farapp.genAnchors();
    });
}
/**
 * For videos...
 */
if (window.location.href.includes('video')) {
    document.addEventListener('readystatechange', () => {
        let vStr = localStorage.getItem('vidURI');
        let vidTitle = localStorage.getItem('vidTitle');

        document.querySelector('h1').innerHTML = vidTitle;

        let close = document.querySelector('a[title="Close"]');

        close.addEventListener('click', () => {
            // If referred from interactive map, shouldn't
            // just go back...
            window.history.go(-1);
        });

        let source = document.querySelector('source');
        let video = source.parentNode;
            
        source.src = `assets/video/${vStr}`;
        
        video.load();
    });
}
/**
 * Slideshow in credits page
 */
if (window.location.href.includes('credits')) {
    document.addEventListener('readystatechange', () => {
        Farapp.slideshow();
    });
}
/**
 * Landscape orientation when fullscreen?!
 * @todo Reliable check for mobile???
 */
if ("maxTouchPoints" in navigator) {
    document.addEventListener('fullscreenchange', () => {
        screen.orientation.lock('landscape');
    });
}