//This code was created by the fine folks at Switch On The Code - http://blog.paranoidferret.com
//This code can be used for any purpose
var i = 1;
var submenuids = 0;
function animate(elementID, newLeft, newTop, newWidth,
      newHeight, time, callback, submenuid)
{
		var el = document.getElementById(elementID);
		//var submenuids = submenuid;
/*	if(i == 4)
	{
		elementID = 'contentdiv';
		var el = document.getElementById(elementID);		
		newLeft = 0;
		newTop = 0;
		newWidth = 535;
		newHeight = 340;
	}
*/
		//alert(i + " --- " + elementID + " -- " + newWidth + " -- " + newHeight);
		 if(el == null)
			return;
		 
		  var cLeft = parseInt(el.style.left);
		  var cTop = parseInt(el.style.top);
		  var cWidth = parseInt(el.style.width);
		  var cHeight = parseInt(el.style.height);
		 
		  var totalFrames = 1;
		  if(time> 0)
			totalFrames = time/8;
		
		  var fLeft = newLeft - cLeft;
		
		if(fLeft != 0)
			fLeft /= totalFrames;
		 
		  var fTop = newTop - cTop;
		  if(fTop != 0)
			fTop /= totalFrames;
		 
		  var fWidth = newWidth - cWidth;
		  if(fWidth != 0)
			fWidth /= totalFrames;
		 
		  var fHeight = newHeight - cHeight;
		  if(fHeight != 0)
			fHeight /= totalFrames;
		   
		   
		  doFrame(elementID, cLeft, newLeft, fLeft,
			  cTop, newTop, fTop, cWidth, newWidth, fWidth,
			  cHeight, newHeight, fHeight, callback, submenuid);
		  //alert(submenuids);
		  i++;


}

function doFrame(eID, cLeft, nLeft, fLeft,
      cTop, nTop, fTop, cWidth, nWidth, fWidth,
      cHeight, nHeight, fHeight, callback, submenuid)
{
	//alert("frame ::     " + submenuids);
   var el = document.getElementById(eID);
  var element_menu2_title = document.getElementById('menudiv2_title');
   var element_tableid = document.getElementById('tableid');

   var element_submenu2 = document.getElementById('menu2_submenu');

if(el == null)
     return;

  cLeft = moveSingleVal(cLeft, nLeft, fLeft);
  cTop = moveSingleVal(cTop, nTop, fTop);
  cWidth = moveSingleVal(cWidth, nWidth, fWidth);
  cHeight = moveSingleVal(cHeight, nHeight, fHeight);
//alert(Math.round(cWidth));

if(Math.round(cWidth) >= 30)
{
  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);
*/

setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','
    +cTop+','+nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','
    +cHeight+','+nHeight+','+fHeight+','+callback+','+submenuid+')', 40);
  
//alert(nWidth + " -- " + el.style.left + " -- " + el.style.width);

	if(nWidth == "232" && el.style.width == "182px")
	{
//alert("inside :" + eID + " -- " + el.style.left + " -- " + el.style.width);
		//alert(eID + " -- " + nTop + " -- " + el.style.width);	
		element_submenu2.style.visibility = "visible";		  
		element_tableid.style.visibility = "visible";
	}

	if(nWidth == "25" && el.style.width == "174px")
	{
//alert("inside :" + eID + " -- " + el.style.left + " -- " + el.style.width);
		//alert(eID + " -- " + nTop + " -- " + el.style.width);	
		element_submenu2.style.visibility = "hidden";		  
		element_tableid.style.visibility = "hidden";
	}

}

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;
}


