// this file handles the acordeon menu
// author:    Dominik Scholz, schlotzz@go4u.de
// changed:   2009-08-27

var acordeon_width = 40;
var acordeon_border = 1;
var acordeon_index = new Array();
var acordeon_interval;
var acordeon_selected;

window.onload = acordeon_start;

function acordeon_start()
{
	// choose first tab by time
	var now = new Date();
	var t = now.getHours()*100+now.getMinutes();
	var i = 1;
	if (t >= 1100 && t < 1400) i = 2;
	if (t >= 1400 && t < 2200) i = 3;

	acordeonOver(document.getElementById('tab'+i));
}

function acordeonClick(obj)
{
	obj = obj.getElementsByTagName('a');
	if (obj.length <= 0)
		return;
	obj = obj[0];
}

function acordeonOver(obj)
{
	// not looked for other tabs
	if (acordeon_index.length == 0)
	{
		sibling = obj;
		while (sibling = acordeon_previousSibling(sibling))
			acordeon_index.push(sibling);

		acordeon_index.push(obj);

		sibling = obj;

		while (sibling = acordeon_nextSibling(sibling))
			acordeon_index.push(sibling);
	}

	acordeon_selected = -1;
	for (var i=0; i<acordeon_index.length; i++)
		if (acordeon_index[i] == obj)
			acordeon_selected = i;

	if (!acordeon_interval)
		acordeon_interval = window.setInterval("acordeon_animate()", 40);
}

function acordeon_animate()
{
	if (acordeon_selected < 0)
	{
		window.clearInterval(acordeon_interval);
		acordeon_interval = null;
		return;
	}

	var parent = acordeon_index[acordeon_selected].parentNode;
	var changed = false;
	var remaining = 0;
	var sibling;
	var width;

	for (var i=0; i<acordeon_selected; i++)
	{
		sibling = acordeon_index[i];
		width = parseInt(sibling.offsetWidth/1.2);
		if (width < acordeon_width)
			width = acordeon_width;
		else
			changed = true;
		remaining += width;
		sibling.style.width = width+'px';
	}
	for (var i=acordeon_selected+1; i<acordeon_index.length; i++)
	{
		sibling = acordeon_index[i];
		width = parseInt(sibling.offsetWidth/1.2);
		if (width < acordeon_width)
			width = acordeon_width;
		else
			changed = true;
		remaining += width;
		sibling.style.width = width+'px';
	}

	acordeon_index[acordeon_selected].style.width = (parent.offsetWidth - remaining - acordeon_border)+'px';

	if (!changed && acordeon_interval)
	{
		window.clearInterval(acordeon_interval);
		acordeon_interval = null;
	}
}

function acordeon_previousSibling(obj)
{
	var sibling = obj.previousSibling;
	while (sibling != null && sibling.nodeName != 'LI')
		sibling = sibling.previousSibling;
	return sibling;
}

function acordeon_nextSibling(obj)
{
	var sibling = obj.nextSibling;
	while (sibling != null && sibling.nodeName != 'LI')
		sibling = sibling.nextSibling;
	return sibling;
}

