AXTabPanel = function(id, selectedId, tabsId, tabContentId)
{
	this.id = id ? id : 'tabpanel';
	this.tabsId = tabsId ? tabsId : 'tabs';
	this.tabContentId = tabContentId ? tabContentId : 'tabcontent';
	this.selectedId = selectedId ? selectedId : 0;
	this.init = function()
	{
		//get tabs and divs
		var o = $(this.tabsId);
		if(o != null)
		{
			this.tabs = o.getElementsByTagName('li');
			this.tabNames = new Array();
			if(typeof(Event.observe) != undefined)
			{
				var links = $(this.tabsId).getElementsByTagName('a');
				for (var j=0;j<links.length;j++)
				{
					if(links[j].innerHTML != null)
					{
						this.tabNames[j] = links[j].innerHTML;
					}
					Event.observe(links[j], 'click', this.selectTab.bindAsEventListener(this), false);
				}
			}
		}
		
		this.divs = new Array();
		o = $(this.tabContentId);
		if(o != null)
		{
			for(var i=0; i<o.childNodes.length; i++)
			{
				if(o.childNodes[i].nodeName == "DIV")
				{
					this.divs.push(o.childNodes[i]);
				}
			}
		}
	}
	
	this.hideTab = function hideTab(id)
	{
		if(typeof(id) != 'number')
		{
			for(var i=0; i<this.tabNames.length; i++)
			{
				if(this.tabNames[i] == id)
				{
					id = i;
					break;
				}	
			}
		}
		
		if(this.tabs != null && this.divs != null && id != null)
		{
			if(this.tabs[id] != null)
			{
				this.tabs[id].style.display = "none";
			}
			if(this.divs[id] != null)
			{
				this.divs[id].style.display = "none";
			}
		}
	}
	
	this.selectTab = function selectTab(e)
	{
		if(this != arguments.callee._oScope){
			return arguments.callee.apply(arguments.callee._oScope, arguments);
		}
		
		var id = 0;
		if(typeof(e) != 'number')
		{
			if(typeof(e) == 'object')
			{
				var o = null;
				if (e.target){o = e.target;}
				else if (e.srcElement){o = e.srcElement;}
				
				//make sure to get the parent a tag
				if(o.nodeName != "A")
				{
					o = o.parentNode;
				}
				
				var t = o.parentNode.parentNode.getElementsByTagName('li');
				for(var i=0; i<t.length; i++)
				{
					if(t[i] == o.parentNode)
					{
						id = i;
						break;
					}
				}
			}
			else
			{
				for(var i=0; i<this.tabNames.length; i++)
				{
					if(this.tabNames[i] == e)
					{
						id = i;
						break;
					}	
				}
			}
		}
		else
		{
			id = e;
		}
		
		if(this.tabs != null && this.divs != null && id != null)
		{
			for (var i=0;i<this.tabs.length;i++)
			{
				if(i != id)
				{
					if(this.tabs[i] != null)
					{
						this.tabs[i].className = "tab";
					}
					if(this.divs[i] != null)
					{
						this.divs[i].style.display = 'none';
					}
				}
				else
				{
					if(this.tabs[i] != null)
					{
						this.tabs[i].className = "tab-selected";
					}
					if(this.divs[i] != null)
					{
						this.divs[i].style.display = 'block';
					}
				}
			}
			this.selectedId = id;
		}
	}
	this.selectTab._oScope = this;
	
	this.showTabs = function(show)
	{
	
	}
	
	this.init();
	this.selectTab(this.selectedId);
}
