(function () {

    ready(function () {
        Nonstop.default.initialize({
            environment: window.environment,
            platform: 'web',
            cdnUrl: '../../dist/'
        });

        var userInput = {
            firstName: chance.first(),
            externalId: chance.guid(),
            email: chance.email()
        };
        Nonstop.default.login(userInput, true);

        var startContentButton = document.querySelectorAll('.btn-start-content')[0];
        startContentButton.addEventListener('click', function() {
            var startContentTask = {
                'contentId': 'VDKA0_52i1bahk',
                'task': 'start-content',
                'isWatchingNonstop': true
            };
            Nonstop.default.userPerformedTask(startContentTask);
        });

        var watch1MinuteButton = document.querySelectorAll('.btn-watch-1-minute-of-content')[0];
        watch1MinuteButton.addEventListener('click', function() {
            var watch1MinuteContentTask = {
                'contentId': 'VDKA0_52i1bahk',
                'task': 'watch-1-minute-of-content',
            };
            Nonstop.default.userPerformedTask(watch1MinuteContentTask);
        });

        var connectMvpdAccount = document.querySelectorAll('.btn-connect-mvpd-account')[0];
        connectMvpdAccount.addEventListener('click', function() {
            var connectMvpdTask = {
                'mvpdName': 'Spectrum',
                'task': 'connect-mvpd-account'
            };
            Nonstop.default.userPerformedTask(connectMvpdTask);
        });
    });

    function ready(fn) {
        if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
            fn();
        } else {
            document.addEventListener('DOMContentLoaded', fn);
        }
    }

})();