function removeLibraryValue(fieldName) {
  // Hide [fieldName]Div field - contains thumbnail or filename
  $("div#" + fieldName + "Div img").attr({
    src: "/spacer.gif",
    width: "",
    height: ""
  });

  $("input#" + fieldName).val('');
}

$(document).ready(function() {
  $(".radioGroup").each(function(i) {
    if ( !$(this).find('input[type=radio]:checked').length ) $(this).find('input[type=radio]:first').attr('checked', 'checked');
  });
  $(".hidden input").each(function() {
    var d = new Date();
    $(this).val('cb-' + d.getTime());
  });
  $(".editForm input[type=text]:first").focus();
});

$(window).load(function() {
  // Adding "delete" option to Library field types
  // Look for image/file/media DIVs
  $(".editForm div[id*='Div']").each(function() {
    var id = $(this).attr('id').replace('Div', '');
    // Append delete button to end of image...
    if ( $("input#" + id).length && $("input#" + id).val()) $(this).append(' <a href="#" onclick="removeLibraryValue(\'' + id + '\'); return false;"><img src="/item-delete-red.gif" width="9" height="9" alt="Delete" /></a>');

    var img = $(this).find("img");
    var imgSrc = img.attr("src");
    if (imgSrc == '/' || imgSrc.substr(0,2) == '/?') {
      img.attr({
        src: "/spacer.gif",
        width: "",
        height: ""
      });
    } else if (imgSrc != '') {
      var imgWidth = img.width();
      var imgHeight = img.height();

      if (imgWidth > 120 || imgHeight > 120) {
        var factor = (imgWidth > imgHeight) ? imgWidth / 120 : imgHeight / 120;
        factor = Math.ceil(factor * 120) / 120;
        img.width(imgWidth / factor);
        img.height(imgHeight / factor);
      }
    }
  });
});
