// Loads the main menu in every page

var ref_values    = new Array( 'index.html',       'tribute.htm',        'coaches.htm',        'college.html', 'schedule.htm',        'results.html',           'vjv.htm',        'State Placers and Champs.htm', 'halloffame.htm',        'links.htm',       'news.htm',        'contacts.htm',       'search.htm',        'pictures.htm',      'teamrecords.htm',        'archives.htm',        ''                 );
var src_values    = new Array( 'webjpg/home.jpg',  'webjpg/tribute.jpg', 'webjpg/coaches.jpg', 'link25.jpg',   'webjpg/schedule.jpg', 'webjpg/0304results.jpg', 'webjpg/vjv.jpg', 'webjpg/statemedalists.jpg',    'webjpg/halloffame.jpg', 'webjpg/link.jpg', 'webjpg/news.jpg', 'webjpg/contact.jpg', 'webjpg/search.jpg', 'webjpg/photos.jpg', 'webjpg/teamrecords.jpg', 'webjpg/archives.jpg', 'webjpg/back2.jpg' );
var width_values  = new Array( '200',              '200',                '200',                '200',          '200',                 '200',                    '200',            '200',                          '200',                   '200',             '200',             '200',                '200',               '200',               '200',                    '200',                 '203'              );
var height_values = new Array( '20',               '20' ,                '20',                 '20',           '20',                  '20',                     '20',             '20',                           '23',                    '20',              '20',              '20' ,                '20',                '21',                '20',                     '20',                  '114'              );
var border_values = new Array( '0',                '0',                  '0',                  '0',            '0',                   '0',                      '0',              '0',                            '0',                     '0',               '0',               '0',                  '0',                 '0',                 '0',                      '0',                   '0'                );

function loadMainMenuDiv( main_menu, root_path )
{
    var menu_table;
	var menu_table_body;
	var new_row;
	var new_col;
	var new_anchor;
	var new_image;

	if( !root_path || root_path.length == 0 ) 
    {
		root_path = ".";
	}

	//alert("root_path = " + root_path );
	
	// create a table for the menu
	menu_table = document.createElement('table');
	menu_table.setAttribute( 'border', '0' );
	menu_table.setAttribute( 'width', '100%' );
	menu_table.setAttribute( 'cellspacing', '0' );
	menu_table.setAttribute( 'cellpadding', '0' );
	menu_table.setAttribute( 'height', '251' );

	menu_table_body = document.createElement('tbody');
	
	var idx = 0;
	var ref_value = '';
	var src_value = '';
	var width_value = '';
	var height_value = '';
	var border_value = '';
	do 
    {
		// read in next set of atributes
		ref_value = ref_values[idx];
		src_value = src_values[idx];
		width_value = width_values[idx];
		height_value = height_values[idx];
		border_value = border_values[idx];

		// create a new row
		new_row = document.createElement('tr');

		// add a single column
		new_col = document.createElement('td');

		// add the ref to the page
		if( ref_value.length ) 
	    {
			ref_value = root_path + '/' + ref_value;
			new_anchor = document.createElement('a');
			new_anchor.setAttribute( 'href', ref_value );

			// add an image
			src_value = root_path + '/' + src_value;
			new_image = document.createElement('img');
			new_image.setAttribute( 'alt', '' );
			new_image.setAttribute( 'src', src_value );
			new_image.setAttribute( 'width', width_value );
			new_image.setAttribute( 'height', height_value );
			new_image.setAttribute( 'border', border_value );
			new_anchor.appendChild( new_image );
			new_col.appendChild( new_anchor );
		}
		else
		{
			// last row add an image only
			src_value = root_path + '/' + src_value;
			new_image = document.createElement('img');
			new_image.setAttribute( 'alt', '' );
			new_image.setAttribute( 'src', src_value );
			new_image.setAttribute( 'width', width_value );
			new_image.setAttribute( 'height', height_value );
			new_image.setAttribute( 'border', border_value );
			new_col.appendChild( new_image );
		}
		new_row.appendChild( new_col );
		menu_table_body.appendChild( new_row );

		idx++;

	}while( ref_value.length );
	
	menu_table.appendChild( menu_table_body );
	main_menu.appendChild( menu_table );
}

function loadMainMenuTable( menu_table, root_path )
{
	var new_row;
	var new_col;
	var new_anchor;
	var new_image;

	if( !root_path || root_path.length == 0 ) 
    {
		root_path = ".";
	}

	//alert("root_path = " + root_path );

	var idx = 1;
	var ref_value = '';
	var src_value = '';
	var width_value = '';
	var height_value = '';
	var border_value = '';
	do 
    {
		// read in next set of atributes
		ref_value = ref_values[idx];
		src_value = src_values[idx];
		width_value = width_values[idx];
		height_value = height_values[idx];
		border_value = border_values[idx];

		// create a new row
		new_row = document.createElement('tr');

		// add a single column
		new_col = document.createElement('td');

		// add the ref to the page
		if( ref_value.length ) 
	    {
			ref_value = root_path + '/' + ref_value;
			new_anchor = document.createElement('a');
			new_anchor.setAttribute( 'href', ref_value );

			// add an image
			src_value = root_path + '/' + src_value;
			new_image = document.createElement('img');
			new_image.setAttribute( 'alt', '' );
			new_image.setAttribute( 'src', src_value );
			new_image.setAttribute( 'width', width_value );
			new_image.setAttribute( 'height', height_value );
			new_image.setAttribute( 'border', border_value );
			new_anchor.appendChild( new_image );
			new_col.appendChild( new_anchor );
		}
		else
		{
			// last row add an image only
			src_value = root_path + '/' + src_value;
			new_image = document.createElement('img');
			new_image.setAttribute( 'alt', '' );
			new_image.setAttribute( 'src', src_value );
			new_image.setAttribute( 'width', width_value );
			new_image.setAttribute( 'height', height_value );
			new_image.setAttribute( 'border', border_value );
			new_col.appendChild( new_image );
		}
		new_row.appendChild( new_col );
		menu_table.appendChild( new_row );

		idx++;

	}while( ref_value.length );
}

function loadMainMenu( root_path ){ 
	var main_menu_table = document.getElementById("main_menu_table");
	
	if( main_menu_table )
	{
     	//alert("found main menu table!");
		loadMainMenuTable( main_menu_table, root_path );
	}
	else
	{
		var main_menu = document.getElementById("main_menu");
		if( main_menu )
		{
			//alert("found main menu!");
			loadMainMenuDiv( main_menu, root_path );
	
		}
		else
		{
			//alert("did not find main menu!");
		}
	}
	
}

