/*
 * (C) 2004 Edward Kujawski, CDC

 * This code will switch out a focal stack for the attached viewer.

 * the reads the mouse, and searches for the max/min heigth on the screen

 * and resets the max/min every 10 seconds, just in case the window was moved/resized

 *
 */
var
  date = new Date(),
  img = new Array(32),
  base_filename,
  max_files;

found_max=0;
found_min=0;
last_time=date.getTime();
//base_filename='focus-test-';
//max_files=32;

function mousemove(e)
{ 
//window.alert(e.screenY);

  if ( !e )
    e = window.event;
  if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4)
    y=e.screenY;
  else
    y=e.clientY;
//window.alert(window.event);
  date= new Date();
  if ( ( ( found_max==0 ) && ( found_min==0 ) ) || ( (date.getTime() - last_time) > 10000 ) )
    {
      found_max=y;
      found_min=y;
    }  
  last_time=date.getTime();
  if ( y < found_min )
    found_min=y;
  if ( y > found_max )
    found_max=y;
  
  if ( found_max == found_min )
    y=0;
  else
    y=1.0*(max_files-1)*(y-found_min)/(found_max-found_min);
  y=parseInt(y);
  
  if ( y < 10 ) 
    {
      y="0"+y;
    }
 

  if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4) 
    {
      document.layers['dispdiv'].src=base_filename + y + "_www.jpg";
      document.layers['dispdiv'].onmousemove=mousemove;
      document.layers['dispdiv'].captureEvents(Event.MOUSEMOVE);
    }
  else
    document.dispimg.src=base_filename + y + "_www.jpg";
}

function load_images(nbase_filename,nmax_files)
{
  base_filename=nbase_filename;
  max_files=nmax_files;

  for (i=0; i<max_files; i++)
    {
      img[i] = new Image();
      if ( i<10 )
	img[i].src=base_filename + "0" + i + "_www.jpg";
      else
	img[i].src=base_filename +       i + "_www.jpg";

    }

}

