//= require <mootools-core-1.3-full-nocompat>
//= require <uiframework/TabBar>
//=  require <uiframework/URLUtil>
var TabNavigation = function()
{
	this.Extends = TabBar;

	this.setTabsByUserInfo = function(userInfo)
	{
		if (!userInfo)
			return;
		// Look in the dataProvider for the tab we need if it exists.
		var myAccountIndex = -1;
		var getListedIndex = -1;
		var dp = this.dataProvider();
		var labelField = this.labelField();
		var i = dp.length;
		while (i--)
		{
			var item = dp[i];
			if (item)
			{
				if (item[labelField] == "My Account")
					myAccountIndex = i;
				else if (item[labelField] == "Get Listed")
					getListedIndex = i;
			}
		}
		// ----------------------
		if (userInfo.validated == true)
		{
			if (myAccountIndex == -1)
				this.addTabAt(dp.length,
				{
					label : "My Account",
					url : "action=myAccount"
				}, true);
			if (getListedIndex != -1)
				this.removeTabAt(getListedIndex, true);
		}
		else
		{
			if (getListedIndex == -1)
				this.addTabAt(dp.length, {
					label:"Get Listed", 
					url:"action=getListed"
				}, true);
			if (myAccountIndex != -1)
				this.removeTabAt(myAccountIndex, true);
		}

	};

	this.setSelectedTabByBreadcrumbData = function(crumbs /* Array */)
	{
		if (!crumbs && this.dataProvider())
		{
			this.selectedIndex(0);
			return;
		}
			
		var crumb = crumbs[0];
		var dp = this.dataProvider();
		var i = dp.length;
		while (i--)
		{
			var item = dp[i];
			var hash = URLUtil.searchStringToObject(item.url);
			if (hash.category == crumb.category_id)
			{
				this.selectedIndex(i);
				return;
			}
		}
		this.selectedIndex(0);
	};
};
TabNavigation = new Class(new TabNavigation());
