exp_id      = 0;
exp_step    = 0;
exp_width   = 0;
exp_height  = 0;
exp_top     = 0;
exp_left    = 0;
exp_time    = 0;
exp_tsteps  = 15;


function getMouseXY(e)
{
	if (IE)
	{
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	}
	else
	{
		tempX = e.pageX
		tempY = e.pageY
  }
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  return true
}

function imageexpand(thumbid, fullwidth, fullheight) {
  if (exp_time != 0) {
    clearTimeout(exp_time);
  }
  if (exp_id > 0 && exp_id != thumbid) {
    imagerestore();
  }
  if (exp_id != thumbid) {
    img = document.getElementById("screen" + thumbid);
    img.style.display = 'block';
    exp_id = thumbid;
    exp_step = 1;
    exp_width = fullwidth;
    exp_height = fullheight;
    exp_top = img.offsetTop;
    exp_left = img.offsetLeft;
  } else if (exp_step < 1) {
    exp_step = 1; 
  }
  do_a_step();
}

function expandprocess() {
  img = document.getElementById("screen" + exp_id);
  thumb = document.getElementById("thumb" + exp_id);
  myscroll = scrollinfo();
  if (exp_top + thumb.height > myscroll.top + myscroll.height) {
    finaltop = myscroll.top + myscroll.height - exp_height;
  } else {
    finaltop = exp_top + thumb.height - exp_height;
  }
  if (finaltop < myscroll.top) { finaltop = myscroll.top; }
  img.style.top = finaltop + ((exp_top - finaltop) * (exp_tsteps - exp_step) / exp_tsteps) + 'px';

  if (exp_left + thumb.width < myscroll.left + myscroll.width) {
    finalleft = myscroll.left + myscroll.width - exp_width;
  } else {
    finalleft = exp_left + thumb.width - exp_width;
  }
  if (finalleft < myscroll.left) { finalleft = myscroll.left; }
  img.style.left = finalleft + ((exp_left - finalleft) * (exp_tsteps - exp_step) / exp_tsteps) + 'px';

  img.width = thumb.width + ((exp_width - thumb.width) * exp_step / exp_tsteps);
  img.height = thumb.height + ((exp_height - thumb.height) * exp_step / exp_tsteps);
}

function imagerestore() {
  img = document.getElementById("screen" + exp_id);
  img.style.top = '';
  img.style.left = '';
  img.style.display = 'none';
  exp_id = 0;
}

function do_a_step() {
  exp_time = 0;
  expandprocess();
  if (exp_step < exp_tsteps) {
    exp_step++;
    exp_time = setTimeout("do_a_step()", 20);
  }
}

function reducestep() {
  exp_time = 0;
  expandprocess();
  if (exp_step > 0) {
    exp_step--;
    exp_time = setTimeout("reducestep()", 20);
  } else {
    imagerestore();
  }
}

function imagereduce(thumbid) {
  if (exp_time != 0) {
    clearTimeout(exp_time);
  }
  if (exp_step > 0) {
    reducestep();
  }
}

function scrollinfo() {
  if (document.all && typeof document.body.scrollTop != "undefined") {  
    var ieBox = document.compatMode != "CSS1Compat";
    var cont = ieBox ? document.body : document.documentElement;
    return {
      left:   cont.scrollLeft,
      top:    cont.scrollTop,
      width:  cont.clientWidth-10,
      height: cont.clientHeight
    };
  } else {
    return {
      left:   window.pageXOffset,
      top:    window.pageYOffset,
      width:  window.innerWidth-30,
      height: window.innerHeight  
    };
  }
}
