var action_timer = null;

var action;

var linkarray = new Array();

var options;

var separators;

var optionholder;

var activetabs;

function getmenuelements()
{
	options = new Array(document.getElementById('popupbutton0'),
						document.getElementById('popupbutton1'),
						document.getElementById('popupbutton2'),
						document.getElementById('popupbutton3'),
						document.getElementById('popupbutton4'),
						document.getElementById('popupbutton5'),
						document.getElementById('popupbutton6'),
						document.getElementById('popupbutton7'));
	optionholder = document.getElementById('optionholder');
	separators = new Array(document.getElementById('sep0'),
							document.getElementById('sep1'),
							document.getElementById('sep2'),
							document.getElementById('sep3'),
							document.getElementById('sep4'),
							document.getElementById('sep5'),
							document.getElementById('sep6'));
}

function setaction(newaction)
{
	action = newaction;
	clearTimeout(action_timer);
	action_timer = setTimeout("performaction()",500);
}

function performaction()
{
	if (action != "dontcollapse")
	{
		collapsetabs();
		if (action != "collapse")
		{menubutton(action);}		
	}

}

function menubutton(button)
{		
	optionholder.className = "menu";
	activetabs = [];
	switch (button)
	{
		case "0":
 		{				
			settab(0,"HOME PAGE","/");
			settab(1,"SITE MAP","site-map.php");
							
			break;
		}

		case "1":
 		{
			settab(1,"CONSULTANTS","consultants.php");
			settab(2,"CLIENTS","client-list.php");
						
			break;
		}
		
		case "2":
 		{
			settab(2,"IMPROVING ORGANISATION PERFORMANCE","improving-organisation-performance.php");
			settab(3,"BENCHMARKING BEST PRACTICES","benchmarking.php");
			settab(4,"COACHING","coaching.php");
			settab(5,"EXECUTIVE LEADERSHIP GROUPS","pdf/ExecutiveLeadershipGroupFlyer.pdf");
			settab(6,"FACILITATION FOR RESULTS","facilitation-for-results.php");
			settab(7,"DEVELOPING EXECUTIVES","developing-executives.php");
												
			break;
		}
		
		case "3":
 		{
			settab(3,"GROUPED BY TYPE","sample-assignments.php");
			
			break;
		}

		case "4":
 		{
			settab(4,"GROUPED BY TYPE","resources-and-publications.php");

			break;
		}
		
		case "5":
 		{
			settab(5,"LATEST UPDATE","book.php");
			
			break;
		}

		default:
		{}
	}
	activetabs.sort();
	for (i = (activetabs[0]); i < activetabs[activetabs.length - 1]; i++)
	{separators[i].style.visibility = "visible";}
}

function settab(index,title,link)
{
	options[index].innerHTML = title;
	linkarray[index] = link;
	options[index].style.visibility = "visible";
	activetabs.push(index);
}

function collapsetabs()
{
	for (i = 0; i < options.length; i++)
	{options[i].style.visibility = "hidden";}
	for (i = 0; i < separators.length; i++)
	{separators[i].style.visibility = "hidden";}
	optionholder.className = "invisible";
}

function clickedlink(optionno)
{window.location = linkarray[optionno];}
