// JavaScript Document

function addCaption(xClass) {
	//var allImages = getElementsByClassName(document, "img", xClass);
	var allImages = getElementsByClassName(xClass, "img", document);
	for ( var i=0; i < allImages.length; i++) {
	var imageCaption = document.createTextNode(allImages[i].title);
	var imageContainer = document.createElement("div");
	var imagePara = document.createElement("p");
	var imageWidth = allImages[i].getAttribute("width");
	var spareSpan = document.createElement("span");
	imagePara.appendChild(imageCaption);
	allImages[i].parentNode.insertBefore(imageContainer, allImages[i]);
	imageContainer.appendChild(allImages[i]);
	if ( allImages[i].title != "" ) {
	imageContainer.appendChild(imagePara);
	}
	imageContainer.appendChild(spareSpan);
	imageContainer.className = xClass
	spareSpan.className = "spareSpan"
	allImages[i].className = "img"
	imageContainer.style.width = imageWidth + "px";
	
	}
}

// Runs all the listed functions on the loading of the window
window.onload=function(){
addCaption("imgLeft");
addCaption("imgRight");
}



