
function addCaption(oImgElem, bUseCaptionMarker)
{
  // Check that image element not already have a div.imgblock as parent.
  if(oImgElem.parentNode && oImgElem.parentNode.className=="imgblock")
    return;
    
  // Create the div.imgblock element
  // Use style.styleFloat for IE and style.cssFloat for FF       
  var oImgBlockElem = document.createElement("div");
  oImgBlockElem.className = "imgblock";
  oImgBlockElem.style.styleFloat = "right";
  oImgBlockElem.style.cssFloat = "right";
  oImgBlockElem.style.marginRight = "5px";
  if (navigator.userAgent.indexOf('MSIE') ==-1)
  {
	  oImgBlockElem.style.marginLeft = "5px";
  }
    
  if( oImgElem.className.search("leftjust") >= 0 )
  {
    oImgBlockElem.className = oImgBlockElem.className + " leftjust";
    oImgElem.className = oImgElem.className.replace("leftjust","");
  }
  if( oImgElem.className.search("rightjust") >= 0 )
  {
    oImgBlockElem.className = oImgBlockElem.className + " rightjust"; 
    oImgElem.className = oImgElem.className.replace("rightjust","");
  }


  var oHandle = oImgElem;  // oHandle is element that should be moved into our div.imgblock element

  // If the current image has a parent A (anchor/hyperlink) element then
  // we would also like that to go into our div.imgblock, therefore the oHandle
  // is adjusted to point to the A element.
  if(oImgElem.parentNode.tagName == "A")
  {
    oHandle = oImgElem.parentNode;
  }

  //  alert("Before for '" + oImgElem.alt + "'");
  // Replace the oHandle node (the img or a) with our new div.imgblock element.
  var oOldHandle = oHandle.parentNode.replaceChild(oImgBlockElem,oHandle);  // This line sometimes crash in IE with error R6025!
  
  if(false) //bUsePhotoShadow )
  {
    var oPhotoShadowElem = document.createElement("div");
    oPhotoShadowElem.className = "photoshadow";
  
    oImgBlockElem.appendChild(oPhotoShadowElem);
    oPhotoShadowElem.appendChild(oOldHandle);
  }
  else
  {
    oImgBlockElem.appendChild(oOldHandle);
  }
  //oImgBlockElem.appendChild(oOldHandle);
  oHandle=null;
  //  alert("After for '" + oImgElem.alt + "'");


  // Create div.caption element
  var oCaptionElem = document.createElement("div");
  oCaptionElem.className = "caption";
  if (navigator.userAgent.indexOf('MSIE') ==-1)
  {
  	oCaptionElem.style.marginLeft = "0px";
  }	
  //oCaptionElem.style.stylefloat = "right";

  if(bUseCaptionMarker)
  {
    // Create div.caption-marker element
    var oCaptionMarkerElem = document.createElement("div");
    oCaptionMarkerElem.className = "caption-marker";
    var oCaptionMarkerTextElem = document.createTextNode("\u00bb");
    //oCaptionMarkerElem.appendChild(oCaptionMarkerTextElem);
    //oCaptionElem.appendChild(oCaptionMarkerElem );
  }

  // Create div.caption-text element with appropriate alt text
  var oCaptionTextElem = document.createElement("div");
  oCaptionTextElem.className = "caption-text";
  var oCaptionText = document.createTextNode(oImgElem.alt);
  oCaptionTextElem.appendChild(oCaptionText);
  oCaptionElem.appendChild(oCaptionTextElem);

  oImgBlockElem.appendChild(oCaptionElem);

  //return true;
    
  with(oImgElem.style)
  {
    oCaptionElem.style.width = (oImgElem.scrollWidth)-6+"px";
  }
  oImgBlockElem.style.width = (oImgElem.scrollWidth)+"px";

  return true; 
}

function addCaps()
{
  var i=0;
  var oImages = document.images; //document.getElementsByTagName("img"); // document.images
  var oImg;
  //alert("inside addCaps() - " + oImages.length );
  for( i=0; i<oImages.length; i++ )
  {
    oImg = document.images[i];
    //alert("oImg.className = " + oImg.className);
    //if( oImg.className.search("addcap") >= 0 )
	if((oImg.width > 150) && (oImg.alt.length > 0))
    {
      	oImg.style.styleFloat = "left";
		oImg.hspace = "0px";
		addCaption(oImg,true);
    } 
  }

  return true;
}
