function Tabs()
{
	this.aTabs = new Array();

	this.classTab = "tab";
	this.classTabDefault = "tab_default";
	this.classTabHide = "tab_hidden";
	this.classTabNav = "tab_navigation";
	this.classNavActive = "tab_navactive";

	this.REclassTab = new RegExp('\\b' + this.classTab + '\\b', 'gi');
	this.REclassTabDefault = new RegExp('\\b' + this.classTabDefault + '\\b', 'gi');
	this.REclassTabHide = new RegExp('\\b' + this.classTabHide + '\\b', 'gi');
}


Tabs.prototype = {
	init : function(sTabHolderID, iDefaultTab)
	{
		var childNodes;
		var eTabHolder, oTab;

		if (isNaN(iDefaultTab)) {
			var iDefaultTab = 0;
		}

		if (!isNaN(window.MessengerAdressBookTab)) {
			iDefaultTab = window.MessengerAdressBookTab;
		}

		//workarround appointment Tab index
		window.appointmentTabIndex = iDefaultTab;


		var DOM_ul, DOM_li;

		eTabHolder = _gel(sTabHolderID);
		if (eTabHolder) {
			// save tab holder id
			if (eTabHolder.id) {
				this.id = eTabHolder.id;
			}

			// check all childs of the tab holder and
			// collect all tabs
			childNodes = eTabHolder.childNodes;
			for (var i=0; i<childNodes.length; i++) {
				if (childNodes[i].className && childNodes[i].className.match(this.REclassTab)) {
					// create new tab object
					oTab = new Object();
					oTab.div = childNodes[i];

					// add tab object to array
					this.aTabs[this.aTabs.length] = oTab;

					if (childNodes[i].className.match(this.REclassTabDefault)) {
						iDefaultTab = this.aTabs.length-1;
					}
				}
			}

			if (this.aTabs.length > 0) {
				// create tab navigation
				DOM_ul = document.createElement("ul");
				DOM_ul.className = this.classTabNav;

				// check all tabs
				for (i=0; i<this.aTabs.length; i++) {
					oTab = this.aTabs[i];

					oTab.sTabText = oTab.div.title;
					if (!oTab.sTabText) {
						oTab.sTabText = i + 1;
					}

					oTab.div.title = '';
					oTab.div.rel = i;

					DOM_li = document.createElement("li");

					// save reference to list element for changing active tab
					oTab.li = DOM_li;

					DOM_a = document.createElement("a");
					DOM_a.appendChild(document.createTextNode(oTab.sTabText));
					DOM_a.href = "javascript:void(null);";
					DOM_a.title = oTab.sTabText;
					DOM_a.onclick = this.onTabNavClick;

					DOM_a.oTabHolder = this;
					DOM_a.iTabIndex = i;

					DOM_a.id = this.id + "_" + i;

					// add link to list element
					DOM_li.appendChild(DOM_a);
					// add list element to list
					DOM_ul.appendChild(DOM_li);

					oSpace = document.createTextNode(" ");
					DOM_ul.appendChild(oSpace);
				}

				// add list before tabs
				eTabHolder.insertBefore(DOM_ul, eTabHolder.firstChild);

				// show default tab
				this.showTab(iDefaultTab);
			}
		}
	},

	onTabNavClick : function(event)
	{
		var eClickedElement = this;
		if (!eClickedElement.oTabHolder) {
			return false;
		}

		// save the selected tab of the adressbook
		if (eClickedElement.id.match(/addressbook_\d+/)) {
			window.MessengerAdressBookTab = eClickedElement.iTabIndex;
		}

		//workarround appointment Tab index
		window.appointmentTabIndex = eClickedElement.iTabIndex;

		eClickedElement.oTabHolder.showTab(eClickedElement.iTabIndex);

		eClickedElement.oTabHolder.startTiny(eClickedElement.iTabIndex);

		return false;
	},

	showTab : function(iTabIndex)
	{
		// check if tab exists
		if (!this.aTabs[iTabIndex])	{
			return false;
		}

		// hide all tabs
		this.hideAllTabs();

		// get selected tab
		var div = this.aTabs[iTabIndex].div;

		var oSelectedTabBuffer = _gel('selected_tab_buffer');
		if (oSelectedTabBuffer) {
			oSelectedTabBuffer.value = div.id;
		}

		// remove hidden class from tab
		div.className = div.className.replace(this.REclassTabHide, '');

		// set current tab in navigation active
		this.navSetActive(iTabIndex);
	},

	hideTab : function(iTabIndex)
	{
		// check if tab exists
		if (!this.aTabs[iTabIndex])	{
			return false;
		}

		// get tab to hide
		var div = this.aTabs[iTabIndex].div;

		// check if already hidden
		if (!div.className.match(this.REclassTabHide)) {
			div.className += ' ' + this.classTabHide;
		}
		this.navClearActive(iTabIndex);
	},

	hideAllTabs : function()
	{
		for (i = 0; i < this.aTabs.length; i++) {
			this.hideTab(i);
		}
	},

	navSetActive : function(iTabIndex)
	{
		this.aTabs[iTabIndex].li.className = this.classNavActive;
	},

	navClearActive : function(iTabIndex)
	{
		this.aTabs[iTabIndex].li.className = '';
	},

	showTabById : function(sTabContentID)
	{
		eTabContent = _gel(sTabContentID);
		if (eTabContent) {
			this.showTab(eTabContent.rel);
		}
	},

	startTiny : function(iTabIndex)
	{

		if (this.aTabs[iTabIndex].div.id == "project_news" || this.aTabs[iTabIndex].div.id == "project_Administration") {
			oProject.initTiny(this.aTabs[iTabIndex].div.id,"false");

		}
	}
}