// IMPORTANT NOTE: the horizontal animation code has undergone limited testing.
// The vertical animation code has undergone NO testing and it's not known if it works or not
// yet. THIS CODE IS NOT FINAL.

// Library to animate a layer moving horizontally or vertically
// by Tom Farrell
// Before calling this library from a page, first call Tom's layercontrol.js 
// library as its functions are required for proper functionality.

// This library uses global variables to store animation information to get around Microsoft and
// Netscape's mutually incompatible versions of the timing functions. Because of this, you can 
// only have one instance of animateHorizontal or animateVertical running at a time.
// The following are the global variables for horizontal animation. You don't need to set any
// of these: please ignore them. The values shown are just for initialization.
var ahLayer = null; // the layer
var ahIncrement = 1; // the increment amount.
var ahCurrentX = 0; // the distance the layer animates in each move.
var ahEndingX = 0; // the final X position of the layer.
var ahY = 0; //the Y coordinate.
var ahInterval = null; //the interval to be set for the animation.
var ahDelay = 1; //the delay period for the animation. (Used if it has to take a partial step.)
var ahDoNext = null; //what to do after completing the horizontal animation.
// The following are the global variables for vertical animation.
var avLayer = null; // the layer
var avIncrement = 1; // the increment amount.
var avCurrentY = 0; // the distance the layer animates in each move.
var avEndingY = 0; // the final X position of the layer.
var avX = 0; //the Y coordinate.
var avInterval = null; //the interval to be set for the animation.
var avDelay = 1; //the delay period for the animation. (Used if it has to take a partial step.)
var avDoNext = null; //what to do after completing the vertical animation.


//the following function animates the motion of a layer along a horizontal line.
function animateHorizontal(layerName,layerY,startingX,endingX,delay,factor) {
	ahLayer = makeAbstract(layerName);
	positionLayer(ahLayer,startingX,layerY);
	showLayer(ahLayer);
	ahIncrement = factor;
	ahCurrentX = startingX;
	ahEndingX = endingX;
	ahY = layerY;
	ahDelay = delay;
	if (endingX<startingX) {
		ahIncrement = 0-factor;
		} //end if
	ahInterval = setInterval("moveOneHorizontal()",ahDelay);
	} //end function
	
// The following function calls animateHorizontal and sets what is supposed to happen after
// the animation has completed.
function sequenceAnimateHorizontal(layerName,layerY,startingX,endingX,delay,factor,doNext) {
	ahDoNext = doNext;
	animateHorizontal(layerName,layerY,startingX,endingX,delay,factor);
	} //end function

//the following function animates the motion of a layer along a vertical line.
function animateVertical(layerName,layerX,startingY,endingY,delay,factor) {
	avLayer = makeAbstract(layerName);
	positionLayer(avLayer,layerX,startingY);
	showLayer(avLayer);
	avIncrement = factor;
	avCurrentY = startingY;
	avEndingY = endingY;
	avX = layerX;
	avDelay = delay;
	if (endingY<startingY) {
		avIncrement = 0-factor;
		} //end if
	avInterval = setInterval("moveOneVertical()",avDelay);
	} //end function

// The following function calls animateVertical and sets what is supposed to happen after
// the animation has completed.
function sequenceAnimateVertical(layerName,layerX,startingY,endingY,delay,factor,doNext) {
	avDoNext = doNext;
	animateVertical(layerName,layerX,startingY,endingY,delay,factor);
	} //end function

//the following function is not intended to be called directly from user code.
//use animateHorizontal() instead and let it worry about this for you.
function moveOneHorizontal() {
	ahCurrentX += ahIncrement;
	positionLayer(ahLayer,ahCurrentX,ahY);
	if ( tooFar(ahCurrentX,ahEndingX,ahIncrement) && (ahCurrentX!=ahEndingX) ) {
		clearInterval(ahInterval);
		ahInterval = null;
		positionLayer(ahLayer,ahEndingX,ahY);
		} //end else
	else if (ahCurrentX==ahEndingX) {
		clearInterval(ahInterval);
		ahInterval = null;
		} //end else if
	if ((ahInterval==null) && (ahDoNext!=null)) {
		setTimeout(ahDoNext,1);
		ahDoNext = null;
		} //end if
	} //end function

//the following function is not intended to be called directly from user code.
//use animateVertical() instead and let it worry about this for you.
function moveOneVertical() {
	avCurrentY += avIncrement;
	positionLayer(avLayer,avX,avCurrentY);
	if ( tooFar(avCurrentY,avEndingY,avIncrement) && (avCurrentY!=avEndingY) ) {
		clearInterval(avInterval);
		avInterval = null;
		positionLayer(avLayer,avX,avEndingY);
		} //end else
	else if (avCurrentY==avEndingY) {
		clearInterval(avInterval);
		avInterval = null;
		} //end else if
	if ((avInterval==null) && (avDoNext!=null)) {
		setTimeout(avDoNext,1);
		avDoNext = null;
		} //end if
	} //end function

// the following function determines if the target number surpasses 
// its goal in the desired direction.
function tooFar(target,end,increment) {
	if ((increment>0) && (target>end)) {
		return true;
		} //end if
	if ((increment<0) && (target<end)) {
		return true;
		} //end if
	return false;
	} //end function


