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()
	{
		this.tabs = [];
		this.tabNames = [];
		
		//get tabs and divs
		$$('#'+this.tabsId + ' li').each(function(tab){    
	        var a = tab.getElementsBySelector('a');
	        if(a && a.length > 0)
	        {
	            if(a[0].innerHTML)
	                this.tabNames.push(a[0].innerHTML);
	            
	            a[0].observe('click', this.selectTab.bindAsEventListener(this), false);
	            this.tabs.push(tab);
	        }   
		}.bind(this));
		
		this.divs = $$('#'+this.tabContentId+' div.textfield');
	}
	
	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)
					{
						if(i == 0)
						{
						    var slide = this.divs[i].getElementsBySelector('#slides');
						    if(slide && slide.length > 0)
						    {
						        slide = slide[0];
						        slide.setStyle({width: "1px", height: "1px"});
						        this.divs[i].setStyle({width: "1px", height: "1px"});
						    }
						    else
						    {
						        $(this.divs[i]).style.display = 'none'; 
						    } 
						}
						else
						{
						    this.divs[i].style.display = 'none';
					    }
					}
				}
				else
				{
					if(this.tabs[i] != null)
					{
						this.tabs[i].className = "tab-selected";
					}
					if(this.divs[i] != null)
					{
						if(i == 0)
						{
						    var slide = this.divs[i].getElementsBySelector('#slides');
						    if(slide && slide.length > 0)
						    {
						        slide = slide[0];
						        slide.setStyle({width: "100%", height: "100%"});
						        $(this.divs[i]).setStyle({width: "", height: ""});
						    }
						    else
						    {
						        this.divs[i].style.display = 'block'; 
						    }  
						}
						else
						{
						    this.divs[i].style.display = 'block';
					    }
					}
				}
			}
			this.selectedId = id;
			
			if(typeof(this.onTabSelected) != 'undefined')
			{
			    this.onTabSelected(this.selectedId);
			}
		}
	}
	this.selectTab._oScope = this;
	
	this.showTabs = function(show)
	{
	
	}
	
	this.init();
	this.selectTab(this.selectedId);
}
