jQuery(document).ready(function(){
 
    var custom_uploader_hami;
	
 
    jQuery('#picker_check').on('click','#upload_image_button_hami',function(e) {
		
        e.preventDefault();
 
        //If the uploader object has already been created, reopen the dialog
        /*if (custom_uploader) {
            custom_uploader.open();
            return;
        }*/
        //Extend the wp.media object
        custom_uploader_hami = wp.media.frames.custom_uploader_hami = wp.media({
				title: 'Select Splash',
				library: {type: 'image'},
				button: {text: 'Select'},
				multiple: false
            
        });
		
		
        //When a file is selected, grab the URL and set it as the text field's value
        custom_uploader_hami.on('select', function() {
        
			attachment = custom_uploader_hami.state().get('selection').first().toJSON();
            jQuery('#upload_image').val(attachment.url);
			imageUrl = attachment.url;
			jQuery('#set_splash').css('background-image', 'url(' + imageUrl + ')');
			jQuery('#set_splash').css('background-size', '100% 100%');
			jQuery('#set_splash').css('background-repeat', 'no-repeat');
			jQuery('#set_splash').removeClass('hide');
			
        });
 
        //Open the uploader dialog
        custom_uploader_hami.open();
 
    });
	
});