function Limit(from, to){
	this.from = from;
	this.to = to;
	this.value = this.from;
	this.onmore = new DOMEvent(this);
	this.onless = new DOMEvent(this);
	this.onmoreout = new DOMEvent(this);
	this.onlessout = new DOMEvent(this);
	this.onchange = new DOMEvent(this);
	this.TO_REACHED = false;
	this.FROM_REACHED = true;
	this.REACHED = true;
	this.SECOND_REACH = false;
	this.PREVENT_SECOND_FIRE = true;
	this.TO_OUT = false;
	this.FROM_OUT = false;
	this.MORE_VALUE = 0;
	this.LESS_VALUE = 0;
	this.exceeded = 0;
	this.preceeded = 0;
	this._attemped_value;
	if(this.constructor._TO_INSTANCES){
		this.constructor._instances.push(this);
	}
}
Limit.prototype.change = function(val){
	this._attempted_value = val;
	var value = val;
	value = this.checkFrom(value);
	value = this.checkTo(value);
	this.value += value;
	this.onchange.fire();
	if(this.TO_REACHED){
		this.onmore.fire(this);
	}
	if(this.FROM_REACHED){
		this.onless.fire(this);
	}
	if(this.TO_OUT){
		this.onmoreout.fire(this);
	}
	if(this.FROM_OUT){
		this.onlessout.fire(this);
	}
}
Limit.prototype.setValue = function(val){
	var value = val - this.from;
	this.change(value);
}
Limit.prototype.checkTo = function(val){
	var value = val;
	this.TO_OUT = false;
	if(this.TO_REACHED){
		if(this.value + value < this.to){
			this.TO_REACHED = false;
			this.TO_OUT = true;
			this.TO_OUT_VALUE = value;
			this.REACHED = false;
			this.SECOND_REACH = false;
		}else{
			this.exceeded = value;
			value = 0;
			this.MORE_VALUE = value;
			this.SECOND_REACH = true;
		}
	}else{
		if(this.value + value >= this.to){
			var v = this.to - this.value;
			this.exceeded = value - v;
			value = v;
			this.MORE_VALUE = value;
			this.TO_REACHED = true;
			this.REACHED = true;
		}
	}
	return value;
}
Limit.prototype.checkFrom = function(val){
	var value = val;
	this.FROM_OUT = false;
	if(this.FROM_REACHED){
		if(this.value + value > this.from){
			this.FROM_REACHED = false;
			this.FROM_OUT = true;
			this.FROM_OUT_VALUE = value;
			this.REACHED = false;
			this.SECOND_REACH = false;
		}else{
			this.preceeded = value;
			value = 0;
			this.LESS_VALUE = value;
			this.SECOND_REACH = true;
		}
	}else{
		if(this.value + value <= this.from){
			var v = this.value + value;
			value = -this.value + this.from;
			this.LESS_VALUE = value;
			this.preceeded = v;
			this.FROM_REACHED = true;
			this.REACHED = true;
		}
	}
	return value;
}
Limit.prototype.__name = "Limit";
Limit.prototype.toString = __toString;
Limit._TO_INSTANCES = true;
Limit._instances = [];
Limit.__loaded = true;