
function Loader() {
    // Constantes liées aux tailles de spinner
    var defaultWidth = 12;
    var defaultRadius = 36;

    var defaultSpinOptions = {
        lines: 11, // The number of lines to draw
        length: 0, // The length of each line
        width: defaultWidth, // The line thickness
        radius: defaultRadius, // The radius of the inner circle
        corners: 1, // Corner roundness (0..1)
        rotate: 0, // The rotation offset
        direction: 1, // 1: clockwise, -1: counterclockwise
        color: '#000', // #rgb or #rrggbb
        speed: 1.0, // Rounds per second
        trail: 60, // Afterglow percentage
        shadow: false, // Whether to render a shadow
        hwaccel: false, // Whether to use hardware acceleration
        className: 'spinner', // The CSS class to assign to the spinner
        zIndex: 2e9, // The z-index (defaults to 2000000000)
        top: 'auto', // Top position relative to parent in px
        left: 'auto' // Left position relative to parent in px
    };

    var timeOut = 0;

    this.initialize = function() {

        /* Creation de la fonction spinLoader */
        $.fn.spinLoader = function(opts) {
            this.each(function() {
                var $this = $(this);
                var spinner = $this.data('spinner');

                if (spinner) {
                    spinner.stop();
                }

                if (opts !== false) {
                    opts = $.extend({
                        color: $this.css('color')
                    }, opts);

                    spinner = new Spinner(opts).spin();
                    var jQuerySpinnerElement = $(spinner.el);
                    jQuerySpinnerElement.css("position", "fixed");
                    $("body").append(jQuerySpinnerElement);

                    $this.data('spinner', spinner);
                }
            });
            return this;
        };

        // Recupération de la position par defaut
        timeOut = parseFloat($("*[data-o-role='page-loader']").attr('data-o-delaytime'));

        // Activation du listener sur les submit        
        orion.event.listenToPageUnload(orion.loader.submitTimeOut);
    };


    this.submitTimeOut = function() {
        setTimeout(orion.loader.showLoadingNotification, timeOut);
        return true;
    };

    /**
     * Affichage du spinner
     */
    this.showLoadingNotification = function() {
        $("*[data-o-role='page-loader']").show().spinLoader(defaultSpinOptions);
    };
};

$(document).ready(function() {
    orion.loader = new Loader();
    orion.loader.initialize();
});