<script>
jQuery(function($) {
	var $ = jQuery;
	
	$('.upload_image_button').live('click', function( event ){
	  event.preventDefault();
	  var target = $(this).data('target-id');

	  window.parent.loadImageFrame($(this), function(attachment) {
		jQuery("#" + target).val(attachment.id);
		
		if ( attachment.sizes.thumbnail ) {
		  jQuery("#" + target + "-thumb").attr("src", attachment.sizes.thumbnail.url);
		} else {
		  jQuery("#" + target + "-thumb").attr("src", attachment.url);
		}

		if ( $('#preview-content').length > 0 ) {
		  $('#preview').click();
		}
	  });
	});
});
</script>