// http://demo.1976design.com/image-captions/
// http://demo.1976design.com/blockquotes/


function extractImageTitles() {
  var images = document.getElementsByTagName('img');
  for (var i = 0; i < images.length; i++) {
    var title = images[i].getAttribute('title');
    if (title && title != '') {
      var Caption = document.createElement('div');
      Caption.className = 'caption';
      if (matches = title.match(/(.*?)\?\?(.+?)\?\?(.*)/)) {
        while (matches = title.match(/(.*?)\?\?(.+?)\?\?(.*)/)) {
          var Cite = document.createElement('cite');
          Cite.appendChild(document.createTextNode(matches[2]));
          Caption.appendChild(document.createTextNode(matches[1]));
          Caption.appendChild(Cite);
          title = matches[3];
        }
        Caption.appendChild(document.createTextNode(title));
      } else {
        Caption.appendChild(document.createTextNode(title));
      }
      images[i].parentNode.appendChild(Caption);
      images[i].removeAttribute('title');
    }
  }
}

Event.observe(window, 'load', extractImageTitles);
