jQuery(function(jQuery) { jQuery('.custom_upload_image_button').click(function() { formfield = jQuery(this).siblings('.custom_upload_image'); preview = jQuery(this).siblings('.custom_preview_image'); tb_show('', 'http://www.thebsa.org.uk/wp-admin//media-upload.php?type=image&TB_iframe=true&width=640&height=500'); window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); classes = jQuery('img', html).attr('class'); id = classes.replace(/(.*?)wp-image-/, ''); formfield.val(id); preview.attr('src', imgurl); tb_remove(); } return false; }); jQuery('.custom_upload_image_button_user').click(function() { formfield = jQuery(this).siblings('.custom_upload_image_user'); preview = jQuery(this).siblings('.custom_preview_image_user'); tb_show('', 'http://www.thebsa.org.uk/wp-admin//media-upload.php?type=image&TB_iframe=true&width=640&height=500'); window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); classes = jQuery('img', html).attr('class'); id = classes.replace(/(.*?)wp-image-/, ''); formfield.val(id); preview.attr('src', imgurl); tb_remove(); } return false; }); jQuery('.custom_clear_image_button_user').click(function() { var defaultImage = jQuery(this).parent().siblings('.custom_default_image_user').text(); jQuery(this).parent().siblings('.custom_upload_image_user').val(''); jQuery(this).parent().siblings('.custom_preview_image_user').attr('html', defaultImage); jQuery(this).parent().siblings('.custom_preview_image_user').hide(); return false; }); });