// Thumbnail expansion and reduction animation
//use expandthumb(142, 500, 449) to increase and 
//reducethumb(142) to decrease the thumbnail
//142 represents the name of the thumbimage.. it should be like thumb142
// for reduceimage 
// and the expanded image id will be screen142 for the value 142 in 
//expandimage 
//500 and 449 are the enlarges size of the image

exid = 0;
exstep = 0;
exwdth = 0;
exht = 0;
extp = 0;
exlft = 0;
extot = 0;
extotst = 5;

function expandthumb(thumbid, fullwidth, fullheight) {
  if (extot != 0) {
    clearTimeout(extot);
  }
  if (exid > 0 && exid != thumbid) {
    restorethumb();
  }
  if (exid != thumbid) {
    img = document.getElementById("screen" + thumbid);
    img.style.display = 'block';
    exid = thumbid;
    exstep = 1;
    exwdth = fullwidth;
    exht = fullheight;
    extp = img.offsetTop;
	
	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		exlft = img.offsetLeft;
	} 
	else { 
		exlft = img.offsetLeft;	
	} 
	
  
	
  } else if (exstep < 1) {
    exstep = 1;
  }
  expandstep();
}

function doexpand() {
  img = document.getElementById("screen" + exid);
  thumb = document.getElementById("thumb" + exid);
  myscroll = getScroll();
  if (extp + thumb.height > myscroll.top + myscroll.height) {
    finaltop = myscroll.top + myscroll.height - exht;
  } else {
    finaltop = extp + thumb.height - exht;
  }
  if (finaltop < myscroll.top) { finaltop = myscroll.top; }
  img.style.top = finaltop + ((extp - finaltop) * (extotst - exstep) / extotst) + 'px';

  if (exlft + thumb.width > myscroll.left + myscroll.width) {
    finalleft = myscroll.left + myscroll.width - exwdth;
  } else {
    finalleft = exlft + thumb.width - exwdth;
  }
  if (finalleft < myscroll.left) { finalleft = myscroll.left; }
  img.style.left = finalleft + ((exlft - finalleft) * (extotst - exstep) / extotst) + 'px';

  img.width = thumb.width + ((exwdth - thumb.width) * exstep / extotst);
  img.height = thumb.height + ((exht - thumb.height) * exstep / extotst);
}

function restorethumb() {
  img = document.getElementById("screen" + exid);
  img.style.top = '';
  img.style.left = '';
  img.style.display = 'none';
  exid = 0;
}

function expandstep() {
extot = 0;
doexpand();
if (exstep < extotst) {
exstep+=.1;// Increment of Step value
extot = setTimeout("expandstep()", 5);//Timeout value to call expandstep() again.
}
}

function reducestep() {
extot = 0;
doexpand();
if (exstep > 0) {
exstep-=.1; // Decrement of Step value
extot = setTimeout("reducestep()", 5); //Timeout value to call reducestep() again.
} else {
restorethumb();
}
}

function reducethumb(thumbid) {
  if (extot != 0) {
    clearTimeout(extot);
  }
  if (exstep > 0) {
    reducestep();
  }
}

// returns the scroll position and size of the browser
function getScroll() {
  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
    };
  }
}
