// JavaScript Document
function MovementHandler(ID)
{
	this.TIME_INTERVAL = 20;
	this.UP_SPEED = 5;
	this.DOWN_SPEED = 3;
	this.ID = ID;
	this.lock = false;
	
	this.CurrentVerticalPosition = CurrentVerticalPosition;
	this.VerticalMove = VerticalMove;
	this.VerticalMoveTo = VerticalMoveTo;
	this.Lock = Lock;
	this.Unlock = Unlock;
	this.ToggleLock = ToggleLock;
	
	if(arguments.length == 2)
	{
		this.UP_SPEED = this.DOWN_SPEED = arguments[1];
	}
	if(arguments.length == 3)
	{
		this.UP_SPEED = arguments[1];
		this.DOWN_SPEED = arguments[2];
	}
}

function CurrentVerticalPosition()
{
	this.div = document.getElementById(this.ID);
	return parseInt(this.div.style.top.substring(0, this.div.style.top.indexOf("px")));
}

function VerticalMove()
{
	var position = this.CurrentVerticalPosition();
	var direction = position - this.destination;
	
	if(direction == 0)
		return;
	else if(direction > 0)
	{
		this.speed = this.UP_SPEED;
		if(position - this.speed <= this.destination)
		{
			this.div.style.top = this.destination;
		}
		else
		{
			this.div.style.top = position - this.speed;
			window.setTimeout("document." + this.ID + ".VerticalMove();", this.TIME_INTERVAL);
		}
	}
	else
	{
		this.speed = this.DOWN_SPEED;
		if(position + this.speed >= this.destination)
		{
			this.div.style.top = this.destination;
		}
		else
		{
			this.div.style.top = position + this.speed;
			window.setTimeout("document." + this.ID + ".VerticalMove();", this.TIME_INTERVAL);
		}
	}
}

function VerticalMoveTo(destination)
{
	if(this.lock == false)
	{
		this.div = document.getElementById(this.ID);
		this.destination = destination;
		this.VerticalMove();
	}
}

function Lock()
{
	this.lock = true;
}

function Unlock()
{
	this.lock = false;
}

function ToggleLock()
{
	this.lock = !this.lock;
}