function addCaptionsToImages() {
   wrapImagesInDiv( '', [], [ '' ] );
}

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);
}





function wrapImagesInDiv( className, attributes, styles ) {
   var images = page_contentarea_content_body.getElementsByTagName("IMG");
   for ( var i = 0; i < images.length; ++i ) {
      var img = images[i];

      if (img.getAttribute('className')!="noimagecaption"){ 

          // Lift the image out of the page and insert a div under it.
          var parent = img.parentNode;
          var frame = document.createElement('div');
          var txtarea = document.createElement('div');
          var txt = document.createTextNode(img.getAttribute('alt'));

          parent.insertBefore(frame, img);
          parent.removeChild(img);
          frame.appendChild(img);
          frame.appendChild(txtarea);
          txtarea.appendChild(txt);

          // These are special cases.  We always copy these from the image to the
          // div.
          frame.style.width = img.getAttribute('width') + 'px';
          txtarea.style.width = img.getAttribute('width') + 'px';
          if(img.align=='right'){
              frame.className = "captionedImage_Right";
              parent.className = "captionedImage_P";
          }else if(img.align=='left'){
              frame.className = "captionedImage_Left";
              parent.className = "captionedImage_P";
          }else{
              frame.className = "captionedImage";
          }
          img.align = "";
          img.setAttribute('alt', '');
          txtarea.className = "captionedImageText";


          // Copy specified attributes and style properties from the image to the
          // div.
          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]];
          }
      }   
   }
}

