// JavaScript Document
var thisObject = null;
var showState = null;
// Sets animation speed.
var animateSpeed = 20;

// Stores Object ID
var object = null;

// Final X and Y coordinates
var fX = null; 
var fY = null;

// Current X and Y coordinates
var cX = null;
var cY = null;

// Keep track of the amount the object has moved to the left and from the top while being animated
var dX = null;
var dY = null;

// Keep track of how far the object should move per each execution
var stepX = null;
var stepY = null;

// Records the ratio of X to Y for the slant of the objects path from start point to end point
var slope = null;

function initAnimate(objectID,x,y,originX,originY,hideThis) {
	showState = hideThis;
	object = document.getElementById(objectID);
	// Set initial position
	object.style.left = Math.round(originX) + 'px';
	object.style.top = Math.round(originY) + 'px';
	
	// final position
	fX = x;
	fY = y;
	// current position
	cX = object.offsetLeft;
	cY = object.offsetTop;
	
	dX = Math.abs(fX-cX);
	dY = Math.abs(fY-cY);
	
	if ((dX == 0) || (dY == 0)) {
		slope = 0;
	}else{
		slope = dY/dX;
	}
	// Determines how far the object has to move
		if (dX>=dY) {
			if (cX<fX) stepX = animateSpeed;
			else if (cX>fX) stepX = - animateSpeed;
			
			if (cY<fY) stepY = animateSpeed*slope;
			else if (cY>fY) stepY = - animateSpeed*slope;
		}else if (dX<dY) {
			if (cY<fY) stepY = animateSpeed;
			else if (cY>fY) stepY = - animateSpeed;
			
			if (cX<fX) stepX = animateSpeed/slope;
			else if (cX>fX) stepX = - animateSpeed/slope;
		}
	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';
		setVisibility();
	}
	return;
}

function setVisibility () {
	if (showState == null) {
		//do nothing	
	}else if (showState == 'false') {
		hideMe('interCut');
		showState = null;
	}
}
