(function($) {
    var $document = $(document);
    var text_init_flag = 0;

    $document.off('initBuilder');
    $document.on('initBuilder', function() {

        var product_settings = {};
        $document.trigger('InitBuilder');

        $document.off('click', '.sys_builder_controllers .tab_menu .block_title');
        $document.on('click', '.sys_builder_controllers .tab_menu .block_title', function () {
            var $this = $(this);
            $('.tab_menu .block_title').removeClass('active');
            $this.addClass('active');
            $('.builder_tab').hide();
            $('.builder_tab[tab_id="' + $this.attr('tab_id') + '"]').show();
        });

        if (text_init_flag === 0) {
            $document.trigger('builder.inittextcontrollers');
            text_init_flag = 1;
        }

        $document.trigger('initBuilderCategories');

        $document.trigger('initClipartDraw');

        $document.trigger('initProduct', [builder_product_id, product_settings,
            function (product_settings) {

                $document.trigger('builder.area.init', [product_settings]);

                $document.trigger('initCanvasControllers');
                $document.trigger('initDesignSaveButton');
                $document.trigger('initDesignUploader');

                $document.trigger('initCreatedDesignsOnBuilder');
            }
        ]);

    });
})(SWjQuery);