// begin variable definitions

// styles used:
// a.MenuOption - link in the menu dropdowns
// a.MenuOption:hover - link hover


// run the writeMenu() function to build the navigation.

var clearGif = "images/spacer.gif";

// sets initial states for menu dropdown. 
var items = new Array("none","none","none","none");

// this holds the xy position of each dropdown menu
// when using variable width menus, this array is used to calculate menu width

var positiony = new Array();
// new
positiony[0] = 96;
// 
positiony[1] = 114;
positiony[2] = 132;
positiony[3] = 150;
positiony[4] = 168;

var positionx = 128;

// sets dropdown menu width at 120px. - only used if menuwidth is not variable (see below)
var menuWidth = 150;
var NSmenuWidth = 140;

function doIt(){
openPopUpWindow('#');
}
// The menu items array defines all the menu options and their associated links, using one sub-array for each drop-down.
// The image rollovers are defined in a separate javascript (menuHeaders_x.js)
menuItems = new Array();
// new below
menuItems[0] = new Array;
menuItems[0][0] = new Array("overview_financial_01.html","Financial Highlights");
menuItems[0][1] = new Array("overview_chief_01.html","Chief Executive's Review");
menuItems[0][2] = new Array("overview_values_01.html","Values & Responsibilities");
//
menuItems[1] = new Array;
menuItems[1][0] = new Array("product_tv_01.html","Television");
menuItems[1][1] = new Array("product_channels_01.html","Channels");
menuItems[1][2] = new Array("product_mag_01.html","Magazines");
menuItems[1][3] = new Array("product_consumerpub_01.html","Consumer Publishing");
menuItems[1][4] = new Array("product_child_01.html","Children's");
menuItems[1][5] = new Array("product_newmedia_01.html","New Media & Internet");
menuItems[1][6] = new Array("product_learning_01.html","Learning");
menuItems[1][7] = new Array("product_music_01.html","Music");
// 
menuItems[2] = new Array;
menuItems[2][0] = new Array("world_factsfigures_01.html","Facts & Figures");
menuItems[2][1] = new Array("world_factfiles_01.html","Fact Files");
// 
menuItems[3] = new Array;
menuItems[3][0] = new Array("awards_industry_01.html","Industry");
menuItems[3][1] = new Array("awards_employee_01.html","Employee");
// 
menuItems[4] = new Array;
menuItems[4][0] = new Array("board_board_01.html","BBC Worldwide Board");
menuItems[4][1] = new Array("board_fairtrade_01.html","Fair Trading");


var timer;	// timeOut varibale
var hideBox;
var delayItemNo; // the reason for this and hideBox is that local variables don't work in a timeout call.
var isIE;
var isNS;

curBrowVer = String(navigator.appVersion);
curBrowVer = curBrowVer.substring( 0 , curBrowVer.indexOf( " " ));



if (document.all) {
	isIE=true;
	isNS=false;
} else {
	if ( curBrowVer.indexOf("4.") == -1 && curBrowVer.indexOf("3.") == -1 ) {
		isIE=true;
		isNS=false;
	
	} else {
		isIE=false;
		isNS=true;
	}
}


var optionColor_off = "#ADA7B4"; // un-highlited menu option
var optionColor_over = "#A29BAA"; // highlighted menu option
var borderColor = "#ffffff"; //border colour. 


// end variable definitions

function wln(str){
 document.writeln(str);
}

// drops the menu
function openIt(itemNo) {

if ( items[ itemNo ] != "disable" ) {
	items[itemNo] = "block";
	for (var i=0; i<items.length; i++){
		if ( items[ i ] != "disable" ) {
		if (isIE) {

			var newId = "item" + i + "box";
			var showBox = document.all(newId);
			window.clearTimeout(timer);
			showBox.style.display = items[i];
			}
		else {
			var layerName = "item"+i+"box";
			var showBox = document.layers[layerName];
			window.clearTimeout(timer);
			if (items[i] == "block") {showBox.visibility = "show";}
			else {showBox.visibility = "hide";}
			}
		   }
		}
	}
}
// closes the menu. It sets a timeout on this action so if another part of the menu is rolled over it stays open.
function closeIt(itemNo) {
if ( items[ itemNo ] != "disable" ) {
	items[itemNo] = "none";
	if (isIE) {
		var newId = "item" + itemNo + "box";
		hideBox = document.all(newId);
		delayItemNo = itemNo;
		timer = window.setTimeout('hideBox.style.display = "none";',150);

		}
	else {
		var layerName = "item"+itemNo+"box";
		hideBox = document.layers[layerName];
		delayItemNo = itemNo;
		timer = window.setTimeout('hideBox.visibility = "hide";',150);
		}
	} 

}

function highlight(objectName,on){
if (on) { objectName.bgColor = optionColor_over;}
else { objectName.bgColor = optionColor_off;}
}


// this function writes the entire menu, including header graphics, dropdowns and menu items.
function writeMenu(){
var title;
var offset;
// new it was 4
for (var itemNo=0; itemNo < menuItems.length; itemNo++){
	// if you want variable menu width (fills space between menu headers), turn on the following line.
	// menuWidth = positionx[itemNo+1] - positionx[itemNo];

	// Netscape version uses layers only
	if (isNS) {
		wln('<layer name="item' + itemNo + 'box" width="' + (NSmenuWidth) + '" height="1" top="' + positiony[itemNo] + '" left="'+positionx+'" onMouseover="openIt('+itemNo+')" onMouseout="closeIt('+itemNo+')" visibility="hidden">');
		offset = 0;
		for (var i=0; i<menuItems[itemNo].length; i++){
			// opHeight sets the height of each menu option.
			// this should correspond to the font size.
			// where the menu option wraps to the next line, the opHeight is increased (see if statement, below).
			if (menuItems[itemNo][i][1].length+2 > 28) {opHeight = 20;} 
			else {opHeight=18;}
			wln('<layer name="menu'+itemNo+'option'+i+'" left="" top="'+((i*(opHeight+1))+offset)+'" bgcolor="' + optionColor_off + '" width="' + NSmenuWidth + '" height="'+opHeight+'" onMouseover="highlight(this,true)" onMouseout="highlight(this,false)">');
			wln('<table cellpadding="0" cellspacing="0" border="0">');
			wln('<tr><td colspan="4" bgcolor="'+borderColor+'"><img src="'+clearGif+'" width="' + NSmenuWidth + '" height="1" /></td></tr>');
			wln('<tr><td rowspan="2" bgcolor="'+borderColor+'"><img src="'+clearGif+'" width="1" height="'+opHeight+'" /></td>');
			wln('<td valign="top" height="1"><img src="'+clearGif+'" width="5" height="1" /></td>');
			wln('<td valign="top" height="1"><img src="'+clearGif+'" width="' + (NSmenuWidth-7) + '" height="1" /></td>');
			wln('<td rowspan="2" bgcolor="'+borderColor+'"><img src="'+clearGif+'" width="1" height="'+opHeight+'" /></td></tr>');
			wln('<tr><td></td><td valign="middle"><a href="' + menuItems[itemNo][i][0] + '" target="_top" class="MenuOption">' + menuItems[itemNo][i][1] + '</a></td></tr>');
			if (i == (menuItems[itemNo].length -1)) {
				wln('<tr><td colspan="4" bgcolor="'+borderColor+'"><img src="'+clearGif+'" width="' + NSmenuWidth + '" height="1" /></td></tr>');
			}
			wln('</table>');
			wln('</layer>');
			if (menuItems[itemNo][i][1].length+2 > 28) offset = offset + 10;
		}
		wln('</layer>');
		}	

	
		// IE version uses absolutely poisitioned divs and tables
	else {
		wln('<table cellspacing="0" border="0" cellpadding="0" id="item' + itemNo + 'box" style="display:none; filter:alpha(Opacity=85, style=0); position:absolute; top:'+ positiony[itemNo] +'px; left:'+positionx+'px; width:' + menuWidth + 'px; height:18px" onMouseover="openIt(' + itemNo + ')" onMouseout="closeIt(' + itemNo + ')">');
		for (var i=0; i<menuItems[itemNo].length; i++){
			// border
			wln('<tr><td bgcolor="' + borderColor + '" rowspan="2"><img src="'+clearGif+'" width="1" height="1" /></td><td bgcolor="' + borderColor + '"><img src="'+clearGif+'" width="' + (menuWidth-2) + '" height="1" /></td><td bgcolor="' + borderColor + '" rowspan="2"><img src="'+clearGif+'" width="1" height="1" /></td></tr>');
			// active cell
			wln('<tr><td id="menu'+itemNo+'option'+i+'" name="menu'+itemNo+'option'+i+'" align="left" bgcolor="'+optionColor_off+'" onMouseover="highlight(this,true)" onMouseout="highlight(this,false)">');
			wln('<table cellpadding="0" cellspacing="0" border="0"><tr>');
			//arrow
			wln('<td width="10"><img src="images/spacer.gif" width="5" height="18" /></td>');
			//menu item
			wln('<td onclick="document.location.href=\''+menuItems[itemNo][i][0]+'\';" width="100%"><a href="' + menuItems[itemNo][i][0] + '" target="_top" class="MenuOption">' + menuItems[itemNo][i][1] + '</a></td></tr></table>');
			wln('</td></tr>');
		}
		wln('<tr><td colspan="3" bgcolor="' + borderColor + '"><img src="'+clearGif+'" width="' + (menuWidth-2) + '" height="1" /></td></tr>');
		wln('</table>');
		}
	}
}


