//Animation
//Anthony Bellingan 2/2/2006

/***************************************************************/
function delayResizeToTargetPosn(id,endL,endT,endW,endH,moveTime,delay)
{
	timerId = setTimeout("resizeToTargetPosn('"+id+"','"+endL+"','"+endT+"','"+endW+"','"+endH+"','"+moveTime+"')",delay);
}
//****************************************
function resizeToTargetPosn(id,endL,endT,endW,endH,moveTime)//moveTime always multiple of 10
{
	clearTimeout(timerId);
	var period = 10; 	//Set the time period between changes - 100ms= jerky, 10ms = smooth!
	var cycles = Math.round(moveTime/period)
	var count = 0; 		//cycle number of altering the position/size
	var tempData = getLayerInf(id);		// returns array of lengths eg: 155px
	var beginL = parseInt(tempData[0]);	// alterTopLeft() and alterWideHi use integers only
	var beginT = parseInt(tempData[1]);
	var beginW = parseInt(tempData[2]);
	var beginH = parseInt(tempData[3]);
	var L1 = beginL;
	var T1 = beginT;
	var W1 = beginW;
	var H1 = beginH;
	var decrement=0.15;
	//decrement = 1/cycles;
	alterCoOrds(id,L1,T1,W1,H1,endL,endT,endW,endH,cycles,period,decrement,count);
}

function alterCoOrds(id,L1,T1,W1,H1,endL,endT,endW,endH,cycles,period,decrement,count)	//integers only!
{
	var L2 = Math.round(parseInt(L1) + (endL - L1)*decrement);
	var T2 = Math.round(parseInt(T1) + (endT - T1)*decrement);
	var W2 = Math.round(parseInt(W1) + (endW - W1)*decrement);
	var H2 = Math.round(parseInt(H1) + (endH - H1)*decrement);
	document.getElementById(id).style.left = L2 + 'px';
	document.getElementById(id).style.top = T2 + 'px';
	document.getElementById(id).style.width = W2 + "px";
	document.getElementById(id).style.height = H2 + "px";
	count++;
	//if(count>=.25*cycles) decrement =0.08;
	if(count>=.95*cycles) decrement =0.15;
	if(count<=cycles) 
	{
	timerId = setTimeout("alterCoOrds('"+id+"','"+L2+"','"+T2+"','"+W2+"','"+H2+"','"+endL+"','"+endT+"','"+endW+"','"+endH+"','"+cycles+"','"+period+"','"+decrement+"','"+count+"')",period);
	}
}
//****************************************
/*
function resizeToTargetPosn(id,endL,endT,endW,endH,moveTime)
{
	var timespan = moveTime;	//time over which layer moves to end position
	var period = 10; 	//time period between changes - 100ms= jerky, 10ms = smooth!
	var count = 0; 		//cycle number of altering the position/size
	var cycles = Math.round(timespan / period);
	var tempData = getLayerInf(id);		// returns array of lengths eg: 155px
	var beginL = parseInt(tempData[0]);	// alterTopLeft() and alterWideHi use integers only
	var beginT = parseInt(tempData[1]);
	var beginW = parseInt(tempData[2]);
	var beginH = parseInt(tempData[3]);
	var moveL = Math.floor((endL - beginL)/cycles);
	var moveT = Math.floor((endT - beginT)/cycles);
	var moveW = Math.floor((endW - beginW)/cycles);
	var moveH = Math.floor((endH - beginH)/cycles);
//	alert(id +': '+cycles +': ' + moveL +' - moveL :moveT: '+ moveT+'-------' + moveW +' - moveW :moveH: '+ moveH);
	var tempL = beginL;
	var tempT = beginT;
	var tempW = beginW;
	var tempH = beginH;
	if(beginL > endL)
		{
		while(tempL > endL)
			{
			tempL = tempL + moveL;
			tempT = tempT + moveT;
			tempW = tempW + moveW;
			tempH = tempH + moveH;
			//alert(count);
			setTimeout("alterTopLeft('"+id+"','"+tempL+"','"+tempT+"'); alterWideHi('"+id+"','"+tempW+"','"+tempH+"')",(period * count));
			count++;
			}
		}
		else
		{
		while(tempL < endL)
			{
			tempL = tempL + moveL;
			tempT = tempT + moveT;
			tempW = tempW + moveW;
			tempH = tempH + moveH;
			setTimeout("alterTopLeft('"+id+"','"+tempL+"','"+tempT+"'); alterWideHi('"+id+"','"+tempW+"','"+tempH+"')",(period * count));
			count++;
			}
		}
		setTimeout("alterTopLeft('"+id+"','"+endL+"','"+endT+"'); alterWideHi('"+id+"','"+endW+"','"+endH+"')",(period * count));
}
*/
//****************************************
function resizeToTarget(id,targetId,endW,endH,moveTime)
{
	var timespan = moveTime;	//time over which layer moves to end position
	var period = 10; 	//time period between changes - 100ms= jerky, 10ms = smooth!
	var count = 0; 		//cycle number of altering the position/size
	var cycles = Math.round(timespan / period);
	var tempData = getLayerInf(id);		// returns array of lengths eg: 155px
	var beginL = parseInt(tempData[0]);	// alterTopLeft() and alterWideHi use integers only
	var beginT = parseInt(tempData[1]);
	var beginW = parseInt(tempData[2]);
	var beginH = parseInt(tempData[3]);
	var tempData = getLayerInf(targetId);
	var endL = parseInt(tempData[0]);
	var endT = parseInt(tempData[1]);
	alert(beginL +' - beginL :endL - '+ endL);
	var moveL = (endL - beginL)/cycles;
	var moveT = (endT - beginT)/cycles;
	var moveW = (endW - beginW)/cycles;
	var moveH = (endH - beginH)/cycles;
	var tempL = beginL;
	var tempT = beginT;
	var tempW = beginW;
	var tempH = beginH;
	if(beginL > endL)
		{
		while(tempL > endL)
			{
			tempL = tempL + moveL;
			tempT = tempT + moveT;
			tempW = tempW + moveW;
			tempH = tempH + moveH;
			setTimeout("alterTopLeft('"+id+"','"+tempL+"','"+tempT+"'); alterWideHi('"+id+"','"+tempW+"','"+tempH+"')",(period * count));
			count++;
			}
		}
		else
		{
		while(tempL < endL)
			{
			tempL = tempL + moveL;
			tempT = tempT + moveT;
			tempW = tempW + moveW;
			tempH = tempH + moveH;
			setTimeout("alterTopLeft('"+id+"','"+tempL+"','"+tempT+"'); alterWideHi('"+id+"','"+tempW+"','"+tempH+"')",(period * count));
			count++;
			}
		}
		setTimeout("alterTopLeft('"+id+"','"+endL+"','"+endT+"'); alterWideHi('"+id+"','"+endW+"','"+endH+"')",(period * count));
}
//****************************************
function layerToTargetPosn(id,endL,endT,moveTime)
{
var timespan = moveTime;	//time over which layer moves to end position
var period = 10; 	//time period between changes - 100ms= jerky, 10ms = smooth!
var count = 0; 		//cycle number of altering the position/size
var cycles = Math.round(timespan / period);
var tempData = getLayerInf(id);			// returns array of lengths eg: 155px
var beginL = parseInt(tempData[0]);		//turn everything into integers as alterTopLeft() uses integers
var beginT = parseInt(tempData[1]);
var moveL = (endL - beginL)/cycles;
var moveT = (endT - beginT)/cycles;
var tempL = beginL;
var tempT = beginT;
while(tempL > endL)
		{
		tempL = tempL + moveL;
		tempT = tempT + moveT;
		setTimeout("alterTopLeft('"+id+"','"+tempL+"','"+tempT+"')",(period * count));
		count++;
		}
setTimeout("alterTopLeft('"+id+"','"+endL+"','"+endT+"')",(period * count));
}
//*************************************************************************
function layerToTarget(id,targetId,moveTime)
{
var timespan = moveTime;	//time over which layer moves to end position
var period = 10; 	//time period between changes - 100ms= jerky, 10ms = smooth!
var count = 0; 		//cycle number of altering the position/size
var cycles = Math.round(timespan / period);
var tempData = getLayerInf(id);			// returns array of lengths eg: 155px
var beginL = parseInt(tempData[0]);		//turn everything into integers as alterTopLeft() uses integers
var beginT = parseInt(tempData[1]);
var tempData = getLayerInf(targetId);
var endL = parseInt(tempData[0]);
var endT = parseInt(tempData[1]);
var moveL = (endL - beginL)/cycles;
var moveT = (endT - beginT)/cycles;
var tempL = beginL;
var tempT = beginT;
if(beginL > endL)
	{
	while(tempL > endL)
		{
		tempL = tempL + moveL;
		tempT = tempT + moveT;
		setTimeout("alterTopLeft('"+id+"','"+tempL+"','"+tempT+"')",(period * count));
		count++;
		}
	}
	else
	{
	while(tempL < endL)
		{
		tempL = tempL + moveL;
		tempT = tempT + moveT;
		setTimeout("alterTopLeft('"+id+"','"+tempL+"','"+tempT+"')",(period * count));
		count++;
		}
	}
	setTimeout("alterTopLeft('"+id+"','"+endL+"','"+endT+"')",(period * count));
}
//*************************************************************************

function alterTopLeft(id,newL,newT)	//where L and T are given as integers only!
{
	document.getElementById(id).style.left = newL + 'px';
	document.getElementById(id).style.top = newT + 'px';
}

function alterWideHi(id,endW,endH)	//where W and H are given as integers only!
{
	document.getElementById(id).style.width = endW + "px";
	document.getElementById(id).style.height = endH + "px";
}

function getLayerInf(id)
{
	var coOrds = new Array(4);
	coOrds[0] = document.getElementById(id).style.left;
	coOrds[1] = document.getElementById(id).style.top;
	coOrds[2] = document.getElementById(id).style.width;
	coOrds[3] = document.getElementById(id).style.height;
	return coOrds;
}

/*
function getLayerInf(id)
{
	var coOrds = new Array(4);
	coOrds[0] = document.getElementById(id).getAttribute("style").left;
	coOrds[1] = document.getElementById(id).getAttribute("style").top;
	coOrds[2] = document.getElementById(id).getAttribute("style").width;
	coOrds[3] = document.getElementById(id).getAttribute("style").height;
	return coOrds;
}
*/