/* 					Animation.js by Learningpoint.ca

	Copywrite 2004 by Damion Dooley

	This is a toolkit of javascript animation functions that apply to Div tags.

	animInit(aDiv)
	animDifMove(t1,t2,item,offsetX,offsetY)
	animMove(t1,t2,item,x,y)
	animDifScroll(t1,t2,item,offsetX,offsetY)
	animLoopScroll(t1,t2,item,offsetX,offsetY)
	
Extra parameters are added onto Div data in order to record knowledge of a Div's fractional positioning.  (animStartX,animStartY) are recorded to indicate a Div's original position before we move it around.
*/
function animInit(aDiv) {
	aDiv = window.document.getElementById(aDiv);
	if (aDiv.style.left && !aDiv.animLeft) {
		aDiv.animLeft = parseInt(aDiv.style.left);//.offsetLeft
		aDiv.animStartX = aDiv.animLeft;}
	if (aDiv.style.top && !aDiv.animTop) {
		aDiv.animTop = parseInt(aDiv.style.top); //.offsetTop
		aDiv.animStartY = aDiv.animTop;}	
	if (aDiv.style.bottom && !aDiv.animBottom) {
		aDiv.animBottom = parseInt(aDiv.style.bottom); 
		aDiv.animStartY = aDiv.animBottom;}
	if (aDiv.style.right && !aDiv.animRight) {
		aDiv.animRight = parseInt(aDiv.style.right); 
		aDiv.animStartX = aDiv.animRight;}	
	aDiv.animHeight = parseInt(aDiv.style.height);
	aDiv.animWidth = parseInt(aDiv.style.width);
	aDiv.animStartScrollLeft=0;
	aDiv.animStartScrollTop=0;
	return aDiv;
}

/*Differential move of a div. 
	animDifMove(t1, t2,adivid,x,y).
	t1=time to start move; can be null and therefore ignored.
	t2=time to end move; as above.
	adivid:div tag id (string).
	offsetX,offsetY: x & y offset to add to div's current position.  Divs are positioned via left,right,top,bottom parameters, and offsets are added appropriately.
*/
function animDifMove(t1,t2,item,offsetX,offsetY) {
	if (t1 && (t1 > t) || t2 && (t > t2)) return true;
	aDiv = window.document.getElementById(item);
	//Future: ensure item is visible if it isn't already.
	if (aDiv.style.left) {
		aDiv.animLeft += offsetX;
		aDiv.style.left = aDiv.animLeft + "px";
	}	
	if (aDiv.style.top) {
		aDiv.animTop += offsetY;
		aDiv.style.top = aDiv.animTop + "px";	
	}
	if (aDiv.style.bottom) {
		aDiv.animBottom += offsetY;
		aDiv.style.bottom = aDiv.animBottom + "px";	
	}
	if (aDiv.style.right) {
		aDiv.animRight += offsetX;
		aDiv.style.right = aDiv.animRight + "px";	
	}	
	//aDiv.style.visibility="visible";
	return aDiv;
}

//As above, but setting position, rather than moving it differentially.
function animMove(t1,t2,item,x,y) {
	if (t1 && (t1 > t) || t2 && (t > t2)) return true;
	aDiv = window.document.getElementById(item);
	if (aDiv.style.left) {
		aDiv.animLeft = x;
		//newPos = parseInt(aDiv.animLeft + x);
		aDiv.style.left = aDiv.animLeft + "px";
	}	
	if (aDiv.style.top) {
		aDiv.animTop = y;
		aDiv.style.top = aDiv.animTop + "px";	
	}
	if (aDiv.style.bottom) {
		aDiv.animBottom = y;
		aDiv.style.bottom = aDiv.animBottom + "px";	
	}
	if (aDiv.style.right) {
		aDiv.animRight = x;
		aDiv.style.right = aDiv.animRight + "px";	
	}	
}

// For divs with scrollbar controls:
function animDifScroll(t1,t2,item,offsetX,offsetY) {
	if (t1 && (t1 > t) || t2 && (t > t2)) return true;
	aDiv = window.document.getElementById(item);
	aDiv.animStartScrollLeft += offsetX;
	aDiv.scrollLeft = aDiv.animStartScrollLeft;
	aDiv.animStartScrollTop += offsetY;
	aDiv.scrollTop = aDiv.animStartScrollTop;	
	return aDiv;
}

// For divs with scrollbar controls; e.g animLoopScroll(0,null,"news",0,aInc * 50 * scrollFlag);
function animLoopScroll(t1,t2,item,offsetX,offsetY) {
	aDiv = window.document.getElementById("news");

	if (aDiv.scrollTop == aDiv.scrollHeight /2)	{
		
		//8px seems to do the trick for smooth scrolling.
		aDiv.animStartScrollTop=8;
		aDiv.scrollTop=8;
	}
	return animDifScroll(t1,t2,item,offsetX,offsetY);
}