/**
 * JavaScript library for the iccore extension. Include this in each controller that needs
 * access to any of this functions.
 *
 * (c) 2009 Boris Feldmann <boris.feldmann@tsitrone.de>
 */

/**
 * Toggles tab menu items that were created with the base view method createTabMenu().
 *
 * @param	string	element that was clicked and called this function.
 * @param	string	ID of the element that should be displayed.
 */
function tabMenuItemClicked(item, tabMenuContent) {
	// Gets parent <li> element
	var li = $(item).getParent('li');
	// Gets parent <ul> element
	var ul = $(li).getParent('ul');
	// Gets wrapping <div> element
	var wrapper = $(ul).getParent('div');
	// Resets class attribute of all <li> tags.
	var liElements = $(ul).getChildren('li');
	for (var i = 0; i < liElements.length; i++) {
		var a = $(liElements[i]).getChildren('a');
		// Set menu item style to 'normal'
		$(a[0]).setStyle('background', '');
		$(a[0]).setStyle('color', '');
		$(a[0]).setStyle('border', 'none');

		//set all to inactive: print.css sets  display to none for all li's without this class
		$(liElements[i]).removeClass('act');

	}
	// Set class attribute to 'act' for active <a> tag.
	$(item).setStyle('background', 'white');
	$(item).setStyle('border', '1px solid #c0c0c0');
	$(item).setStyle('border-bottom', 'none');

	//set flag  to print this tab
	$(li).addClass('act');

	// Hide all contents from inactive tabs
	var contentDivs = $(wrapper).getElements('div.tabMenuContent');
	for (var i = 0; i < contentDivs.length; i++) {
		$(contentDivs[i]).setStyle('display', 'none');
	}
	// Show selected tabMenuContent
	$(tabMenuContent).setStyle('display', 'block');
}
