var oImageCaptions = {
   init: function() {
      // get all image elements with class "strapline"
      var aImages = YAHOO.util.Dom.getElementsByClassName('caption', 'img');

      // loop through them
      for (var i = 0, j = aImages.length; i < j; i++) {
         // make sure they have title text set
         if (aImages[i].title != '') {
            // save some stuff for later use
            var oParent = aImages[i].parentNode;
            var sTitle = aImages[i].title;
			var sClasses = aImages[i].className;
            
            // clear title and remove the "caption" class
            aImages[i].title = '';
            aImages[i].className = '';
            
            // create new parent container for image
            var oContainer = document.createElement('div');

			// assign classes from img tag
			oContainer.className = sClasses;
            
            // constrain the width and height of DIV to image dimensions
            oContainer.style.width = aImages[i].getAttribute('width') + 'px';
            oContainer.style.height = aImages[i].getAttribute('height') + 'px';
            
            // swap existing image
            oParent.replaceChild(oContainer, aImages[i]);
            oContainer.appendChild(aImages[i]);

			// create strap line
            var oCaption = document.createElement('p');
            oCaption.appendChild(document.createTextNode(sTitle));

			// append strapline to parent container
            oContainer.appendChild(oCaption);

			var iImageWidth = aImages[i].getAttribute('width');
			
            oCaption.style.width = iImageWidth + 'px';
			
			if (oCaption.offsetWidth > iImageWidth) {
				oCaption.style.width = iImageWidth - (oCaption.offsetWidth - iImageWidth) + 'px';
			}
         }
      }
   }
}

YAHOO.util.Event.addListener(window, 'load', oImageCaptions.init);