﻿var cursor_in = 1;

window.onload = function(){
  //SetImageSize();
}

window.onresize = function(){
  SetImageSize();
}

function SetImageSize(){

  if (fitsInWindow()) return;

  img = document.getElementById("image");

  imageRatio = imageWidth   / imageHeight;
  tableRatio = tableWidth() / tableHeight();

  if (imageRatio >= tableRatio){
    img.width  = tableWidth();
    img.height = tableWidth() / imageWidth * imageHeight;
    return;
  }else{
    img.height = tableHeight();
    img.width  = tableHeight() / imageHeight * imageWidth;
    return;
  }
}

function scaleImage(){

  if (fitsInWindow()) return;

  if(cursor_in)
    cursor_in = 0;
  else
    cursor_in = 1;

  img = document.getElementById("image");

  if (img.width == imageWidth && img.height == imageHeight){
    SetImageSize();
  }else{
    img.width  = imageWidth;
    img.height = imageHeight;
  }

}

function fitsInWindow(){

  img = document.getElementById("image");

  if (imageHeight > tableHeight() || imageWidth > tableWidth()){

   if(cursor_in)
     document.getElementById("url").style.cursor = "url(\\img\\zoom_in.cur), hand";
   else
     document.getElementById("url").style.cursor = "url(\\img\\zoom_out.cur), hand";

    document.getElementById("url").setAttribute("href", url);
    return false;

  }else{

    document.getElementById("url").removeAttribute("href");
    document.getElementById("url").removeAttribute("style");
    return true;

  }
}

function tableWidth(){
  return windowWidth() - 21;
}

function tableHeight(){
  return windowHeight() - 70 - skipHeight;
}

function windowWidth(){
  if (navigator.appName == "Netscape")
    return window.innerWidth;
  return document.body.offsetWidth;
}

function windowHeight(){
  if (navigator.appName == "Netscape")
    return window.innerHeight;
  return document.body.offsetHeight;
}