// {{{ function historyLast
function historyLast()
{
	var offset = -(50 * 3 * 7);

	return history(offset);
}
// }}}
// {{{ function historyNext
function historyNext()
{
	var offset = historyOffset - (50 * 7);

	return history(offset);
}
// }}}
// {{{ function historyPrev
function historyPrev()
{
	var offset = historyOffset + (50 * 7);

	return history(offset);
}
// }}}
// {{{ function historyFirst
function historyFirst()
{
	var offset = 0;

	return history(offset);
}
// }}}
// {{{ function history
function history(offset)
{
	// validate
	if (offset > 0 || offset < (-50 * 3 * 7))
	{
		return false;
	}

	var table = document.getElementById('history');

	// get header row by id and offset
	historyMove(document.getElementById('history-dates'), offset);

	for (var i=0; i < table.childNodes.length; i++)
	{
		if (table.childNodes[i].getAttribute && table.childNodes[i].getAttribute('id'))
		{
			var row = table.childNodes[i];
			var type = row.getAttribute('id').match(/(group|services)/);

			if (!type)
			{
				continue;
			}
			type = type[1];

			for (var j=0; j < row.childNodes.length; j++)
			{
				if (type == 'group')
				{
					if (row.childNodes[j].className && row.childNodes[j].className.match(/row-history/))
					{
						for (var x = 0; x < row.childNodes[j].childNodes.length; x++)
						{
							if (row.childNodes[j].childNodes[x].tagName)
							{
								historyMove(row.childNodes[j].childNodes[x], offset);
							}
						}
					}
				}
				else
				{
					if (row.childNodes[j].getAttribute)
					{
						var subRow = row.childNodes[j];

						for (var k=0; k < subRow.childNodes.length; k++)
						{
							if (subRow.childNodes[k].className && subRow.childNodes[k].className.match(/row-history/))
							{
								for (var x = 0; x < subRow.childNodes[k].childNodes.length; x++)
								{
									if (subRow.childNodes[k].childNodes[x].tagName)
									{
										historyMove(subRow.childNodes[k].childNodes[x], offset);
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return false;
}
// }}}
// {{{ function historyMove
function historyMove(element, offset)
{
	element.style.left = offset;
	historyOffset = offset;

	var disabled = ['history-link-active', 'history-link-inactive'];
	var enabled = ['history-link-inactive', 'history-link-active'];

	//var link_first = document.getElementById('history-link-first');
	var link_prev = document.getElementById('history-link-prev');
	var link_next = document.getElementById('history-link-next');
	//var link_last = document.getElementById('history-link-last');

	// update link styles
	if (offset >= 0)
	{
		var left = disabled;
		var right = enabled;
	}
	else if (offset <= (-50 * 3 * 7))
	{
		var left = enabled;
		var right = disabled;
	}
	else
	{
		var left = enabled;
		var right = enabled;
	}

	//link_first.className = link_first.className.replace(left[0], left[1]);
	link_prev.className = link_prev.className.replace(left[0], left[1]);
	link_next.className = link_next.className.replace(right[0], right[1]);
	//link_last.className = link_last.className.replace(right[0], right[1]);
}
// }}}


var historyOffset = -3 * 7 * 50;
