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);

			// which box model do we need
			if ((!document.compatMode || document.compatMode == 'BackCompat') && document.all) {
            	oCaption.style.width = aImages[i].getAttribute('width') + 'px';
			} else {
				// get the left and right padding specified in CSS
				// check separately as left and right paddings might have different values
	            var iPadLeft = YAHOO.util.Dom.getStyle(oCaption, 'padding-left').replace('px', '');
	            var iPadRight = YAHOO.util.Dom.getStyle(oCaption, 'padding-right').replace('px', '');
	
				// set width to make strapline stretch full width of image
				oCaption.style.width = (aImages[i].getAttribute('width') - iPadLeft - iPadRight) + 'px';
			}
         }
      }
   }
}

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