
function DynDiv (layer, width, height, func) {
	this.layer = layer;
	document.documentElement.style.overflow = "hidden";
	this.WIDTH_MODIFICATOR  = width;
	this.HEIGHT_MODIFICATOR = height;
	this.condition_function = func;
	this.isOn = false;
	this.doLayout();
	this.originalWidth = 0;
	this.originalHeight = 0;
}

/*void*/ DynDiv.prototype.doLayout = function() {
	if (this.condition_function()) {
		if (!this.isOn)
			this.turnOn();
		this.setMaxAvailWidth();
		this.setMaxAvailHeight();
	} else
	{
		if (this.isOn)
			this.turnOff();
	}
}

/*void*/ DynDiv.prototype.turnOn = function() {
	this.isOn = true;
	this.originalWidth = this.layer.style.width;
	this.originalHeight = this.layer.style.height;
	this.layer.style.overflow = "auto";
}

/*void*/ DynDiv.prototype.turnOff = function() {
	this.isOn = false;
	this.layer.style.width = "";
	this.layer.style.height = "";
	this.layer.style.overflow = "visible";
}

/*number*/ DynDiv.prototype.getMaxAvailHeight = function() {
	if (window.innerHeight) {
		var height = window.innerHeight - this.HEIGHT_MODIFICATOR;
	} else {
		var height = document.documentElement.clientHeight - this.HEIGHT_MODIFICATOR;
	}
	return height;
}

/*number*/ DynDiv.prototype.getMaxAvailWidth = function () {
	if (window.innerWidth) {
		var width = window.innerWidth - this.WIDTH_MODIFICATOR;
	} else {
		var width = document.documentElement.clientWidth - this.WIDTH_MODIFICATOR;
	}
 	return width;
}

/*void*/ DynDiv.prototype.setMaxAvailWidth = function () {
	this.layer.style.width = this.getMaxAvailWidth() + "px";
}

/*void*/ DynDiv.prototype.setMaxAvailHeight = function () {
	this.layer.style.height = this.getMaxAvailHeight() + "px";
}

