var Launch = function () {

    var _self = this,
        _data = null,
        /* _simple_audio = null, */
        _global_wrapper = null,
        _bigPlay_button_holder_index = null,
        _launch_wraper = null,
        _start_btn = null,
        _bigPlay_button = null;

    var _blankAudio = {
        url: "./global/launch/launch.mp3",
        autoplay: true,
        timeline: [{}]
    }


    this.init = function () {
        

        _global_wrapper = $("#global_wrapper")
        _bigPlay_button_holder_index = $("#bigPlay_button_holder_index")
        _bigPlay_button = $("#bigPlay_button_holder_index #bigPlay_button");
        _launch_wraper = $("#launch_wraper")
        Utils.clear();
        _bigPlay_button_holder_index.show();
        _data = getData();

        loadStart();

        $("#listImgs").children("li").each(function (i, el) {
            setTimeout(function () {
                $(el).toggleClass("animate");
            }, i * 100);
        });
    }


    var getToday = function () {
        var today = new Date();
        var dd = String(today.getDate());
        var mm = String(today.getMonth() + 1);
        //January is 0!
        var yyyy = today.getFullYear();
        today = mm + '/' + dd + '/' + yyyy;
        return today
    }

    var addEvents = function () {
        try {
            var _user_details = data['shellModel'].user_details;
            _user_details['title'] = getToday() + ": Employbridge";
            var _uData = JSON.parse(data['LS'].getUserData(_user_details['title']));
            _user_details = _uData || _user_details;
        } catch (err) { }

        _start_btn = _launch_wraper.find("#launch_btn");

        _start_btn.off("click").on("click", function () {
            var _btn = $(this);
            var callBack = function () {
                _global_wrapper.trigger('loadShellWrapper')
            };


            if (_btn.hasClass('active')) {
                $("#preloader").fadeIn();
                _btn.removeClass('active').addClass('disabled');
                callBack();
            }

        })

        // Utils.enabledDisabled(_start_btn, true)
    }

    var loadStart = function () {

        _bigPlay_button_holder_index.show();
        _bigPlay_button.off("click").on("click", function () {
            loadSimpleAudio();
            _bigPlay_button_holder_index.hide();

        })
        addEvents();

    }

    var loadSimpleAudio = function () {
        Utils.loadTemplate("#simple_audio_holder", "simple_audio", function () {
            var _aData = _data['audio']
            _simple_audio = new Simple_Audio();
            _simple_audio.init(_aData);
        });
    }


    var changeAudio = function (aData) {
        try {
            if (_simple_audio) {
                var _audioData = aData;
                _audioData["callback"] = aData["callback"] || function () {
                    //  console.log("audio .. completed....", aData)
                }
                _simple_audio.updateMedia(_audioData);
            }
        } catch (err) {
            Utils.error(err)
        }
    }


    var getData = function () {
        var _data = {};
        _data['audio'] = {
            url: "./global/launch/blank.mp3",
            autoplay: true,
            timeline: [{}],
            callBack: function () {
                Utils.enabledDisabled(_start_btn, true)
            }
        }
        return _data
    }

    return this;
}