function ClassTabs()
{
	/* User defined */
	this.TabHeight = 20;
	
	/* Class */
	this.TabCounter = 0;
	this.TabSourceData = Array();
	this.AniTimer = false;
	this.AniSpeed = 10;
	this.AniTab = -1;
	this.AniState = '#close';
		
	this.Initialize = function()
	{
		/* Read the data from the divs */
		var tabs = document.getElementsByTagName("div");
		for (var i=0; i<tabs.length; i++)
		{
			var currentTab = tabs[i];
			if(currentTab.className == 'main_nav_tab')
			{
				/* Read tab creation params (which are stored within the tab itself....) */
				var readData = currentTab.innerHTML.split('|');
				this.TabSourceData.push(readData);

				/* Clean div from source data */
				currentTab.innerHTML = '';
				
				currentTab.style.display = 'inline';
								
				/* Add attributes to the tab */
				currentTab.id = 'main_nav_tab_'+this.TabCounter;
				
				/* Add events... */
				AddEvent(currentTab, "mouseover", function(evt) { return OpenTab(evt); }, true);
				//AddEvent(currentTab, "mouseout", function(evt) { return CloseTab(evt); }, true);
				
				sHtml = '';

				/* Set text in tab itself */
				currentTab.innerHTML = sHtml;
				
				/* Create the content div for when the tab is opened */
				this.CreateTabContent(currentTab);

				/* Inc. the number of the tabs */
				this.TabCounter++;
			}
		}
	}
	
	this.CreateTabContent = function(currentTab)
	{
		/* Create stuff with data as input
			Format :
				1: name of the tab
				2: width of the opened tab
				3: height of the opened tab
				4: background color of the tab
		*/
		
		var TabContent = document.createElement("div");
		TabContent.id = "tabContent_"+this.TabCounter;
		
		TabContent.style.position = 'absolute';
		TabContent.style.left = findPosX(currentTab) + 'px';
		TabContent.style.top = findPosY(currentTab) + this.TabHeight + 'px';
		
		TabContent.style.padding = '0px';
		TabContent.style.margin = '0px';
		
		TabContent.style.width = this.TabSourceData[this.TabCounter][1]+'px';
		TabContent.style.height = 0 +'px';
		//TabContent.style.backgroundColor = this.TabSourceData[this.TabCounter][3];
		
		TabContent.style.overflow = 'hidden';
		TabContent.innerHTML = this.TabSourceData[this.TabCounter][4];
		
		document.body.appendChild(TabContent);
	}

	this.TabCount = function()
	{
		return this.TabCounter;
	}
	
	this.GetCurrentTab = function ()
	{
		return this.AniTab;
	}
	
	this.ShowTab = function(tab_nr)
	{
		if(this.AniState == '#animate') { return true; }
		
		/* Not closed and is opened before */
		if(this.AniState == '#open' && this.AniTab != tab_nr)
		{
			/* save prev tab height */
			this.TabSourceData[this.AniTab][2] = this.GetTabHeight();
			
			/* close current tab */
			this.SetTabHeight(0);
		
			/* open new tab */
			document.body.focus();
			this.AniTab = tab_nr;
			
			var _this = this;
			clearInterval(this.AniTimer);
			this.AniTimer = window.setInterval(function() { _this.EnlargeInTimer(); }, 10);
			
			return true;
		}
		
		/* Initial state */
		if(this.AniState == '#close')
		{
			/* new tab opened */
			document.body.focus();
			this.AniTab = tab_nr;
			var _this = this;
			clearInterval(this.AniTimer);
			this.AniTimer = window.setInterval(function() { _this.EnlargeInTimer(); }, 10);
		}
	}
	
	this.EnlargeInTimer = function()
	{
		var height = parseInt(document.getElementById('tabContent_'+this.AniTab).style.height);
		
		if(height < this.TabSourceData[this.AniTab][2])
		{
			height = height + this.AniSpeed;
			this.SetTabHeight(height);
			this.AniState = '#animate';
		}
		else
		{
			height = this.TabSourceData[this.AniTab][2];
			this.SetTabHeight(height);
			this.AniState = '#open';
			clearInterval(this.AniTimer);
		}
	}
	
	this.GetTabHeight = function ()
	{
		if(document.getElementById('tabContent_'+ this.AniTab))
		{
			return parseInt(document.getElementById('tabContent_'+ this.AniTab).style.height);
		}
		else
		{
			return false;
		}
	}
	
	this.SetTabHeight = function (height)
	{
		document.getElementById('tabContent_'+ this.AniTab).style.height = height + 'px';
	}
}

function OpenTab (evt)
{
	var tabElem = (evt.target) ? evt.target : evt.srcElement;
	if(tabElem.id != '')
	{
		var tabData = tabElem.id.split('_');
		var tabNumber = parseInt(tabData[(tabData.length - 1)]);
		if(typeof(tabNumber) == 'number' && tabNumber > -1)
		{
			Tabs.ShowTab(tabNumber);
		}
	}
}

function CloseTab (evt)
{
	Tabs.AniState = '#close';
	Tabs.SetTabHeight(0);
	return true;
}