/***********************************************************
   Core Functions
***********************************************************/

function getAttributeValue(elt,attName) {
  var retval;
  if (elt.getAttribute) {
    retval = elt.getAttribute(attName);
  } else if ((elt.attributes) && (elt.attributes[attName])) {
    retval = elt.attributes[attName].value;
  }
  return retval;
}

function setAttributeValue(elt,attName,attValue) {
  if (elt.setAttribute) {
    elt.setAttribute(attName,attValue);
  } else if ((elt.attributes) && (elt.attributes[attName])) {
    elt.attributes[attName].value = attValue;
  }
}

/***********************************************************
   For Documents with Thumbnails
***********************************************************/

function getImageDataBySrc(srcStr) {
  for (j = 1; j < imageSizes.length; j++) {
    if (srcStr.indexOf(imageSizes[j].url) > -1) {
      return imageSizes[j];
    }
  } 
  var genericImageData = {url: srcStr, h: 24, w: 24};
  return genericImageData;
}

function applyToThumbs(theFunction, theNode) {
  if (theNode == null) {    theNode = document;  }  var theImgs = theNode.getElementsByTagName('IMG');
  for (count = 0; count < theImgs.length; count++) {    var thisImg = theImgs[count];
    var theSrc = getAttributeValue(thisImg, 'SRC');
    if (theSrc.match(/\/thumbs\//) != null) {
      theFunction(thisImg);
    }  }}function translateSrc(str) {  var result = str.match(/(.*\/)thumbs\/([-_a-zA-Z0-9]*[-_a-z0-9])([A-Z]*).gif$/);  if (result != null) {    var prefix = result[1];    var filename = result[2];    var suffix = result[3];    return(prefix + 'fullsize/' + filename + '.gif');  }}function openFullsize() {  var theThumb = this;
  var theThumbSrc = getAttributeValue(theThumb, 'SRC');
  var theFullSrc = translateSrc(theThumbSrc);
  var theImageData = getImageDataBySrc(theFullSrc);
  var imgHeight = theImageData.h;
  var imgWidth = theImageData.w;
  var wWidth; var wHeight;
  if ((imgWidth > 32) && (imgHeight > 32)) {
    wWidth = imgWidth + 96; 
    wHeight = imgHeight + 264;
  } else {
    wWidth = 840; 
    wHeight = 840;
  }
  var wFeatures = "width=" + wWidth + ",height=" + wHeight;
  var w = window.open('imageview.html?mainImage='+theFullSrc,'',wFeatures);}function initThumbs() {
  applyToThumbs(addBehaviorToThumbnail);
  applyToThumbs(cursorPointer);
//  applyToThumbs(prefetchFullsize);
}

function prefetchFullsize(theThumb) {
  var theImage = new Image();
  theImage.src = translateSrc(getAttributeValue(theThumb,'SRC'));
  return theImage;
}

function cursorPointer(theThumb) {
  if (theThumb.style != null) {
    theThumb.style.cursor = "pointer";
  }
}

function addBehaviorToThumbnail(theThumb) {
  theThumb.onclick = openFullsize ;
}
 
/***********************************************************
   For Pop-ups with Full-size Images
***********************************************************/

function loadImage() {  var locStr = document.location.toString();  var result = locStr.match(/.*mainImage=(.*)$/);  var theMainImage = document.getElementById('mainImage');
  theMainImage.setAttribute('SRC', result[1]);  theMainImage.src = result[1];
}function sizeWindowByImage() {  var theMainImage = document.getElementById('mainImage');  var theWidth = theMainImage.width;
  var theHeight = theMainImage.height;
  if ((theWidth > 32) && (theHeight > 32)) {    window.resizeTo(theWidth + 96, theHeight + 264);  } else {    window.resizeTo(840, 840);  }}function loadCaption() {  var locStr = document.location.toString();  var result = locStr.match(/.*mainImage=.*\/([^\/]+).gif$/);  if ((result != null) && (result[1] != null)) {    setCaption(result[1]);  }}function setCaption(captionId) {  var theCaptionSpan = document.getElementById(captionId);  if (theCaptionSpan != null) {    var theTableRow = document.getElementById('captionRow');
    theTableRow.style.display = "";
    theCaptionSpan.style.display = "";
  }}      