
function animate(elementID, newLeft, newTop, newWidth,newHeight, time, callback)
{
  var el = document.getElementById(elementID);
  if(el == null)
    return;

//var cLeft = parseInt(el.currentStyle.left); if (isNaN(cLeft)) {cLeft = 0; }
//var cTop = parseInt(el.currentStyle.top); if (isNaN(cTop)) { cTop = 0; }
//var cWidth = parseInt(el.currentStyle.width); if (isNaN(cWidth)) { cWidth = 0; }
//var cHeight = parseInt(el.currentStyle.height); if (isNaN(cHeight)) { cHeight = 0; }
var cLeft = parseInt(el.scrollLeft); if (isNaN(cLeft)) { cLeft = 0; }
var cTop = parseInt(el.scrollTop); if (isNaN(cTop)) { cTop = 0; }
var cWidth = parseInt(el.scrollWidth); if (isNaN(cWidth)) { cWidth = 0; }
var cHeight = parseInt(el.scrollHeight); if (isNaN(cHeight)) { cHeight = 0; }
 
  var totalFrames = 1;
  if(time> 0)
    totalFrames = time/40;

if (newLeft == -1) { var fLeft = newLeft = cLeft; }
else {
    var fLeft = newLeft - cLeft;
    if (fLeft != 0) { fLeft /= totalFrames; } 
}



if (newTop == -1) { var fTop = newTop = cTop; }
else {
    var fTop = newTop - cTop;
    if (fTop != 0) { fTop /= totalFrames; } 
}



if (newWidth == -1) {var fWidth= newWidth = cWidth; }
else {
    var fWidth = newWidth - cWidth;
    if (fWidth != 0) { fWidth /= totalFrames; } 
}



if (newHeight == -1) {var fHeight= newHeight = cHeight; }
else {
    var fHeight = newHeight - cHeight;
    if (fHeight != 0) { fHeight /= totalFrames; } 
}
 
 
  doFrame(elementID, cLeft, newLeft, fLeft,
      cTop, newTop, fTop, cWidth, newWidth, fWidth,
      cHeight, newHeight, fHeight, callback);
}

function doFrame(eID, cLeft, nLeft, fLeft,
      cTop, nTop, fTop, cWidth, nWidth, fWidth,
      cHeight, nHeight, fHeight, callback)
{
   var el = document.getElementById(eID);
   if(el == null)
     return;

  cLeft = moveSingleVal(cLeft, nLeft, fLeft);
  cTop = moveSingleVal(cTop, nTop, fTop);
  cWidth = moveSingleVal(cWidth, nWidth, fWidth);
  cHeight = moveSingleVal(cHeight, nHeight, fHeight);

  el.style.left = Math.round(cLeft) + 'px';
  el.style.top = Math.round(cTop) + 'px';
  el.style.width = Math.round(cWidth) + 'px';
  el.style.height = Math.round(cHeight) + 'px';
 
  if(cLeft == nLeft && cTop == nTop && cHeight == nHeight
    && cWidth == nWidth)
  {
    if(callback != null)
      callback();
    return;
  }
   
  setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','
    +cTop+','+nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','
    +cHeight+','+nHeight+','+fHeight+','+callback+')', 40);
}

function moveSingleVal(currentVal, finalVal, frameAmt)
{
  if(frameAmt == 0 || currentVal == finalVal)
    return finalVal;
 
  currentVal += frameAmt;
  if((frameAmt> 0 && currentVal>= finalVal)
    || (frameAmt <0 && currentVal <= finalVal))
  {
    return finalVal;
  }
  return currentVal;
}

