/* ***********************************************************
moveIt.js
script to manage news flash bulletin
based on Chapter 15 in 'DHTML and CSS for the WWW" Jason Teague
L. Ebert
October 16, 2008
************************************************************ */

//following code moves news flash box from outside of
//browser window down vertically into window
//based on Chapter 15 in 'DHTML and CSS for the WWW by Jason Teague

// global variables
var animateSpeed = 5;   //delay in recursive running of function
var object = null;      // object's address
var fX = null;			//final left position of object
var fY = null;			//final top position of object
var cX = null;			//current left
var cY = null;			//current top
var dX = null;			//keeps track of the amount object moved during animation
var dY = null;
var stepX = 0;		//records how far object should move horizontally for each step in animation
var stepY = null;		//records how far object should move vertically for each step in animation
var slope = null;		//ratio of x to y

function initAnimate(objectID, x, y)
{
	object = document.getElementById(objectID);
	fX = x;
	fY = y;

	cX = object.offsetLeft;
	cY = object.offsetTop;
	dX = Math.abs(fX-cX);
	dY = Math.abs(fY-cY);
	stepY = animateSpeed;  //this can be much more complex if moved at angle

	animateObject();
}

function animateObject() 
{
	if ((dX > 0) || (dY > 0))
	{
		object.style.left = Math.round(cX) + 'px';
		object.style.top = Math.round(cY) + 'px';
		cX = cX + stepX;
		cY = cY + stepY;
		dX = dX - Math.abs(stepX);
		dY = dY - Math.abs(stepY);
		setTimeout ('animateObject()',0);
	}
	else
	{
		object.style.left = fX + 'px';
		object.style.top = fY + 'px';
	}
	return;
}

function closeNews()
{
	var object=document.getElementById('news_window');
	object.style.visibility = 'hidden';
}