/*
	Auto captions for unconfirmedsources.com by Kelly Taylor.  Hemlock at grnet dot com.

	I got the idea from http://www.suodenjoki.dk/us/productions/articles/addcaption.htm
	and just rolled my own, cuz I like to do that stuff.	If you want to use it, go ahead; just
	leave me some credit in this file or on your page, please.
*/


if (window.addEventListener)
	window.addEventListener("load", captions, false);
else if (window.attachEvent)
	window.attachEvent("onload", captions);

captions.MINSIZE = 100;
captions.IMAGESOURCE = /\/nucleus\/media\//i;
function captions()
{
	var images = document.getElementsByTagName("IMG");
	for ( var i=0; i< images.length; i++)
	{
		var image = images[i];
		if (image.offsetWidth > captions.MINSIZE && image.src.match(captions.IMAGESOURCE))
		{
			var text = image.caption || image.getAttribute("caption") || image.alt || "";
			if (text)
			{
				var div = document.createElement("div");
				div.className = "caption";

				div.appendChild(document.createTextNode(text));
				div.style.width = image.offsetWidth + "px";

				if(image.nextSibling)
					image.parentNode.insertBefore(div,image.nextSibling);
				else
					image.parentNode.appendChild(div);
			}
		}
	}
};
