
var maxW = 0;
var maxH = 0;

function toggleSize(image) {
  var dimensions = getWindowDimensions();
  var imagePos = findPos(image);
  var raysh = image.width / image.height;
  if (!maxW) {
    maxW = image.width;
    maxH = image.height;
  }
  if (image.width == maxW && image.height == maxH && (image.width < dimensions[0] && image.height < dimensions[1])) {
  } else if (image.width != maxW) {
    image.width = maxW;
    image.height = maxH;
  } else {
    image.height = dimensions[1] - imagePos[1] - 10;
    image.width = image.height * raysh;
  }
  return 0;
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];
}

function getWindowDimensions() {
  var ww;
  var wh;
  d = document;
  if (typeof window.innerWidth != 'undefined') {
    ww = window.innerWidth;  // NN and Opera version
    wh = window.innerHeight;  // NN and Opera version
  } else {
    if (d.documentElement &&
        typeof d.documentElement.clientWidth!='undefined' &&
        d.documentElement.clientWidth != 0) {
      ww = d.documentElement.clientWidth;
      wh = d.documentElement.clientHeight;
    } else {
      if (d.body && typeof d.body.clientWidth != 'undefined') {
        ww = d.body.clientWidth;
        wh = d.body.clientHeight;
      } else {
        alert ("Can't identify width - please tell me which browser you are using.");
      }
    }
  }
  return [ww,wh];
}


