namespace("Rtx.Web");

Rtx.Web.Control = Class.create();
// Static members
Object.extend(Rtx.Web.Control, {

	autoPositioning:	function (div, clientX, clientY) {
		var x = clientX + document.body.scrollLeft + 1;
		var y = clientY + document.body.scrollTop + 1;
		if ((document.body.scrollLeft + document.body.clientWidth - x) < div.clientWidth) x -= div.clientWidth;
		if ((document.body.scrollTop + document.body.clientHeight - y) < div.clientHeight) y -= div.clientHeight;
		div.style.left = x + "px";
		div.style.top = y + "px";
	}

});
// Dynamic members
Class.inherit(Rtx.Web.Control, BaseObject, {

	///////////////////////////////////////////////////////////////////////////
	// Fields

	element:	null,
	controls:	null,

	///////////////////////////////////////////////////////////////////////////
	// Events

	onShowing:		null,
	onHiding:		null,
	onShowed:		null,
	onHided:		null,

	///////////////////////////////////////////////////////////////////////////
	// Initializers

	initialize:	function () {
		this.base();
		switch (arguments.length) {
			case 1:
				this._defaultElement = null;
				this.attach(arguments[0]);
				break;
			case 2:
				this._defaultElement = arguments[0];
				this.attach(arguments[1]);
				break;
			default:
				throw "The method WebControl.prototype.initialize needs one or two parameter(s) specified.";
		}
	},

	attach:	function (ctrlInfo) {
		Object.extend(this, ctrlInfo);
		this.element = this.setupMainElement(this._defaultElement);
	},

	detach:	function() {
		for (key in this.controls) {
			this.controls[key] = null;
		}
	},

	setupMainElement:	function (element) {
		return element;
	},

	///////////////////////////////////////////////////////////////////////////
	// Methods

	show:	function (visible, event) {
		if (visible) {
			this.doShowing(event);
			if (this.element.style.position == 'absolute')
				this.element.style.visibility = 'visible';
			else
				Element.show(this.element);
			this.doShowed(event);
		} else {
			this.doHiding(event);
			if (this.element.style.position == 'absolute')
				this.element.style.visibility = 'hidden';
			else
				Element.hide(this.element);
			this.doHided(event);
		}
	},
	
	visible:	function () {
		if (this.element.style.position == 'absolute')
			return this.element.style.visibility != 'hidden';
		else
			return Element.visible(this.element);
	},
	
	toggle:	function (event) {
		if (this.visible())
			this.show(false, event);
		else
			this.show(true, event);
	},
	
	doShowing:	function (event) {
		if (typeof this.onShowing == 'function')
			this.onShowing(event);
	},
	
	doShowed:	function (event) {
		if (typeof this.onShowed == 'function')
			this.onShowed(event);
	},
	
	doHiding:	function (event) {
		if (typeof this.onHiding == 'function')
			this.onHiding(event);
	},
	
	doHided:	function (event) {
		if (typeof this.onHided == 'function')
			this.onHided(event);
	},

	///////////////////////////////////////////////////////////////////////////
	// Cookie Helpers

	getCookiePrefix:	function () {
		return "";
	},

	getPropertyFromCookie:	function (propName, time) {
		var cookie = this.getCookiePrefix();
		if (!cookie) return false;
		return CookieStateBag.get(cookie, propName, time ? time : BagExpirePolicy.Hour);
	},

	setPropertyToCookie:	function (propName, value, time) {
		if (!propName) return false;
		var cookie = this.getCookiePrefix();
		if (!cookie) return false;
		CookieStateBag.set(cookie, propName, value, time ? time : BagExpirePolicy.Hour);
		return true;
	}

	///////////////////////////////////////////////////////////////////////////
	// Event Handlers

});

var WebControl = Rtx.Web.Control;

// [AtlasScript]

if(typeof(Sys)!="undefined")
	Sys.Application.notifyScriptLoaded();

// [/AtlasScript]
