(function($) {
    function upload_field() {
        $(document).on('rad_upload', function(e, data, $input) {
            $('#slider_board .inside').css('background-image', 'url(' + data.url + ')');
            $('#slider_board .inside').css('background-size', 'cover');
        });
        if ($('input#field-background-image').val() != '') {
            $('#slider_board .inside').css('background-image', 'url(' + $('.slider-image-upload img').attr('src') + ')');
            $('#slider_board .inside').css('background-size', 'cover !important');
        }
    }

    function ColorPicker() {
        if (!$.fn.wpColorPicker) return;
        $('#slider_options .colorinput').each(function() {
            $(this).wpColorPicker({
                palettes: false
            });
        });
    }

    function select_fields() {
        $('#slider_options #field-button-text').on('input', function() {
            $('#slider_board .button-lable span').html($(this).val());
        }).trigger('input');
        $('#slider_options textarea[name="title-text"]').on('input', function() {
            $('#slider_board .title-lable span').html($(this).val());
        }).trigger('input');
        $('#slider_options textarea[name="subtitle1-text"]').on('input', function() {
            $('#slider_board .subtitle1-lable span').html($(this).val());
        }).trigger('input');
        $('#slider_options textarea[name="subtitle2-text"]').on('input', function() {
            $('#slider_board .subtitle2-lable span').html($(this).val());
        }).trigger('input');
    }
    $(document).ready(function() {
        $('#postdivrich').addClass('hide-box');
        $('#postimagediv').addClass('hide-box');
        ColorPicker();
        upload_field();
        select_fields();
    });
})(jQuery);