function Tabs () {
	this.init = function (t, args) {
		this.success = args.success;
		this.loading = args.loading;
		this.error = args.error;
		this.elem = args.elem;
		this.timeout = undefined;
		this.content = args.content;
		this.value = args.value;
		this.bind (this);
	}
	this.callback = function (t, ev, callback) {
		clearTimeout (t.timeout);
		setTimeout (function () {
			t.timeout = undefined;
		}, 125);
		callback (ev);
	}
	this.click = function (t, ev) {
		if (!t.timeout) {
			var dfr = $.Deferred ();
			$ (t.elem).removeClass ("tabSelected");
			ev.addClass ("tabSelected");
			t.timeout = setTimeout (function () {
				t.callback (t, ev, t.loading);
			}, 1000);
			$.ajax ({
				async: true,
				type: "POST",
				url: ev.attr (t.value),
				complete: function (jqXHR, statusText) {
					if (statusText == "success") {
						$ (t.content).html (jqXHR.responseText);
						dfr.resolve ();
					} else {
						dfr.reject ();
					}
				}
			});
			$.when (dfr).always (function () {
				if (dfr.isResolved ()) {
					t.callback (t, ev, t.success);
				} else {
					t.callback (t, ev, t.error);
				}
			});
		}
	}
	this.unbind = function (t) {
		$ (t.elem).unbind ("click");
	}
	this.bind = function (t) {
		$ (t.elem).bind ("click", function () {
			t.click (t, $ (this));
			return false;
		});
	}
}

