// -----------------------------------------------------------------------------
// All the source code contained in this file is owned by DuoKomp company and 
// you are not allowed to use, modify, distribute or make it subject to any 
// other action of yours unless you obtain an explicit DuoKomp's consent to do 
// so.
// -----------------------------------------------------------------------------
// If you need to contact us for any reason, visit www.duokomp.eu.
// -----------------------------------------------------------------------------
function Geom_Rectangle ()
{
	this.left = 0;
	this.top = 0;
	this.right = 0;
	this.bottom = 0;
	
	this.getWidth = function ()
	{
		return this.right - this.left;
	}
	
	this.getHeight = function ()
	{
		return this.bottom - this.top + 1;
	}
	
	this.getDiffWidth = function ()
	{
		return this.right - this.left + 1;
	}
	
	this.getDiffHeight = function ()
	{
		return this.bottom - this.top;
	}
	
	this.getBrowserInnerRect = function ()
	{
				this.left = 0;
				this.top = 0;
				if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
					this.right = window.innerWidth - 1;
					this.bottom = window.innerHeight - 1;
				} 
				else if( document.documentElement &&
				( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
				{
				//IE 6+
					this.right = document.documentElement.clientWidth - 1;
					this.bottom = document.documentElement.clientHeight - 1;
				} 
				else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
					this.right = document.body.clientWidth - 1;
					this.bottom = document.body.clientHeight - 1;
				};
	}
	
	this.getBodyInnerRect = function ()
	{
		this.left = 0;
		this.top = 0;
		this.right = document.body.clientWidth - 1;
		this.bottom = document.body.clientHeight - 1;
	}
	
	this.normalize = function ()
	{
		if (this.right < this.left) {
			var tmp = this.left;
			this.left = this.right;
			this.right = tmp;
		};
		if (this.bottom < this.top) {
			var tmp = this.top;
			this.top = this.bottom;
			this.bottom = this.top;
		};
	}
	
	this.moveBy = function (cx, cy) 
	{
		this.left += cx;
		this.right += cx;
		this.top += cy;
		this.bottom += cy;
	}
	
	this.moveTo = function (x, y)
	{
		var wdt = getDiffWidth();
		var hgt = getDiffHeight();
		this.left = x;
		this.right = x + wdt;
		this.top = y;
		this.bottom = y + hgt;
	}
	
	this.getMidPoint = function (point)
	{
		var wdt = this.getWidth();
		var hgt = this.getHeight();
		point.x = this.left + wdt / 2;
		point.y = this.top + hgt / 2;
	}
	
	this.centerIntoRectangle = function (parentRect)
	{
		var myMid = new Geom_Point();
		this.getMidPoint(myMid);
		var parentMid = new Geom_Point();
		parentRect.getMidPoint(parentMid);
		var diffx = parentMid.x - myMid.x;
		var diffy = parentMid.y - myMid.y;
		this.moveBy(diffx, diffy);
	}
}

Geom_Point = function ()
{
	this.x = 0;
	this.y = 0;
}
