function containerFunctions(_varName, _window) {
	this.varName =_varName ? _varName : 'myContainerFunctions';
	this.window =_window ? _window : window;
	this.document = this.window.document;
	this.body = this.document.getElementsByTagName('body');
	this.body = this.body ? this.body[0] : false;
	this.containers = new Array();

	this.getPosXY = function(element) {
		var x = 0;
		var y = 0;
		while (element) {
			x += element.offsetLeft;
			y += element.offsetTop;
			element = element.offsetParent;
		}
		return new Array(x, y);
	}

	this.getElementById = function(_id) {
		return this.document.getElementById(_id);
	}

	this.getElementsByTagName = function(_tag) {
		return this.document.getElementsByTagName(_tag);
	}

	this.createElement = function(_tag) {
		return this.document.createElement(_tag);
	}

	this.insertElementAsFirst = function(_container, _element) {
		var first = _container.firstChild;
		if (first) {
			_container.insertBefore(_element, first);
		} else {
			_container.appendChild(_element);
		}
	}

	this.insertElementIntoBody = function(_element) {
		this.insertElementAsFirst(this.body, _element);
	}

	this.drawFullFrame = function(_className) {
		var fullFrame = this.getElementById('full-frame');
		if (!fullFrame) {
			fullFrame = this.createElement('div');
			fullFrame.id = 'full-frame';
			fullFrame.style.position = 'absolute';
			fullFrame.className = _className ? _className : 'full-frame';
			this.insertElementIntoBody(fullFrame);
			var f = this.varName + '.resizeFullFrame();';
			this.addOnresize(function() {eval(f)});
			this.resizeFullFrame();
		}
	}

	this.bodyWidth = function() {
		return this.body.clientWidth;
	}

	this.bodyHeight = function() {
		var h1 = this.body.clientHeight;
		var f = this.getElementById('footerstrip');
		var h2 = f ? f.offsetTop + f.clientHeight : 0;
		return h2 > h1 ? h2 : h1;
	}

	this.getRelativeX = function(_x, _width) {
		return this.bodyWidth() + (_x > 0 ? 0 : _x) - _width;
	}

	this.getRelativeY = function(_y, _height) {
		return this.bodyHeight() + (_y > 0 ? 0 : _y) - _height;
	}

	this.addOnresize = function(_f) {
		if (this.window.addEventListener) {
        	this.window.addEventListener('resize', _f, false);
        } else {
            this.window.attachEvent('onresize', _f);
        }
	}

	this.addOnclick = function(_element, _f) {
		if (_element.addEventListener) {
        	_element.addEventListener('click', _f, false);
        } else {
            _element.attachEvent('onclick', _f);
        }
	}

	this.resizeFullFrame = function() {
		var fullFrame = this.getElementById('full-frame');
		if (fullFrame) {
			var parent = this.removeChild(fullFrame);
			fullFrame.style.width = this.bodyWidth() + 'px';
			fullFrame.style.height = this.bodyHeight() + 'px';
			this.insertElementAsFirst(parent, fullFrame);
		}
	}

	this.removeChild = function(_element) {
		var parent = _element.parentNode;
		if (parent) {
			parent.removeChild(_element);
		}
		return parent;
	}

	this.removeFullFrame = function() {
		var fullFrame = this.getElementById('full-frame');
		if (fullFrame) {
			this.removeChild(fullFrame);
		}
		return fullFrame;
	}

	this.getContainer = function(_index) {
		return (_index >= 0) && (_index < this.containers.length) ? this.containers[_index] : false;
	}

	this.assignContainer = function(_elementOrId) {
		if (typeof(_elementOrId) == 'string') {
			_elementOrId = this.getElementById(_elementOrId);
		}
		return this.newContainer(_elementOrId);
	}

	this.createContainer = function(_id, _className) {
		return this.newContainer(_id, _className);
	}

	function parseValue(value) {
		value = parseInt(value);
		return isNaN(value) ? 0 : value;
	}

	this.newContainer = function(_elementOrId, _className) {
		var length = this.containers.length;
		var varName = this.varName + '.getContainer(' + length + ')';
		var c = new container(varName, _elementOrId, this, _className);
		this.containers[length] = c;
		return c;
	}

	function container(_varName, _elementOrId, _cf, _className) {
		this.varName = _varName;
		this.x = 0;
		this.y = 0;
		this.isRelativeX = false;
		this.isRelativeY = false;
		this.width = 0;
		this.height = 0;
		this.cf = _cf ? _cf : new containerFunctions();
		this.element = false;
		this.visible = false;
		if (typeof(_elementOrId) == 'string') {
			this.element = this.cf.createElement('div');
			this.element.id = _elementOrId;
			this.element.style.display = 'none';
			this.element.style.marginLeft = '0px';
			this.element.style.marginTop = '0px';
			this.element.style.width = '0px';
			this.element.style.height = '0px';
			this.cf.insertElementIntoBody(this.element);
			if (_className) {
				this.element.className = _className;
			}
		} else {
			this.element = _elementOrId;
			this.x = parseValue(this.element.style.marginLeft);
			this.y = parseValue(this.element.style.marginTop);
			this.width = parseValue(this.element.style.width);
			this.height = parseValue(this.element.style.height);
			this.visible = this.element.style.display != 'none';
		}
		this.element.style.position = 'absolute';
		this.element.style.overflow = 'hidden';
		this.timeoutFunctions = new Array();
		this.waitingForTimeout = false;
		var f = this.varName + '.redraw();';
		f = f + ' ' + f;
		this.cf.addOnresize(function() {eval(f)});

		this.setPositionRelative = function(_x, _y, _isRelativeX, _isRelativeY) {
			this.x = _x;
			this.y = _y;
			this.isRelativeX = true && _isRelativeX;
			this.isRelativeY = true && _isRelativeY;
			this.redraw();
		}

		this.setPosition = function(_x, _y) {
			this.setPositionRelative(_x, _y, _x < 0, _y < 0);
		}

		this.resize = function(_width, _height, _orientation) {
			if (_width !== false) {
				if (_width != this.width) {
					if (this.isRelativeX) {
						if ((_orientation == 1) || (_orientation == 2)) {
							this.x += (_width - this.width);
						}
					} else {
						if ((_orientation == 3) || (_orientation == 4)) {
							this.x -= (_width - this.width);
						}
					}
				}
				this.width = _width;
			}
			if (_height !== false) {
				if (_height != this.height) {
					if (this.isRelativeY) {
						if ((_orientation == 2) || (_orientation == 3)) {
							this.y += (_height - this.height);
						}
					} else {
						if ((_orientation == 1) || (_orientation == 4)) {
							this.y -= (_height - this.height);
						}
					}
				}
				this.height = _height;
			}
			this.redraw();
		}

		this.redraw = function() {
	//		if (this.isRelativeX || this.isRelativeY) {
	//			this.element.style.display = 'none';
	//		}
			var marginX = this.isRelativeX ? this.cf.getRelativeX(this.x, this.width) : this.x;
			var marginY = this.isRelativeY ? this.cf.getRelativeY(this.y, this.height) : this.y;
			this.element.style.marginLeft = marginX + 'px';
			this.element.style.marginTop = marginY + 'px';
			this.element.style.width = this.width + 'px';
			this.element.style.height = this.height + 'px';
			if ((this.width == 0) || (this.height == 0)) {
				this.element.style.display = 'none';
			} else {
				if (this.visible) {
					this.element.style.display = '';
				}
			}
	//		alert(new Array(this.x, this.y, marginX, marginY, this.width, this.height, this.isRelativeX, this.isRelativeY));
		}

		this.expand = function(_width, _height, _steps, _time, _orientation, _f) {
			if (!_orientation) {
				_orientation = 1;
			}
			if (_steps == 0) {
				this.resize(_width, _height, _orientation);
				if (_f) {
					eval(_f);
				}
			} else {
				if (!_time) {
					_time = 1000;
				}
				var t = _time / _steps;
				if (_width === false) {
					_width = this.width;
				}
				if (_height === false) {
					_height = this.height;
				}
				var dW = _width - this.width;
				var wDesc = dW < 0;
				var w = dW / _steps;
				if ((w == 0) && (dW != 0)) {
					w = wDesc ? -1 : 1;
				}
				var dH = _height - this.height;
				var hDesc = dH < 0;
				var h = dH / _steps;
				if ((h == 0) && (dH != 0)) {
					h = hDesc ? -1 : 1;
				}
				var width = this.width;
				var height = this.height;
				for (var i = 1; i < _steps; i++) {
					width += w;
					width = Math.max(0, Math.floor(wDesc ? Math.max(width, _width) : Math.min(width, _width)));
					height += h;
					height = Math.max(0, Math.floor(hDesc ? Math.max(height, _height) : Math.min(height, _height)));
					this.setTimeoutResize(width, height, _orientation, t);
				}
				this.setTimeoutResize(_width, _height, _orientation, t, _f);
			}
		}

		this.doTimeout = function(_onlyIdle) {
			if (!(_onlyIdle && this.waitingForTimeout)) {
				if (this.timeoutFunctions.length > 0) {
					this.waitingForTimeout = true;
					var f = this.timeoutFunctions.shift();
					var t = f[1];
					f = f[0];
					setTimeout(f + ' ' + this.varName + '.doTimeout();' , t);
				} else {
					this.waitingForTimeout = false;
				}
			}
		}

		this.setTimeout = function(_function, _time) {
			this.timeoutFunctions.push(new Array(_function, _time));
			this.doTimeout(true);
		}

		this.setTimeoutResize = function(_width, _height, _orientation, _time, _f) {
			_f = _f ? ' ' + _f : '';
			this.setTimeout(this.varName + '.resize(' + _width + ', ' + _height + ', ' + _orientation + ');' + _f, _time);
		}

		this.hide = function() {
			this.element.style.display = 'none';
			this.visible = false;
		}

		this.show = function() {
			this.element.style.display = '';
			this.visible = true;
		}
	}

	this.createTabs = function(_varName) {
		return new tabsMain(this, _varName);
	}

	function tabsMain(_cf, _varName) {
		this.cf = _cf ? _cf : new containerFunctions();
		this.varName = _varName ? _varName : this.cf._varName + 'Tabs';
		this.tabs = new Array();
		this.selectedTab = false;

		this.addTab = function(_title, _imgActive, _imgInactive) {
			var index = tabs.length;
			tabs.push(new Array(_title, _imgActive, _imgInactive));
			return index;
		}
	}
}