Index: wp-admin/includes/media.php
===================================================================
--- wp-admin/includes/media.php	(revision 19901)
+++ wp-admin/includes/media.php	(working copy)
@@ -386,7 +386,7 @@
 	return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='{$id}-add_{$type}' class='thickbox add_$type' title='" . esc_attr( $title ) . "'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' onclick='return false;' /></a>";
 }
 
-function get_upload_iframe_src( $type = null ) {
+function get_upload_iframe_src( $type = null, $tab = null ) {
 	global $post_ID;
 
 	$uploading_iframe_ID = (int) $post_ID;
@@ -395,6 +395,9 @@
 	if ( $type && 'media' != $type )
 		$upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
 
+	if ( $tab )
+		$upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src);
+
 	$upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
 
 	return add_query_arg('TB_iframe', true, $upload_iframe_src);
Index: wp-admin/js/custom-background.dev.js
===================================================================
--- wp-admin/js/custom-background.dev.js	(revision 19901)
+++ wp-admin/js/custom-background.dev.js	(working copy)
@@ -10,6 +10,14 @@
 		jQuery('#clearcolor').hide();
 }
 
+function send_to_editor( data ) {
+	data = jQuery.parseJSON(data);
+	jQuery.post(ajaxurl, { action: 'set-background-image', attachment_id: data.id, size: data.size }, function(){
+		tb_remove();
+		window.location.reload();
+	});
+}
+
 jQuery(document).ready(function() {
 	jQuery('#pickcolor').click(function() {
 		jQuery('#colorPickerDiv').show();
Index: wp-admin/custom-background.php
===================================================================
--- wp-admin/custom-background.php	(revision 19901)
+++ wp-admin/custom-background.php	(working copy)
@@ -69,6 +69,9 @@
 		add_action("load-$page", array(&$this, 'admin_load'));
 		add_action("load-$page", array(&$this, 'take_action'), 49);
 		add_action("load-$page", array(&$this, 'handle_upload'), 49);
+		add_filter('attachment_fields_to_edit', array(&$this, 'attachment_fields_to_edit'), 10, 2);
+		add_filter('image_send_to_editor', array(&$this, 'image_send_to_editor'), 10, 7);
+		add_filter('media_upload_tabs', array(&$this, 'filter_upload_tabs'));
 
 		if ( $this->admin_header_callback )
 			add_action("admin_head-$page", $this->admin_header_callback, 51);
@@ -96,6 +99,8 @@
 			'<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
 		);
 
+		add_thickbox();
+		wp_enqueue_script('media-upload');
 		wp_enqueue_script('custom-background');
 		wp_enqueue_style('farbtastic');
 	}
@@ -246,7 +251,13 @@
 <input type="hidden" name="action" value="save" />
 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?>
 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
-</form>
+<?php
+	$image_library_url = get_upload_iframe_src('image', 'library');
+	$image_library_url = remove_query_arg('TB_iframe', $image_library_url);
+	$image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url );
+?>
+	</form>
+	<span class="howto"><?php _e('or'); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a>
 </td>
 </tr>
 </tbody>
@@ -366,4 +377,47 @@
 		$this->updated = true;
 	}
 
+	function attachment_fields_to_edit( $form_fields, $post ) {
+		if ( !isset( $_REQUEST['context'] ) ) return $form_fields;
+		if ( $_REQUEST['context'] != 'custom-background' ) return $form_fields;
+
+		$form_fields = array( 'image-size' => $form_fields['image-size'] ); // Reset
+		$button = get_submit_button( __( 'Use as background image' ), 'button', "send[{$post->ID}]", false );
+		$form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' );
+		$form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' );
+
+		return $form_fields;
+	}
+
+	function image_send_to_editor( $html, $id, $caption = '', $title = '', $align = '', $url = '', $size ) {
+		if ( !isset( $_REQUEST['attachments'][$id]['context'] ) ) return $html;
+		if ( $_REQUEST['attachments'][$id]['context'] != 'custom-background' ) return $html;
+
+		return json_encode( array( 'id' => $id, 'size' => $size ) );
+	}
+
+	function filter_upload_tabs ( $tabs ){
+		if ( !isset( $_REQUEST['context'] ) ) return $tabs;
+		if ( $_REQUEST['context'] != 'custom-background' ) return $tabs;
+
+		return array( 'library' => __('Media Library') );
+	}
 }
+
+function wp_set_background_image() {
+	if ( ! current_user_can('edit_theme_options') ) exit;
+	if ( ! isset( $_POST['attachment_id'] ) ) exit;
+	$attachment_id = intval($_POST['attachment_id']);
+	$sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) ));
+	$size = 'thumbnail';
+	if ( in_array( $_POST['size'], $sizes ) )
+		$size = esc_attr( $_POST['size'] );
+
+	update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) );
+	$url = wp_get_attachment_image_src($attachment_id);
+	$thumbnail = wp_get_attachment_image_src($attachment_id, $size);
+	set_theme_mod('background_image', esc_url($url[0]));
+	set_theme_mod('background_image_thumb', esc_url($thumbnail[0]));
+	exit;
+}
+add_action('wp_ajax_set-background-image', 'wp_set_background_image');
\ No newline at end of file
