﻿/**************************************************
 Javascript Code to create the top menu on the fly
****************************************************/
var MenuArray = new Array();
var ChapterArray  = new Array();
var WhichButton = 0;
MenuArray[0] = new RadioButton("http://www.azdivudc.org/index.html", "News");
MenuArray[1] = new RadioButton("http://www.azdivudc.org/division/aboutus.html", "About Us");
MenuArray[2] = new RadioButton("http://www.azdivudc.org/division/membership.html", "Membership");
MenuArray[3] = new RadioButton("http://www.azdivudc.org/division/schedule.html", "Schedule");
MenuArray[4] = new RadioButton("http://www.azdivudc.org/division/photos.html", "Event Photos");
MenuArray[5] = new RadioButton("http://www.azdivudc.org/division/contacts.html", "Contacts");
MenuArray[6] = new RadioButton("http://www.azdivudc.org/division/scholarships.html", "Scholarships");
MenuArray[7] = new RadioButton("http://www.hqudc.org/", "General Site");
MenuArray[8] = new RadioButton("http://www.azdivudc.org/division/legal.html", "Legal");
MenuArray[9] = new RadioButton("http://www.azdivudc.org/division/AnnualConvention.html", "Annual Convention");

ChapterArray[0] = new RadioButton("http://www.azdivudc.org/chapters/ArizonaCavalry/index.html", "Arizona Cavalry 2683");
ChapterArray[1] = new RadioButton("http://www.azdivudc.org/chapters/Dixie/index.html", "Dixie 1679");
ChapterArray[2] = new RadioButton("http://www.azdivudc.org/chapters/JohnRBaylor/index.html", "John R. Baylor 2298");
ChapterArray[3] = new RadioButton("http://www.azdivudc.org/chapters/JohnnyReb/index.html", "Johnny Reb 2674");
ChapterArray[4] = new RadioButton("http://www.azdivudc.org/chapters/Thunderbird/index.html", "Thunderbird 2102");
// ChapterArray[4] = new RadioButton("http://www.azdivudc.org/chapters/PicachoPass/index.html", "Picacho Pass");

// Constructor for the Object to hold the button link and button text
function RadioButton(ButtonLink, ButtonLabel)
{
	this.buttonlink = ButtonLink;
	this.buttonlabel = ButtonLabel;
}

// Code to figure out which page we are loading, so we know which button should be visually "pressed"
function CurrentButtonNumber()
{
	WhichButton = -1;
	
	// the location pathname contains a relative path from the root of 
	// our directory structure, so make it a complete "Link" for testing
	PagePath = "http://www.azdivudc.org" + location.pathname;
	
	// Check this page's complete link against the complete links stored in the buttons
	for(i=0; i<MenuArray.length; i++)
	{
		// check the top menu button links first...
		if(MenuArray[i].buttonlink == PagePath)
		{
			// we found it, so set the button number
			WhichButton = i;
		} // end if
		
	} // end for
	
	
	// now check the Chapter buttons
	for(i=0; i<ChapterArray.length; i++)
	{
		// checking the Chapter button links
		if(ChapterArray[i].buttonlink == PagePath)
		{
			// we found it so set the button number 
			// (we're in the second set of buttons, so skip the first set by adding them)
			WhichButton = i + MenuArray.length;
		} // end if
		
	} // end for loop
	
	if(WhichButton == -1) WhichButton = 0; // Default to News (first button)
	
	// pass the button number back to the program
	return WhichButton;
}

// WARNING - changing this code might result in invalid HTML code being generated
// BE CAREFUL!!

// Build the HTML code to display the Top picture and the Menu Buttons
function CreateHeaderText()
{
	ButtonText = new String();

	WhichButton = CurrentButtonNumber();

	// First add in the <DIV> markers to properly format this section with CSS
	ButtonText = 
	'<div id="header">' +
	'	<div id="side-menus">' +
	'		<div id="main-menu">' +
	'<img src="http://www.azdivudc.org/images/NewDivLogo.gif"  width="120" />' +
	'				<h1>Menu</h1>' +
	'				<div class="menubuttons">';
	
	// Now build each of the MENU buttons
	for(i=0; i<MenuArray.length; i++)
	{
		// Build the first half of the LINK for the button
		ButtonText = ButtonText + 
			'<a href="' + MenuArray[i].buttonlink + '"';
			
		// Did we find a button that should look pressed?
		if(WhichButton != -1)
		{
			// Is THIS button the one that should look "Pressed?"
			if(WhichButton == i)
			{
				// add the code which makes it look pressed
				ButtonText = ButtonText + 
					'class="pressed"';
			} // end if
			
		} // end if
		
		// build the LABEL for the button
		ButtonText = ButtonText + 
			'>' + MenuArray[i].buttonlabel + '</a> ';
	} // end for		

	// Add in the DIV markers to mark the end of the Menu buttons
	// and the start of the Chapter buttons
	ButtonText = ButtonText + 
	'				</div>' +
	'		</div>' +
	'		<div id="chapter-menu">' +
	'				<h1>Chapter<br />Links</h1>' +
	'				<div class="menubuttons">';
	
	// Now build each of the Chapter buttons
	for(i=0; i<ChapterArray.length; i++)
	{
		// Build the first half of the LINK for the button
		ButtonText = ButtonText + 
			'<a href="' + ChapterArray[i].buttonlink + '" ';

		// Did we find a button that should look pressed?
		if(WhichButton != -1)
		{
			// Is THIS button the one that should look "Pressed?"
			if((WhichButton - MenuArray.length) == i)
			{
				// add the code which makes it look pressed
				ButtonText = ButtonText + 
					'class="pressed"';
			} // end if
			
		} // end if
		
		// build the LABEL for the button
		ButtonText = ButtonText + 
			'>' + ChapterArray[i].buttonlabel + '</a> ';
			
	} // end for		

	// Now add in the closing </DIV> markers to end the menus
	ButtonText = ButtonText + 
	'				</div>' +
	'		</div>' +
	'	</div>' +
	'</div>';
	
	// pass this fully-constructed set of HTML code back to the program
	return ButtonText;
}
 
// Create a new empty HTML section to insert at the top of the BODY
var PageHeader = document.createElement("div");

// Generate the HTML code to insert into that empty section
PageHeader.innerHTML = CreateHeaderText();

// Insert this new code-filled section into the actual web page
document.body.insertBefore(PageHeader, document.body.firstChild);