function TabPane(
	aTabElements,
	aTabSheetElements,
	oParams
	) {

	this.aTabElements = aTabElements;
	this.aTabSheetElements = aTabSheetElements;
	this.oParams = Common.Object.extend(
		TabPane.DEFAULT_PARAMS,
		oParams
		);

	this.iSelectedIndex = this.getInitialSelectedIndex();

	var oThis = this;

	for(var i = 0; i < this.aTabElements.length; i++) {
		Common.Event.add(
			this.aTabElements[i],
			'click',
			function(iSelectedIndex) {

				return function(oEvent) {

					oThis.select(iSelectedIndex);

					Common.Event.cancel(oEvent);

				}

			}(i)
			);
	}

	this.select(this.getSelectedIndex());

}

TabPane.DEFAULT_PARAMS = {
	bStoreInCookie : false,
	sCookiePrefix  : '__'
	};

TabPane.CLASS_NAME_INVISIBLE = 'invisible';
TabPane.CLASS_NAME_SELECTED  = 'selected';

TabPane.prototype = {

	getInitialSelectedIndex : function() {

		for(var i = 0; i < this.aTabElements.length; i++) {
			if(Common.Class.match(this.aTabElements[i], TabPane.CLASS_NAME_SELECTED)) {
				return i;
			}
		}

		return 0;

	},

	getSelectedIndex : function() {

		return this.iSelectedIndex;

	},

	setSelectedIndex : function(iSelectedIndex) {

		this.iSelectedIndex = iSelectedIndex;

	},

	select : function(iSelectedIndex) {
	
		if(iSelectedIndex == this.getSelectedIndex()) {
			return;
		}

		Common.Class.remove(this.aTabElements[this.getSelectedIndex()], TabPane.CLASS_NAME_SELECTED);
		Common.Class.add(this.aTabSheetElements[this.getSelectedIndex()], TabPane.CLASS_NAME_INVISIBLE);

		this.setSelectedIndex(iSelectedIndex);

		Common.Class.add(this.aTabElements[this.getSelectedIndex()], TabPane.CLASS_NAME_SELECTED);
		Common.Class.remove(this.aTabSheetElements[this.getSelectedIndex()], TabPane.CLASS_NAME_INVISIBLE);

		// ie hack
		if(this.aTabElements[this.getSelectedIndex()].tagName.toLowerCase() == 'div') {

			this.aTabElements[this.getSelectedIndex()].style.display = 'none';
			this.aTabElements[this.getSelectedIndex()].style.display = 'block';

		}

		if(this.oParams.bStoreInCookie) {
			Common.Cookie.set(this.oParams.sCookiePrefix + '_tab', iSelectedIndex);
		}

	}

};
