if(!document.getElementById('imageGallery')) {}
else{
  var staticImg = document.getElementById('imageGallery').getAttribute('src');
  if(document.getElementById('thisPicture')) {
      document['thisPicture'].src = staticImg;
      originalImg = staticImg;
    }
}


function resizeImg(which) {
  var elem = document.getElementById('imageGallery');
  if (elem == undefined || elem == null){ return false; }
  var newImg = new Image();
  newImg.src = document.getElementById('imageGallery').getAttribute('src');
  var curW = newImg.width;
  var curH = newImg.height;
  var origImg = new Image();
  origImg.src = staticImg;
  var maxw = origImg.width;
  var maxh = origImg.height;
  if (curW > curH) {
      var aspect = curH/curW;
      var aspect = Math.round(aspect*100)/100;
      var newDim = aspect*maxw;
      var newDim = Math.round(newDim*100)/100;
      var newGap = maxh - newDim;
      var newGap = Math.round(newGap);
      if(newGap<=0){newGap=10;}else{newGap=newGap+10;}
      document.getElementById('imageGallery').setAttribute("height", newDim);
      paddingX = (newGap)/2;
      
      if(paddingX>3){paddingX = paddingX + "px";document.getElementById('imageGallery').style.marginTop = paddingX;}
      else{paddingX = paddingX + "px"; document.getElementById('imageGallery').style.marginTop = 3;}
      document.getElementById('imageGallery').style.marginBottom = paddingX;
  } else {
      var aspect = curW/curH;
      var aspect = Math.round(aspect*100)/100;
      var newDim = aspect*maxh;
      var newDim = Math.round(newDim*100)/100;
      var newGap = maxw - newDim;
      var newGap = Math.round(newGap);
      if(newGap<=0){newGap=10;}else{newGap=newGap+10;}
      document.getElementById('imageGallery').setAttribute("width", newDim);
      paddingX = (newGap)/2;
      paddingX = paddingX + "px";
      document.getElementById('imageGallery').style.marginLeft = paddingX;
      document.getElementById('imageGallery').style.marginRight = paddingX;
  }
}


function changeIt(imageName,objName)
{
var imgsrc = document.getElementById(objName).getAttribute('src');;
if(imageName=="ORIGINAL"){
document.getElementById(objName).src = staticImg;
}else{

document.getElementById(objName).src = imageName;
}
resizeImg(objName);
return;
}


function imgWindow(imageName)
{
  var newImg = new Image();
  newImg.src = imageName;
    if(imageName == "ORIGINAL"){
       newImg.src = staticImg;
    }
  var curW = newImg.width + 45;
  var curH = newImg.height + 135;
  var my_window = window.open ("", "mywindow1","status=1, width=200, height=200, top=200px, left=10px");
  var htmlToOpen = '<html><head><title>Infrared Image Gallery</title></head>';
  htmlToOpen += '<body bgcolor=#131E22><div align="center"><img style="padding:3px;" src="' + newImg.src + '" />';
  htmlToOpen += '<br /><input type="button" value="Close" onClick="javascript:window.close()" />';
  htmlToOpen += '</div></body></html>';
  my_window.document.write(htmlToOpen); 
  my_window.resizeTo(curW, curH);
  my_window.focus();
  my_window.document.close();

}

