

ex_id = 0;
ex_step = 0;
ex_width = 0;
ex_height = 0;
ex_top = 0;
ex_left = 0;
ex_timeout = 0;
ex_total = 15;

function expand(t_id, fwidth, fheight) {
  if (ex_timeout != 0) {
    clearTimeout(ex_timeout);
  }
  if (ex_id> 0 && ex_id!= t_id) {
    restore();
  }
  if (ex_id!= t_id) {
    img = document.getElementById("full" + t_id);
    img.style.display = 'block';
    ex_id= t_id;
    ex_step = 1;
    ex_width = fwidth;
    ex_height = fheight;
    ex_top = img.offsetTop;
    ex_left = img.offsetLeft;
  } else if (ex_step < 1) {
    ex_step = 1;
  }
   step_exp();
}

function do_exp(){
  img = document.getElementById("full" + ex_id);
  small = document.getElementById("small" + ex_id);
  scrolls = Scroll_get();



  if (ex_top + small.height > scrolls.top + scrolls.height) {
    finaltop = scrolls.top + scrolls.height - ex_height;
  } else {
    finaltop = ex_top + small.height - ex_height;
  }
  if (finaltop < scrolls.top) { finaltop = scrolls.top; }
  img.style.top = finaltop  + ((ex_top - finaltop) * (ex_total - ex_step) / ex_total) + 'px';

  if (ex_left + small.width > scrolls.left + scrolls.width) {
    finalleft = scrolls.left + scrolls.width - ex_width;
  } else {
    finalleft = ex_left + small.width - ex_width;
  }
  if (finalleft < scrolls.left) { finalleft = scrolls.left; }
  img.style.left = finalleft  +((ex_left - finalleft) * (ex_total - ex_step) / ex_total) + 'px';

  img.width = small.width + ((ex_width - small.width) * ex_step / ex_total);
  img.height = small.height + ((ex_height - small.height) * ex_step / ex_total);
}

function restore() {
  img = document.getElementById("full" + ex_id);
  img.style.top = '';
  img.style.left = '';
	
  img.style.display = 'none';
  ex_id= 0;
}

function step_exp() {
  ex_timeout = 0;
  do_exp();
  if (ex_step < ex_total) {
    ex_step++;
    ex_timeout = setTimeout("step_exp();", 20);
  }
}

function step_red() {
  ex_timeout = 0;
  do_exp();
  if (ex_step > 0) {
    ex_step--;
    ex_timeout = setTimeout("step_red()", 20);
  } else {
    restore();
  }
}

function thumb_red(t_id) {
  if (ex_timeout != 0) {
    clearTimeout(ex_timeout);
  }
  if (ex_step > 0) {
    step_red();
  }
}

// returns the scroll position and size of the browser
function Scroll_get() {
  if (document.all && typeof document.body.scrollTop != "undefined") {  
    // IE model
    var ieBox = document.compatMode != "CSS1Compat";
    var cont = ieBox ? document.body : document.documentElement;
    return {
      left:   cont.scrollLeft,
      top:    cont.scrollTop,
      width:  cont.clientWidth,
      height: cont.clientHeight
    };
  } else {
    return {
      left:   window.pageXOffset,
      top:    window.pageYOffset,
      width:  window.innerWidth,
      height: window.innerHeight
    };
  }
}
