(function($) {
    "use strict";
    $(document).ready(function($){
        var mediaUploader;
        $('#exporo-cat-upload-button').click(function(e) {
            e.preventDefault();
            if (mediaUploader) {
                mediaUploader.open();
                return;
            }
            mediaUploader = wp.media({
                title: exporoGenParams.chooseImage,
                button: {
                    text: exporoGenParams.useImage
                },
                multiple: false 
            });
            mediaUploader.on('select', function() {
                var attachment = mediaUploader.state().get('selection').first().toJSON();
                $('#exporo_cover').val(attachment.url);
            });
            mediaUploader.open();
        });
    });
})(jQuery);