var addCaptionsToImages = function() {
   
   var images = $$('div.obiki-component-static img');
   for ( var i = 0; i < images.length; ++i ) {
      var img = images[i];
      if (img.getAttribute('alt').match(/ /)) {
        // Lift the image out of the page and insert a div under it.
        var parent = img.parentNode;
        var frame = document.createElement('div');
        var captionWrap = document.createElement('div');
        var txt = document.createTextNode(img.getAttribute('alt'));
        parent.insertBefore(frame, img);
        parent.removeChild(img);
        frame.appendChild(img);
        frame.appendChild(captionWrap);
        captionWrap.appendChild(txt);
        // These are special cases.  We always copy these from the image to the
        // div.
        frame.style.width = img.getAttribute('width') + 'px';
        if (img.getAttribute('align') == 'right') {
          Element.setStyle(frame, {float: img.getAttribute('align'), paddingLeft: '30px'});
        } else {
          Element.setStyle(frame, {float: img.getAttribute('align'), paddingRight: '30px'});
        }
        frame.className = 'obiki-inlineimage';
      }
   }
}

if(typeof window.addEventListener != 'undefined') {
   window.addEventListener('load', addCaptionsToImages, false);
}
else if(typeof document.addEventListener != 'undefined') {
   document.addEventListener('load', addCaptionsToImages, false);
}
else if(typeof window.attachEvent != 'undefined') {
   window.attachEvent('onload', addCaptionsToImages);
}

