/***************************************************************************************
**                                Create Drop Down Menus
**                                  Written on:5/27/08
**                                Author: Dennis Cornwell
***************************************************************************************/

//Global Variables
var menuFlag = new Array();//Works like a boolean (1: menu open, 0:menu closed)
var menuArray = new Array();//Holds list of HTML elements
var I = 1; //Index value (for recursive function definition. **MUST BEGIN AT 1**)

/***************************************************************************************
** Function: Create Menus
** Purpose: Creates menus which can be clicked to display contents.
** Input: (Id of Element being applied to),
**        (String of menus in the format of:
**        *MenuName*,*MenuData*,*MoreData*,...;*NewMenuName*,*NewMenuData,...;)
** Note: Menu titles can be referenced in CSS by their MenuName with all spaces removed
***************************************************************************************/
function menuCreate(elementId, menuData)
{
	var N; //Index -- holds size of menuArray
	menuArray = menuData.split(';'); //Divide data into separate menus
	
	//Divide data once more into menu items
	for(N = 0; N < menuArray.length; N++)
	{
		//Assemble each menu
		menuArray[N] = menuArray[N].split(',');
		menuFlag[N] = 0;
		//classId = menuArray[N][0].replace(/ /g,"");//Removes all spaces for CSS use
		//Display Menus
		elementId.innerHTML += "<div class='picMenuHead' onclick='collapse("+N+");'>"+
	                                   menuArray[N][0]+"</div><br />"+
                                       "<span class='photomenu' id='menu"+N+"'></span>";  
	}
}
/***************************************************************************************
** Function: Collapse Menus
** Purpose: Displays/removes contents of menu
** Input: Supplied by preformatted menus created above.
***************************************************************************************/
function collapse(menuNum)
{
	menuId = document.getElementById("menu"+menuNum);
	//Check to see if the menu is open or not
	if( menuFlag[menuNum] == 0 )
	{
		//var T; //Holds timeout
		for(I = 1;I < menuArray[menuNum].length;I++)
		{
			//alert(menuId.innerHTML);
			menuId.innerHTML += menuArray[menuNum][I];//+"<br />";//Display current item
			//I++;
			/*Sets timeout between menu items appearing:
			**25 default
			**0 is instantaneous
			**-1 causes one item to appear per click*/
			//T = setTimeout("collapse("+menuNum+")", 0);
		}
		/*else 
		{*/
			menuFlag[menuNum] = 1;
			/*I = 1;
			clearTimeout(T);
		}*/
	}
	else
	{
		menuId.innerHTML = ""; //Reset menu
		menuFlag[menuNum] = 0;
	}
}


/***************************************************************************************
** Function: Image Table Setup
** Purpose: Creates data for a dynamic image table (used with menuCreate)
** Input: Id of the table, number of elements, location of images
***************************************************************************************/

function ImgTable(TblHead, PicNum, PicId, StartNum)
{
	var I;
	var TblStr = TblHead+",";
	var fName = PicId.split('.jpg');
	PicNum += StartNum;
	for(I=StartNum;I<PicNum;I++)
	{
		if(I<10) I='0'+I;
		if(!((I-StartNum)%8) && (I-StartNum)!=0) TblStr += "<br />";
		TblStr += "<a href='#disp'><img class='thmbNl' src='"+fName[0]+I+".jpg"+
				  "' onclick='SwitchDisplayImage( this.src )'></a>,";
	}
	TblStr += "</div><br /><br />";
	
	return TblStr;
}

function SwitchDisplayImage( imageSource )
{
	var imageContainer = document.getElementById( "disp" );
	
	imageContainer.innerHTML = "<img class='view' src='" + imageSource + "'/>";
}
