function WindowsSystemInstance(windowWidth, windowHeight)
{
	this.createViewFromAjax = function(id, url, data, callback)
	{
		$.get(url, data, 
		function(data)
		{

			thisRef.createView(id);

			$("#" + id).html(data);

			callback();

		});
	}

	this.createViewsFromAjax = function(url, data, callback)
	{
		$.get(url, data,
		function(data)
		{

			$(data).appendTo(thisRef.window);

			$(thisRef.window).find(".view:not(:first-child)").hide();

			callback();

		});
	}

	this.createView = function(id)
	{
		var view = $('<div class="view">')
		.attr("id", id)
		.appendTo(this.window);

		return view;
	}

	this.switchView = function(id, callback)
	{
		$(this.window).find(".view:visible")
		.fadeOut(function() {$("#" + id).fadeIn(); if (callback) callback();});
	}

	this.switchViewFast = function(id)
	{
		$(this.window).find(".view:visible").hide();
		$("#" + id).show();
	}

	this.fadeIn = function(callback)
	{
		$("body").css("overflow", "hidden");
		$(this.instance).fadeIn("normal", callback);
	}

	this.fadeOut = function(callback)
	{
		$("body").css("overflow", "auto");
		$(this.instance).fadeOut("normal", callback);
	}

	this.onClose = function() { }

	this.close = function()
	{
		this.onClose();
		this.fadeOut(function() { $(this).remove(); });
	}

	this.update = function()
	{
		// centrowanie okienka
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();

		var pos =
		{
			"left": (windowWidth/2) - (this.width/2) + "px",
			"top": (windowHeight/2) - (this.height/2) + "px"
		};

		$(this.window).css(pos);
	}

	this.width = windowWidth;
	this.height = windowHeight;

	this.instance = $('<div class="windows-system-instance">')
	.appendTo("body")
	.hide();

	// transparent background
	$('<div class="bg">').appendTo(this.instance);

	// main window
	this.window = $('<div class="window-base">')
	.css({"width": windowWidth + "px", "height": windowHeight + "px"})
	.appendTo(this.instance);

	// wycentrowanie okna init.
	this.update();

	// --- events
	var thisRef = this;

	$(window).resize
	(
		function()
		{
			thisRef.update();
		}
	);

	$(thisRef.window).click
	(
		function(e)
		{
			e.stopPropagation();
		}
	);

	$(document).click
	(
		function()
		{
			thisRef.close();
		}
	);
}
