/*	Function: display_selected(select_num, max_num, div_tag)

	Display selected element and hide all others in the group. Each item must be given an ID comprised
	of an ID value plus a unique number, eg. "ExampleDiv1".
	For a single button, or a pair of buttons, select_num should be set to -1 for incremental shuffling of
	the hidden items, or -2 for decremental shuffling.
	If select_num > 0 then each onclick call of this function should provide a unique positive number
	correlating with the hidden object to be displayed.
	
	Author: 	Justin F Welch
	Created On:	2009-8-12
	Last Edit:	2009-8-13
*/
function display_selected(select_num, max_num, div_tag, /*OPTIONAL*/show_multi, /*OPTIONAL*/close_div)
{
	show_multi = show_multi || 0;
	close_div = close_div || 0;
	if(select_num == -1)
		dec_shift(max_num, div_tag);
	else if(select_num == -2)
		inc_shift(max_num, div_tag);
	else if(select_num > 0 && close_div == 0)
	{
		if(show_multi == 1)
			show_many_div(select_num, max_num, div_tag);
		else if(show_multi == 0)
			show_one_div(select_num, max_num, div_tag);
	}
	else if(close_div == 1)
		close_current_div(select_num, div_tag);
		
}

// 	Function: display_hid_div_simple(div_tag)
function display_hid_div_simple(div_tag)
{
	document.getElementById(div_tag).style.visibility = "visible";
	document.getElementById(div_tag).style.display = "block";
}

//	Function: close_hid_div_simple(div_tag)
function close_hid_div_simple(div_tag)
{
	document.getElementById(div_tag).style.visibility = "hidden";
	document.getElementById(div_tag).style.display = "none";	
}

//	Function: show_div(select_num, max_num, div_tag)
function show_one_div(select_num, max_num, div_tag)
{
	for(i=1; i<=max_num; i++)
	{
		var divId = div_tag + i;
	
		document.getElementById(divId).style.visibility = "hidden";
		document.getElementById(divId).style.display = "none";	
	}
	
	var divId = div_tag + select_num;
	document.getElementById(divId).style.visibility = "visible";
	document.getElementById(divId).style.display = "block";
}

/*	Function: show_div(select_num, max_num, div_tag)

	Makes the selected div visible without hiding the others.
*/
function show_many_div(select_num, max_num, div_tag)
{
	var divId = div_tag + select_num;
	document.getElementById(divId).style.visibility = "visible";
	document.getElementById(divId).style.display = "block";
}

/*	Function: close_current_div(select_num, div_tag)

	Hides the selected div.
*/
function close_current_div(select_num, div_tag)
{
	var divId = div_tag + select_num;
	document.getElementById(divId).style.visibility = "hidden";
	document.getElementById(divId).style.display = "none";	
}

/*	Function: inc_shift(max_num, div_tag)

	Increments through a list of divs with ID equal to div_tag# hidding the previous selection
	and displaying the next in the series.
*/
function inc_shift(max_num, div_tag)
{
	var vis = 0;

	for(i=1; i<=max_num; i++)
	{
		var divId = div_tag + i;
		if (document.getElementById(divId).style.visibility == "visible" && i != max_num)
			vis = (i + 1);
		else if (i == max_num)
			vis = 1;
		if (vis != 0) i = 9;
	}

	for(i=1; i<=max_num; i++)
	{
		var divId = div_tag + i;
		if (i == vis) 
		{
			document.getElementById(divId).style.visibility = "visible";
			document.getElementById(divId).style.display = "block";
		}
		else
		{
			document.getElementById(divId).style.visibility = "hidden";
			document.getElementById(divId).style.display = "none";
		}
	}
}

/*
	Function: dec_shift(max_num, div_tag)

	Decrements through a list of divs with ID equal to div_tag# hiding the previous selection
	and displaying the next in the series.
*/
function dec_shift(max_num, div_tag)
{
	var vis = 0;

	for(i=max_num; i>=1; i--)
	{
		var divId = div_tag + i;
		if (document.getElementById(divId).style.visibility == "visible" && i != 1)
		vis = (i - 1);
		else if (i == 1)
		vis = max_num;
		if (vis != 0) i = 0;
	}

	for(i=1; i<=max_num; i++)
	{
		var divId = div_tag + i;
		if (i == vis) 
		{
			document.getElementById(divId).style.visibility = "visible";
			document.getElementById(divId).style.display = "block";
		}
		else
		{
			document.getElementById(divId).style.visibility = "hidden";
			document.getElementById(divId).style.display = "none";
		}
	}
}
