function _window(w, h, _title, _content, _parent)
{
	this.title = _title;
	this.content = _content;
	this.parent = _parent;
	
	this.width = w;
	this.height = h;
	this.parent = _parent;
	this.asd = "asd";
	
	this.obj = $('<div class="window_"></div>').css("width", w+"px").css("height", h+"px").
	css("position", "absolute").css("left", "300px").css("top", "300px");
	
	this.titleObj = $('<div><div class="titleText_">'+this.title+'</div></div>').attr("class","windowTitle_");
	this.contentObj = $('<div class="windowContent_">'+this.content+'</div>');
	this.obj.append(this.titleObj).append(this.contentObj);
	this.obj[0].win = this;
	this.parent.append(this.obj);
	
	this.dropped = 0;
	this.oldX = 0;
	this.oldY = 0;
	
	this.titleObj.bind("mousedown", null, this.onmousedown);
	this.titleObj.parent().bind("mouseup", null, this.onmouseup);
	this.titleObj.bind("mousemove", null, this.onmousemove);
	this.titleObj.parent().bind("mousemove", null, this.onwinmousemove);
	this.titleObj.parent().bind("mouseout", null, this.onmouseout);
	
	//this.watch("title", function(id, oldVal, newVal){this.titleObj.text(newVal);});
	this.setContent =  function(val){this.contentObj.html(val);};
	
}

_window.prototype.show = function()
{
		this.obj.hide().animate({"opacity":"show"}, 300);
		//alert(this.obj.css("opacity"));
}

_window.prototype.onmousedown = function(e)
{
	this.dropped = 1;
	this.parentNode.dropped = 1;
	
	if (IE4) e=event;
	
	for (var key in e)
	{
		//alert(key+" => "+e[key]);
	}
	
	if (IE4)
	{
		this.oldX = e.offsetX;
		this.oldY = e.offsetY;
	} else
	{
		this.oldY = e.pageY - getTop(this);
		this.oldX = e.pageX - getLeft(this);
	}
	//$(".windowContent_", $(this.parentNode)).html(this.oldX+"px");/**/
}

_window.prototype.onmouseup = function(e)
{
	this.dropped = 0;
	this.parentNode.dropped = 0;
	
}

_window.prototype.onmousemove = function(e)
{
	if (IE4) e=event;
	
	//alert(e.target);
	if (this.dropped)
	{
		if (IE4)
		{
			newX = e.offsetX;
			newY = e.offsetY;
		} else
		{
			newY = e.pageY - getTop(this);
			newX = e.pageX - getLeft(this);
		}
		var dx = newX - this.oldX;
		var dy = newY - this.oldY;
		var win = (this.parentNode);
		//$(win).css("left", win.offsetLeft+dx+"px");
		//$(win).css("top", win.offsetTop+dy+"px");
		//this.oldX = newX;
		//this.oldY = newY;
		//trace(this.oldX);
		
	}
}

_window.prototype.onwinmousemove = function(e)
{

	if (IE4) e=event;
	
	//alert(e.target);
	if (this.dropped)
	{
		if (IE4)
		{
			newX = e.offsetX;
			newY = e.offsetY;
		} else
		{
			newY = e.pageY - getTop(this);
			newX = e.pageX - getLeft(this);
			
		}
		var dx = newX - $(".windowTitle_",$(this))[0].oldX;
		var dy = newY - $(".windowTitle_",$(this))[0].oldY;
		
		var win = (this);
		$(win).css("left", win.offsetLeft+dx+"px");
		$(win).css("top", win.offsetTop+dy+"px");/**/
		document.selection.clear();
	}
}

_window.prototype.onmouseout = function(e)
{
	if (IE4) e=event;
	
	//alert(e.target);
	if (this.dropped)
	{
		if (IE4)
		{
			newX = e.offsetX;
			newY = e.offsetY;
		} else
		{
			newY = e.pageY - getTop(this);
			newX = e.pageX - getLeft(this);
			
		}
		var dx = newX - $(".windowTitle_",$(this))[0].oldX;
		var dy = newY - $(".windowTitle_",$(this))[0].oldY;
		
		var win = (this);
		$(win).css("left", win.offsetLeft+dx+"px");
		$(win).css("top", win.offsetTop+dy+"px");/**/
		
	}
	
}


_window.prototype.setContent = function(cont)
{
	this.contentObj.html(cont);
}/**/
