﻿/// <reference path="../src/jquery-1.4.1-vsdoc.js" />
/// <reference path="pc3_JavaScript.js" />


function Wall(id, padding, minW, minH, position)
{
	var context = JQ;
	var Id = id;
	var pads = padding;
	var MinW = minW;
	var MinH = minH;
	var Absolute = (position == "absolute");

	this.ID = id;
	this.getId = function () { return Id; };

	this.init = function ()
	{
		context = $("#" + Id);
		PC3.onAjaxUpdate.add(function () { Self.run(); });
		var Self = this;
		win.resize(function () { Self.run(); });
		this.run();
	};

	this.Resize = function ()
	{
		this.run();
	};

	this.run = function ()
	{
		if (!pads.top > 0) pads.top = 0;
		if (!pads.left > 0) pads.left = 0;
		if (!pads.right > 0) pads.right = 0;
		if (!pads.bottom > 0) pads.bottom = 0;

		if (Absolute)
		{
			//context.offset({ top: pads.top, left: pads.left });
			context.css("top", pads.top + "px");
			context.css("left", pads.left + "px");
			context.css("position", "absolute");
		}

		var h = win.height() - (context.position().top + pads.top + pads.bottom);
		var w = win.width() - (context.position().left + pads.left + pads.right);

		if (w < MinW)
		{
			w = MinW;
			bod.css("overflow", "scroll");
		}
		if (h < MinH)
		{
			h = MinH;
			bod.css("overflow", "scroll");
		}
		if (w > MinW && h > MinH)
		{
			bod.css("overflow", "hidden");
		}

		context.height(h);
		context.width(w);
		lastH = h;
		lastW = w;
		this.onResize.init();
		this.onPostResize.init();
	};

	this.onResize = new EventHandle();
	this.onPostResize = new EventHandle();

	var lastH = 0;
	var lastW = 0;
	this.getHeight = function () { return lastH; };
	this.getWidth = function () { return lastW; };
	this.getJQ = function () { return context; };
}
