(function($) {
    function post_formats() {
        var $formats = $('#formatdiv .post-format'),
            format = $formats.filter(':checked').val();
        var show_metabox = function(format) {
            var $container = $('.rad-main'),
                $editors = $('#postdivrich,#wpb_visual_composer,#poststuff .composer-switch'),
                $sections = $container.find('.section-gallery,.section-video,.section-audio,.section-quote,.section-link'),
                $items = $container.find('.item-gallery,.item-video,.item-audio,.item-quote,.item-link'),
                $container = $('.rad-main'),
                $selected_section = $container.find('.section-' + format),
                $selected_item = $container.find('li[data-class="section-' + format + '"]');
            if (format != '0') {
                $sections.not($selected_section).addClass('hide-format').removeClass('active');
                $items.not($selected_item).addClass('hide-format').removeClass('active');
                $selected_section.removeClass('hide-format').addClass('active');
                $selected_item.removeClass('hide-format').addClass('active');
                $('.section-extra_class').removeClass('active');
                $('.item-extra_class').removeClass('active');
            } else {
                $sections.addClass('hide-format').removeClass('active');
                $items.addClass('hide-format').removeClass('active');
                $('.section-extra_class').addClass('active');
                $('.item-extra_class').addClass('active');
            }
            if (format == 'quote' || format == 'link') {
                $editors.addClass('hiddeneditor');
            } else {
                $editors.removeClass('hiddeneditor');
            }
        }
        show_metabox(format);
        /* Show options based on user selected format*/
        $(document).on('click', '#formatdiv .post-format', function() {
            var format = $(this).val();
            show_metabox(format);
        });
    }
    $(document).ready(function() {
        post_formats();
    });
})(jQuery);