var aboutHistory =
{
	params :
	{
		collection : []
	}
	,init : function()
	{
		aboutHistory.collect();
		aboutHistory.createNavigation();
	}
	,collect : function()
	{
		var i, x, title, list = afw.common.functions.getElement('history-table');
		if(list && (list = afw.common.functions.getElements(list, 'TR')))
		{
			for(i = 0, x = list.length; i < x; ++i)
			{
				if(title = afw.common.functions.getElements(list[i], 'H2'))
				{
					title = afw.common.functions.trim(title[0].innerHTML);
					aboutHistory.params.collection.push(
					{
						title : title
						,tableRow : list[i]
					});
				}
			}
		}
	}
	,createNavigation : function()
	{
		var first, table, parent, child, i, x, list = aboutHistory.params.collection;
		if(table = afw.common.functions.getElement('history-table'))
		{
			parent = document.createElement('DIV');
			parent.id = 'history-navigation';
			for(i = 0, x = list.length; i < x; ++i)
			{
				child = document.createElement('DIV');
				child.className = 'menu';
				child.innerHTML = '<h3>' + list[i].title + '</h3>';
				(function(title)
				{
					child.onclick = function(){ aboutHistory.display(title, this); };
				})(list[i].title);
				parent.appendChild(child);
				if(i == 0)
				{
					first =
					{
						title : list[i].title
						,child : child
					};
				}
			}
			table.parentNode.insertBefore(parent, table);
			if(first)
			{
				aboutHistory.display(first.title, first.child);
			}
		}
	}
	,display : function(title, dom)
	{
		var tableRow;
		if(!afw.common.functions.classExists(dom, 'active'))
		{
			aboutHistory.hide();
			afw.common.functions.addClass(dom, 'active');
			if(tableRow = aboutHistory.title2dom(title))
			{
				afw.common.functions.addClass(tableRow, 'active');
			}
		}
	}
	,hide : function()
	{
		var navigation, active, title, tableRow;
		if(navigation = afw.common.functions.getElement('history-navigation'))
		{
			if(active = afw.common.functions.getChildren(navigation, 'DIV', 'active'))
			{
				afw.common.functions.removeClass(active[0], 'active');
				if(title = afw.common.functions.getChildren(active[0], 'H3'))
				{
					title = title[0].innerHTML;
					if(tableRow = aboutHistory.title2dom(title))
					{
						afw.common.functions.removeClass(tableRow, 'active');
					}
				}
			}
		}
	}
	,title2dom : function(title)
	{
		var i, x, list = aboutHistory.params.collection;
		for(i = 0, x = list.length; i < x; ++i)
		{
			if(list[i].title == title)
			{
				return list[i].tableRow;
			}
		}
		return false;
	}
};
afw.common.functions.addEvent('load', window, aboutHistory.init);
