
function VideoResize() {
	this.isResizing = false;
	this.setMinWidth(200);
}

VideoResize.prototype.setElement = function (element) {
	this.element = $(element); 
	this.left = $(element).positionedOffset().left;
	this.top = $(element).positionedOffset().top;
	this.height = $(element).getDimensions().height;
	this.width = $(element).getDimensions().width;
	this.resize();
}

var widthPerHeight = 1.33;

VideoResize.prototype.setMinWidth = function (minWidth) {
	this.minWidth = minWidth;
	this.minHeight = minWidth / widthPerHeight;
}

VideoResize.prototype.setWidth = function (width) {
	if (width > this.minWidth) {
		this.width = width;
		this.height = width / widthPerHeight;
		this.resize();
	}
}

VideoResize.prototype.setHeight = function (height) {
	if (height > this.minHeight) {
		this.width = widthPerHeight * height;
		this.height = height;
		this.resize();
	}
}

VideoResize.prototype.makeFullScreen = function () {
	this.setBottom(document.viewport.getHeight());
	if (this.getRight() > document.viewport.getWidth()) {
		this.setRight(document.viewport.getWidth());
	}
}

VideoResize.prototype.resize = function () {
	$(this.element).setStyle({ width: this.width + 'px' });
	$(this.element).setStyle({ height: this.height + 'px' });
}

VideoResize.prototype.setRight = function (right) {
	if (right - this.left > this.minWidth) { 
		this.setWidth(right - this.left);
	}
}

VideoResize.prototype.setBottom = function (bottom) {
	if (bottom - this.top > this.minHeight) { 
		this.setHeight(bottom - this.top);
	}
}

VideoResize.prototype.getBottom = function () {
	return this.top + this.height;
}

VideoResize.prototype.getRight = function () {
	return this.left + this.width; 
}

VideoResize.prototype.overRightBorder = function (x, y) {
	return x >= this.getRight() - 10 &&
		x <= this.getRight() + 10 &&
		y > this.top - 10 && y < this.getBottom() + 10;
}

VideoResize.prototype.overBottomBorder = function (x, y) {
	return y >= this.getBottom() - 10 &&
		y <= this.getBottom() + 10 &&
		x > this.left - 10 && x < this.getRight() + 10;
}

