function select_tab(tab)
{
	var selectedClass = 'selected';
	var tabs_div = document.getElementById('tabs');
	var tabs = tabs_div.getElementsByTagName('li');
	for (var i = 0; i < tabs.length; i = i + 1)
	{
		var classes = tabs[i].className;
		var re = new RegExp('(^|\\s)' + selectedClass + '(\\s|$)');

		classes = classes.replace(re, ' ');
		if (tabs[i] === tab.parentNode)
		{
			classes += ' ' + selectedClass;
		}
		tabs[i].className = classes;
	}
}

function show_section(container, obj, divClass)
{
	var divs = container.getElementsByTagName('div');
	var sections = [];
	var minHeight = 330;

	var h = 0;

	for (i = 0; i < divs.length; i = i + 1)
	{
		if (divs[i].className === divClass)
		{
			sections.push(divs[i]);
			if( divs[i].style.display != 'none' )
			{
				h += $(divs[i]).getHeight();
			}
		}
	}

	if( h < minHeight )
	{
		h = minHeight;
	}
	$(container).style.minHeight = h + 'px';

	if (sections.length > 0)
	{
		for (i = 0; i < sections.length; i = i + 1)
		{
			if (sections[i] !== obj && sections[i].style.display != 'none')
			{
//				Effect.BlindUp(sections[i]);
				Effect.SlideUp(sections[i],
				{
					duration: 0.55, 
					queue:
					{
						position: 'end',
						scope: 'tabreveal'
					} 
				});
			}
		}

		if (obj.style.display == 'none')
		{
//			Effect.BlindDown(obj, { queue: 'end' } );
			Effect.SlideDown(obj,
			{
				duration: 0.25,
				queue:
				{
					position: 'end', 
					scope: 'tabreveal'
				},
				afterFinish: function()
				{
					h = $(obj).getHeight();
					if (h < minHeight )
					{
							h = minHeight;
					}
					$(container).style.height = ($(container).getHeight() - 2) + 'px';
					$(container).style.minHeight = minHeight + 'px';
					$(container).morph('',
					{
						style: 'height: ' + h + 'px;', 
						duration: 0.1,
						afterFinish: function()
						{
							$(container).style.height = '';
						}
					});
				}
			});
		}
	}

}

function show_tab(name, tab)
{
	select_tab(tab);

	var obj = document.getElementById(name);

	if (obj)
	{
		var c = document.getElementById('product_sections');
		show_section(c, obj, 'tabbed_section');
		return false;
	}
	else
	{
		return true;
	}
}

function showOnloadTab()
{
	var section = 'features';
	var hash=window.location.hash;
	if( hash)
	{
		section = hash.substring(1);
	}
	var obj = document.getElementById(section);
	if (obj)
	{
		var c = document.getElementById('product_sections');

		var divs = c.getElementsByTagName('div');
		var divClass = 'tabbed_section';

		for (var i = 0; i < divs.length; i = i + 1)
		{
			if (divs[i].className === divClass && divs[i] != obj)
			{
				divs[i].style.display = 'none';
			}
		}
	}
}

