// DynamicZoomClick by Nathaniel Dragon (Nathaniel J. Bird)
// Original created on September 14th & 15th, 2007
// Version 1.2 update on December 18th, 2007
// www.dragonshobbies.com

// Set these two variables to the maximum widths and heights that you normally 
//  want displayed on your website. If images are wider than your maxwidth, 
//  they will be resized based on that, otherwise they will be compared to the
//  maxheight for adjustment. 
var maxwidth = 400;
var maxheight = 400;

function dynamicZoomClickPrep() 
{
  if(navigator.appName=="Microsoft Internet Explorer")
  {
    // Do nothing.
    // Since I haven't figured out how to get the click zoom to work for IE, 
    // I have decided to disable the shrinking. 
  }
  else
  { 
    var imgs = document.getElementsByTagName("img");
    
    for(i=0 ; i<imgs.length ; i++){
    
      var oneimg = imgs[i];    
      var imgwidth = oneimg.width;
      var imgheight = oneimg.height;
      var zoom = 1;
      if(imgwidth > maxwidth)
      {
         zoom = maxwidth/imgwidth;
      }
      else if(imgheight > maxheight)
      {
         zoom = maxheight/imgheight;
      }
  
      if(zoom!=1)
      {
         oneimg.setAttribute("id", "img"+i);
         var zoomstring = "dynamicZoomClick('img"+i+"','"+imgwidth+"','"+imgheight+"','"+zoom+"')";   
         oneimg.setAttribute('onclick',''+zoomstring);
         oneimg.setAttribute('alt',''+zoomstring);
         oneimg.setAttribute('style','cursor: -moz-zoom-in;');
         oneimg.setAttribute('class','dzcimg');
         oneimg.width=imgwidth*zoom;
         oneimg.height=imgheight*zoom;
      }  
    }
  }
}

function dynamicZoomClick(id,actualwidth,actualheight,zoom)
{
  //alert(''+imgid+', '+actualwidth+', '+actualheight+', '+zoom);
  var image = document.getElementById(id);
  if(image.width!=actualwidth)
  {
    image.width=actualwidth;
    image.height=actualheight;
    image.setAttribute('style','cursor: -moz-zoom-out;');
    image.setAttribute('class','dzcimg0');
  }
  else
  {
    image.width=actualwidth*zoom;
    image.height=actualheight*zoom;
    image.setAttribute('style','cursor: -moz-zoom-in;');
    image.setAttribute('class','dzcimg1');
  }
}

function notice(msg)
{
  alert(""+msg);
}
