
var _debug = false;


/* Preload the button down images */
function doPreload()
{
	// Put all the images to be preloaded in this array
	var the_images = new Array(
		'images/ThisYearDn.gif',
		'images/PreviousYearsDn.gif',
		'images/PerformanceInfoDn.gif',
		'images/BookingDn.gif',
		'images/ShakespeareDn.gif',
		'images/TheCompanyDn.gif',
		'images/ReviewsDn.gif',
		'images/GalleryDn.gif',
		'images/guestDn.gif',
		'images/WebringDn_Prev.gif',
		'images/WebringDn_Home.gif',
		'images/WebringDn_Next.gif',
		'images/WebringDn_Rand.gif');
	preloadImages(the_images);
}

/* Perform the actual image loading */
function preloadImages(the_images_array) 
{
	var alen = the_images_array.length;
	for(var lp = 0; lp < alen; lp++)
	{
	 	var an_image = new Image();
		an_image.src = the_images_array[lp];
	}
}

/* Function to write all the main menu buttons */
function writeMainMenu(currPage)
{
	var button_data = new Array(
	// Data for all the buttons
	// Image prefix			h ref						Status text
		"Home", 					"index", 				"Home",
		"ThisYear", 			"thisyear", 			"This year\\'s production",
		"PreviousYears", 		"previousyears", 		"Previous productions",
		"PerformanceInfo", 	"performanceinfo", 	"Location, times, facilities and tips",
		"Booking", 				"booking", 				"Booking information",
		"Shakespeare", 		"shakespeare", 		"About Shakespeare",
		"TheCompany", 			"thecompany", 			"About Shakespeare Live",
		"Reviews", 				"reviews", 				"Reviews and Comments",
		"Gallery",				"gallery",				"Gallery of Photographs",
	    "Guest",            "gbook1",                "Guest Book");
	// -- Logo Line
   if (currPage != "Home")
   {
   	tracewrite('<tr>');
   	tracewrite('<td>');
   	tracewrite('<img src="images/Logo150gp.gif" width="150" height="86" alt="">');
   	tracewrite('</td>');
   	tracewrite('</tr>');
   }

	// Do the buttons
	var alen = button_data.length;
	var txt = "";
	for(var lp = 0; lp < alen; lp += 3)
	{
		txt += menuButtonString(currPage==button_data[lp], button_data[lp], button_data[lp+1], button_data[lp+2]);
	}
	tracewrite(txt);
}

/* Function to write a single menu button */
function menuButtonString(thisPage, page, ref, statusText)
{
	var s = '<tr class="button">\n<td class="button">\n';
	if (thisPage)
	{
		s += '<img src="images/' + page + 'Gr.gif">';
	}
	else
	{
		s += '<a href="' + ref + '.html" \n';
		
		s += 'onMouseOver="setButton(' + "'" + page + "Button','" + page 
			+ "Dn.gif','" + statusText + "');return true;" + '"\n';
		s += 'onMouseOut="setButton(' + "'" + page + "Button','" + page 
			+ "Up.gif','');return true;" + '">\n';
		s += '<img src="images/' + page + 'Up.gif" name="' + page + 'Button" border="0">';
		s += '</a>';
	}
	s += '</td>\n</tr>\n';
	return s;
}

/* Simple fn to reduce inline code for rollover */
function setButton(button, pic, text)
{
	var button_obj = eval("document."+button);
	button_obj.src="images/"+pic;
	window.status=text;
}

/* Function to add extra menu elements
 * It takes an array defining the types and parameters of each menu element.
 * The types may be:
 * 0				1				2				3				4					5					6				7
 * Separator
 * Comment		text
 * Link			page			text			ref			statustext	subnote/null	external(t/f)	highlight(t/f)
 */

function addMenuItems(itemList, currPage)
{
	var alen = itemList.length;
	var i = 0;
	var txt = "";
	while (i < alen)
	{
		switch (itemList[i])
		{
		case 'Seperator':
			txt += '<tr>\n<td>\n<hr align="center" width="70%">\n</td>\n</tr>\n';
			i++;
			break;

		case 'Comment':
			txt += '<tr>\n<td>\n<span class="asubnote">' + itemList[i+1] + '</span>\n</td>\n</tr>\n';
			i += 2;
			break;

		case 'Link':
   		txt += '<tr class="button">\n<td class="menulink">\n';

			// Check if current page
			var page = itemList[i+1];
			// Equal page or regexp test it
			if ((page == currPage) || (typeof page != "string" && page.test(currPage)))
			{
				// Grey link
				txt += '<p class="greylink">\n' + itemList[i+2] + '</p>\n';
			}
			else
			{
   			// Check Highlight
   			if (itemList[i+7])
				{
   				txt += '<a class="menuhigh" href="' + itemList[i+3] + '" ';
				}
   			else
				{
   				txt += '<a href="' + itemList[i+3] + '" ';
				}
   			txt += 'style="padding-left: 20px;"';
   			// Check external
   			if (itemList[i+6])
				{
   				txt += ' target="_blank" ';
				}
   			txt += 'onMouseOver="window.status=' + "'" + itemList[i+4] + "';return true;" +'"';
   			txt += 'onMouseOut="window.status=' + "''" + ';return true;">';
   			txt += itemList[i+2] + '<br>';
   			if (itemList[i+5] != null)
				{
   				txt += '<span class="asubnote">' + itemList[i+5] + '</span>';
				}
   			txt += '</a>\n';
			}
   		txt += '</td>\n</tr>\n';
   		i += 8;
			break;

		default:
			i++;
			break;
		}
	}
	tracewrite(txt);
}

function debug(msg)
{
	if ((!debug.console) || (debug.console.closed))
	{
		debug.console = window.open("","console","width=600,height=300,resizable,scrollbars");
		debug.console.document.open("text/plain");
	}
	debug.console.focus();
	debug.console.document.write(msg);
}

function tracewrite(msg)
{
	document.write(msg);

	if (_debug)
	{
		debug(msg);
	}
}

function tracewriteln(msg)
{
	document.writeln(msg);

	if (_debug)
	{
		debug(msg);
		debug("\n");
	}
}
