/**
 * ./js/tuv_accordion.class.js
 * @package js
 * @version $id$
 */
(function($)
{
	$('.accordion > li').not('.showall').children('a').bind('click', toggleNode).next().hide();

	$('.accordion > li.showall > a').bind('click', showAllNodes);

	 /**
	 * Open the clicked node
	 * @author Dominik Siebel <dominik.siebel@twt.de>
	 */
	function toggleNode(event)
	{
		$node = $(this);
		if ($node.parent().hasClass('active'))
		{
			$node.parent().removeClass('active');
			$node.next().hide();
		} // if
		else
		{
			$node.parent().addClass('active');
			$node.next().show();
		} // else
		event.preventDefault();
	} //function

	/**
	 * Hide all nodes
	 * @author Dominik Siebel <dominik.siebel@twt.de>
	 */
	function hideAllNodes(event)
	{
		$hideall = $(this);
//		$hideall.text('Alle Antworten einblenden');
		$hideall.text($('.accordion > li.showall  .showall_text:first').text());
		$hideall.parent().siblings().not('.showall').each(function() {
			$node_li = $(this);
			$node_li.removeClass('active');
			$node_li.children('a').next().hide();
		}); // each()
		$hideall.unbind('click').bind('click', showAllNodes);
		event.preventDefault();
	}

	/**
	 * show all nodes
	 * @author Dominik Siebel <dominik.siebel@twt.de>
	 */
	function showAllNodes(event)
	{
		$showall = $(this);
//		$showall.text('Alle Antworten ausblenden');
		$showall.text($('.accordion > li.showall  .hideall_text:first').text());
		$showall.parent().siblings().not('.showall').each(function() {
			$node = $(this);
			$node.addClass('active');
			$node.children('a').next().show();
		}); // each()
		$showall.unbind('click').bind('click', hideAllNodes);
		event.preventDefault();
	}
})(jQuery);

