(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 pointsInput = document.getElementById('Points');
        var animationsInput = document.getElementById('Animation');
        Nonstop.default.getAnimations().then(function(animations) {
            for(var i = 0; i < animations.length; i++) {
                var currentAnimation = animations[i];
                var optionElem = document.createElement('option');
                optionElem.value = currentAnimation.name;
                optionElem.text = currentAnimation.name;
                animationsInput.appendChild(optionElem);
            }
        });

        var playButton = document.getElementById('Play');
        playButton.addEventListener('click', function() {
            var points = pointsInput.value * 1;
            var animationName = animationsInput.value;
            Nonstop.default.playAnimation(animationName, points);
        });
    });

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

})();