Window = function( settings )
{	
	this.name = settings.name;	
	this.width = ( parseInt(settings.width) > 0 ? parseInt(settings.width)-2 : 238);	
	this.height = ( parseInt(settings.height) > 0 ? parseInt(settings.height)-2 : 318);	
	this.left = ( parseInt(settings.left) > 0 ? parseInt(settings.left) : 0);	
	this.top = ( parseInt(settings.top) > 0 ? parseInt(settings.top) : 0);	
	
	this.headerHeight = 21;		
	this.canvas = document.createElement('div');	
	this.canvas.style.position = 'absolute';
	this.canvas.style.width = this.width + 'px';	
	this.canvas.style.height = this.height + 'px';	
	this.canvas.style.left = this.left + 'px';	
	this.canvas.style.top = this.top + 'px';	
	this.canvas.style.zIndex = 2000;
	this.canvas.style.border = '1px solid #000000';
	this.canvas.style.backgroundColor = '#FFFFFF';
	this.canvas.style.display = 'none';
	this.canvas.style.overflow = 'hidden';
	this.header = document.createElement('div');
//	this.canvas.appendChild(this.header);
	this.header.style.backgroundColor = '#FFFFFF';
	this.header.style.color = '#b806a6';
//	this.header.style['font-size'] = '20px';
//	this.header.style['text-align'] = 'right';
//	this.header.style.height = this.headerHeight + 'px';
//	this.header.style.paddingLeft = '5px';
//	this.header.style.borderBottom = '1px solid #9999FF';
//	this.header.innerHTML = settings.header;
//	this.header.onmousedown = this.startMove(this);
	document.body.onmouseup = this.endMove();
	this.startCoords = [0, 0];
	this.body = document.createElement('div');
	this.canvas.appendChild(this.body);
	this.canvas.onmousedown = this.startMove(this);
	this.body.style.backgroundColor = '#EEEEEE';
	this.body.style.color = '#000000';	
	this.body.style.width = this.width + 'px';
	this.body.style.height = (this.height - this.headerHeight - 1) + 'px';
	this.body.overflow = 'auto';
	this.canvas.style.filter = 'alpha(opacity=90)';
	this.canvas.style['-moz-opacity'] = '.90';
	this.canvas.style['opacity'] = '.90';
};

Window.prototype.startMove = function( object ){
	return function (e)	{
		document.body.onmousemove = object.makeMove(object);
		if ( !e )		
		{
			e = event;		
		}		
		object.startCoords = [e.clientX, e.clientY];
	};
};

Window.prototype.endMove = function ()
{	
	return function()
	{
		document.body.onmousemove = null;
	};
};

Window.prototype.makeMove = function( object )
{
	return function (e)
	{
		if ( !e )
		{
			e = event;
		}
		object.move( e.clientX - object.startCoords[0], e.clientY - object.startCoords[1] ) ;
		object.startCoords = [e.clientX, e.clientY];
	};
};

Window.prototype.show = function( center )
{	
	if (center)	
	{
		this.moveToCenter();
	}
	this.canvas.style.display = 'block';
};

Window.prototype.hide = function()
{
	this.canvas.style.display = 'none';
};

Window.prototype.move = function(x, y)
{
	this.left += x;
	this.top += y;
	this.moveTo(this.left, this.top);
};

Window.prototype.moveTo = function(x, y)
{
	this.left = x;
	this.top = y;
	if ( (this.left + (this.width + 2)) > document.documentElement.clientWidth + document.documentElement.scrollLeft)
	{
		this.left = document.documentElement.clientWidth + document.documentElement.scrollLeft - (this.width + 2);
	} else if ( this.left < document.documentElement.scrollLeft )
	{
		this.left = document.documentElement.scrollLeft;
	}
	if ( (this.top + (this.height + 2)) > document.documentElement.clientHeight + document.documentElement.scrollTop)
	{
		this.top = document.documentElement.clientHeight + document.documentElement.scrollTop - (this.height + 2);
	} else if ( this.top < document.documentElement.scrollTop )
	{
		this.top = document.documentElement.scrollTop;
	}

	this.canvas.style.left = this.left + 'px';
	this.canvas.style.top = this.top + 'px';
};


Window.prototype.draw = function()
{
	document.body.appendChild(this.canvas);
};

Window.prototype.setBody = function( innerHTML )
{
	this.body.innerHTML = innerHTML;
};

Window.prototype.moveToCenter = function()
{
	var howHigh = screen.availHeight;
	this.left = Math.ceil((document.documentElement.clientWidth - (this.width + 2)) / 2) + document.documentElement.scrollLeft;
	this.top = Math.ceil((document.documentElement.clientHeight - (this.height + 2)) / 2) + document.documentElement.scrollTop;
	this.moveTo(this.left, this.top);
};


