Window = function (leftPos, topPos, elm)
{
	var self = this;
	this.elm = elm;

	elm.style.position = "absolute";
	elm.style.left = leftPos + "px";
	elm.style.top = topPos + "px";
	elm.style.cursor = "pointer";
	elm.onmousedown = function(e){return self.startMove.call(self, e )};

	this.mouseX=0;
	this.mouseY=0;

	this.startX=0;
	this.startY=0;

	this.startW=0;
	this.startH=0;

}

Window.prototype = {


	startMove : function(e){
		var self = this;

		e= e||window.event;

		this.mouseX = e.clientX;
		this.mouseY = e.clientY;

		this.elm.focus();

		var tmp = this.elm.getElementsByTagName("object")[0];
		if( tmp )
		{
						tmp.style.visibility = "hidden";
			tmp.oldW = tmp.style.width;
			tmp.oldH = tmp.style.height;
			tmp.style.width = "0px";
			tmp.style.height = "0px";
		}

		this.startX = parseInt(this.elm.style.left);
		this.startY = parseInt(this.elm.style.top);

		document.documentElement.onmousemove = function(e){self.moveWindow.call(self, e)};
		document.documentElement.onmouseup =  function(e){self.stopMove.call(self, e)};



		//stopPropagation(e);
		return false;
	},

	stopMove : function () {
		var tmp = this.elm.getElementsByTagName("object")[0];
		if( tmp )
		{
			tmp.style.visibility = "";
			tmp.style.width = tmp.oldW;
			tmp.style.height = tmp.oldH;
		}
		document.documentElement.onmousemove = "";
	},


	moveWindow : function (e) {

		e=(e||window.event);

		var left = this.startX + e.clientX - this.mouseX;
		var top = this.startY + e.clientY - this.mouseY;

		if(left<0)
			left=0;
		else if(left+this.elm.clientWidth > document.documentElement.clientWidth -20 )
			left=document.documentElement.clientWidth-this.elm.clientWidth-20;

		if(top<54)
			top=54;
		else if(top+this.elm.clientHeight > document.documentElement.clientHeight -54 )
			top=document.documentElement.clientHeight-this.elm.clientHeight-54;

		var lDiff = left - parseInt(this.elm.style.left);
		var tDiff = top - parseInt(this.elm.style.top);
		
		this.elm.style.left = left + "px";
		this.elm.style.top = top + "px";

	}

}



