//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
// position class

function class_position (x, y) {

	this.X = x;
	this.Y = y;

	this.Add = function (val) {
		var newPos = new class_position (this.X, this.Y);
		if (val != null) {
			if (!isNaN (val.X))  newPos.X += val.X;
			if (!isNaN (val.Y))  newPos.Y += val.Y
		} //if
		return newPos;
	} //function - method

	this.Subtract = function (val) {
		var newPos = new class_position (this.X, this.Y);
		if (val != null) {
			if (!isNaN (val.X))  newPos.X -= val.X;
			if (!isNaN (val.Y))  newPos.Y -= val.Y
		} //if
		return newPos;
	} //function - method

	this.Min = function (val) {
		var newPos = new class_position (this.X, this.Y)
		if (val == null)  return newPos;
		if (!isNaN (val.X) && this.X > val.X)  newPos.X = val.X;
		if (!isNaN (val.Y) && this.Y > val.Y)  newPos.Y = val.Y;
		return newPos;
	} //function - method

	this.Max = function (val) {
		var newPos = new class_position (this.X, this.Y)
		if (val == null)  return newPos;
		if (!isNaN (val.X) && this.X < val.X)  newPos.X = val.X;
		if (!isNaN (val.Y) && this.Y < val.Y)  newPos.Y = val.Y;
		return newPos;
	} //function - method

	this.Bound = function (lower, upper) {
		var newPos = this.Max (lower);
		return newPos.Min (upper);
	} //function - method

	this.Check = function() {
		var newPos = new class_position (this.X, this.Y);
		if (isNaN (newPos.X))  newPos.X = 0;
		if (isNaN (newPos.Y))  newPos.Y = 0;
		return newPos;
	} //function - method

	this.Apply = function (element) {
		if (typeof (element) == "string")
			element = document.getElementById (element);
		if (element == null)  return;
		if (!isNaN (this.X))  element.style.left = this.X + 'px';
		if (!isNaN (this.Y))  element.style.top = this.Y + 'px';
	} //function - method

} //function - class

