(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).then(function() {
            var nonstopHomeEarnContainer = document.querySelectorAll('.nonstop-home-earn-container')[0];
            var baseUrl = window.location.pathname.replace('/', '');
            Nonstop.default.presentNonstopHome(nonstopHomeEarnContainer, baseUrl);
        });
    });

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

})();