// ImageText.js
// This file will swap text for images with appropreate attributes:
// NOTE must be applied to inline "span" tags
// replacement="" - REQUIRED - the source file for the image
//
//First check the name space...

var com;
if (!com || !com.jchristy) { throw new Error("com.jchristy: Required object 'com.jchristy.Support' does not exist."); }
if (!com.jchristy.Handler) { throw new Error("com.jchristy: Required object 'com.jchristy.Handler' does not exist."); }

//Name space is ready.

com.jchristy.ImageText = {}; 
com.jchristy.ImageText.addImage = function() {
	if (!com.jchristy.Support.features.HTML1) { return; }
	
	var spans = document.getElementsByTagName("span");
	var swap = [];
	var imgs = [];
	for (var i = 0; i < spans.length; i++) {
		var imgSource = spans[i].getAttribute("replacement");
		if (imgSource) {
			var img = document.createElement("img");
			img.src = imgSource;
			imgs.push(img);
			swap.push(spans[i]);
		}
	}
	for (var i = 0; i < swap.length; i++) {
		swap[i].parentNode.replaceChild(imgs[i], swap[i]);
	}

}
if(document.getElementsByTagName("body").item(0)) {
	com.jchristy.ImageText.addImage();
} else {
	com.jchristy.Handler.add(window, "load", com.jchristy.ImageText.addImage);
}