function box(style, head, copy, image) {
  if (copy) {
    output = '';
    if (image) {
      output += '<img class="' + style + 'img" src="' + image + '">';
    }
    output += '<div class="' + style + '">';
    if (!image) {
      output += '<div class="header"></div>';
    }
    output += '<h3>' + head + '</h3>';
    output += copy;
    output += '<div class="footer"></div>';
    output += '</div>';

    document.write(output);
  }
}

function addCaptionsToImages() {
  wrapImagesInDiv('snapshot', [], ['float']);
}

function wrapImagesInDiv(className, attributes, styles) {
  var images = document.getElementsByClassName(className);
  for (var i = 0; i < images.length; ++i ) {
    var img = images[i];
    var parent = img.parentNode;
    var frame = document.createElement('div');
    var txt = document.createTextNode(img.getAttribute('title'));

    parent.insertBefore(frame, img);
    parent.removeChild(img);
    frame.appendChild(img);
    frame.appendChild(txt);

    frame.style.width = img.width + 'px';
    frame.className = img.className;

    for (var j = 0; j < attributes.length; ++j) {
      frame.setAttribute(attributes[j], img.getAttribute(attributes[j]));
    }
    for (var j = 0; j < styles.length; ++j) {
      frame.style[styles[j]] = img.style[styles[j]];
    }
  }
}

addLoadEvent(addCaptionsToImages);
