// Dimin Image JavaScript Tools
// Copyright (c) 2003 Dmitry Fedorov
// Designed for IE 4 and up, Netscape 7 and up
// v 1.2 

var oW=1, oH=1;
var vImageWidth=640, vImageHeight=640;
var newWidth, newHeight;
var maxWidth = 640;
var maxHeight = 500;

function adjustSize(myImage)
{
  if ( (oW > 1) && (oH > 1) )
  {
    vImageWidth  = oW;  
    vImageHeight = oH;
  }
  else
  {
    oW = myImage.width;
    oH = myImage.height;
    vImageWidth  = oW;  
    vImageHeight = oH;
  }  
  
  newWidth  = vImageWidth;
  newHeight = vImageHeight;
  
  if (vImageWidth >= vImageHeight)
  {
    if (vImageWidth >= maxWidth)
    {
      newWidth = maxWidth;
      newHeight = vImageHeight * (maxWidth/vImageWidth);	 
    }
    else
    {
      newWidth  = vImageWidth;
      newHeight = vImageHeight;
    }
  } // if width larger then height
  else
  {
    if (vImageHeight >= maxHeight)
    {
      newHeight = maxHeight;
      newWidth = vImageWidth * (maxHeight/vImageHeight);	 
    }
    else
    {
      newWidth  = vImageWidth;
      newHeight = vImageHeight;
    }
  } // if height larger then width
  
  myImage.width = newWidth;  
  myImage.height = newHeight;
  vImageWidth = newWidth;
  vImageHeight = newHeight;  
}

function setZoom(zoom, myImage) 
{
  if (zoom == -1)
  {
    vImageWidth    = vImageWidth / 2;
    vImageHeight   = vImageHeight / 2;
    myImage.width  = vImageWidth;
    myImage.height = vImageHeight;
  }
  if (zoom == 1)
  {
    vImageWidth    = vImageWidth * 2;
    vImageHeight   = vImageHeight * 2;
    myImage.width  = vImageWidth;
    myImage.height = vImageHeight;
  }
}

function getImageSize(myImage) 
{
  newImg = new Image ();
  newImg.src = myImage.src;
  oW = newImg.width;
  oH = newImg.height;
  delete newImg;
}

function init(myImage) 
{
  getImageSize(myImage);
  if ( (oW > maxWidth) || (oH > maxHeight) )
    adjustSize(myImage);
}




