﻿function makeImageCaption()
{
	var imageArray = getElementsByClassName("ImageWithCaption", "img");
	for(var i = 0; i < imageArray.length; i++)
	{
		var container = document.createElement("div");
		
		container.className = "ImageWithCaption";
		imageArray[i].parentNode.insertBefore(container, imageArray[i]);
		container.appendChild(imageArray[i]);
		
		if(imageArray[i].getAttribute("title") != "")
		{
			var caption = document.createElement("p");
			caption.appendChild(document.createTextNode(imageArray[i].getAttribute("title")));
			container.appendChild(caption);
		}
		
		container.style.width = imageArray[i].style.width;
		removeClassName(imageArray[i], "ImageWithCaption");
	}
}

addLoadEvent(makeImageCaption);