/* Javascript originally written by: Brett Chang of evercloud.com */
/* Javascript altered to create one Div with a class of "caption" containing the image and the images alt-text displayed within a span for flexible styling abilities (plus it's a bit cleaner output and since an image is not tabular data, why would it be in a table?)*/

var IMAGE_TRACKER = new Array();

function addImgCaption(myImgElem)

{

 var myParent = myImgElem.parentNode;

 var myParentParent = myImgElem.parentNode.parentNode;

 var myWrapperTable = null;

 var myNodeForAppend = myImgElem; function createDiv(myImgElem, myNodeForAppend)

 {

  var eDiv = document.createElement("div");

  var eBr = document.createElement("br");
  
  var eSpan = document.createElement("span");

  var eCaption =  document.createTextNode (myImgElem.getAttribute('alt'));

//stylin'!

  eDiv.className = "caption";
  eDiv.style.width=myImgElem.getAttribute("width")+"px";
  eDiv.style.cssFloat=myImgElem.getAttribute("align");
  eDiv.style.styleFloat=myImgElem.getAttribute("align");
	

//create the table structure
  eDiv.appendChild(myNodeForAppend);
  eDiv.appendChild(eBr);
  
  var imgAlt = myNodeForAppend.getAttribute("alt");
  var imgSrc = myNodeForAppend.getAttribute("src");  //http://temp.artofthepeace.ca/wp-content/uploads/2007/04/euphemia.jpg
  var imgSplit = imgSrc.split("/");
  var imgCount = (imgSplit.length-1);
  var imgName = imgSplit[imgCount];

  if(imgName != imgAlt){
	  eDiv.appendChild(eSpan);
  	  eSpan.appendChild(eCaption);
  }
  
  	myNodeForAppend.removeAttribute("alt");
	myNodeForAppend.removeAttribute("title");
    myNodeForAppend.removeAttribute("align");
  
return eDiv;

 }

 if(null == IMAGE_TRACKER[myImgElem.getAttribute('src')])

 {

if(myParent.nodeName == 'A'){

   myNodeForAppend = myParent;

   myWrapperDiv = createDiv(myImgElem, myNodeForAppend);

   myParentParent.appendChild(myWrapperDiv);

  }

  else

  {

   myWrapperDiv = createDiv(myImgElem, myNodeForAppend);

   myParent.appendChild(myWrapperDiv);

  }

  IMAGE_TRACKER[myImgElem.getAttribute('src')] = '1';

 }

}