// 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 positionx = new Array();
// new
positionx[0] = 4;
// 
positionx[1] = 132;
positionx[2] = 516;

var positiony = 120;

// sets dropdown menu width at 120px. - only used if menuwidth is not variable (see below)
var menuWidth = 127;
var NSmenuWidth = 127;

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("financial_high_1.htm","Financial Highlights");
menuItems[0][1] = new Array("Cexect_review.htm","Chief Executive's Review");
menuItems[0][2] = new Array("strategy.htm","Strategy");
menuItems[0][3] = new Array("worldwide_contrib_bbc_1.htm","BBC Worldwide's Contribution");
//
menuItems[1] = new Array;
menuItems[1][0] = new Array("tele1.htm","Television");
menuItems[1][1] = new Array("cha1.htm","Channels");
menuItems[1][2] = new Array("magazines_1.htm","Magazines");
menuItems[1][3] = new Array("conpub_1.htm","Consumer Publishing");
menuItems[1][4] = new Array("child1.htm","Children's");
menuItems[1][5] = new Array("dig_intermedia_1.htm","Digital & Interactive Media");
menuItems[1][6] = new Array("learn_1.htm","Learning");
menuItems[1][7] = new Array("music.htm","Music");
// 
menuItems[2] = new Array;
menuItems[2][0] = new Array("worldwide_board.htm","BBC Worldwide Board");
menuItems[2][1] = new Array("fair_trading.htm","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 = "#AABFDA"; // un-highlited menu option
var optionColor_over = "#8CA6C9"; // highlighted menu option
var borderColor = "images/spacer.gif"; //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+ '" left="'+positionx[itemNo] +'" 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"><img src="'+clearGif+'" width="' + NSmenuWidth + '" height="1" /></td></tr>');
			wln('<tr><td rowspan="2"><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"><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"><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=95, style=0); position:absolute; top:'+ positiony+'px; left:'+positionx[itemNo] +'px; width:' + menuWidth + 'px; height:24px" onMouseover="openIt(' + itemNo + ')" onMouseout="closeIt(' + itemNo + ')">');
		for (var i=0; i<menuItems[itemNo].length; i++){
			// border
			wln('<tr><td rowspan="2"><img src="'+clearGif+'" width="1" height="1" /></td><td><img src="'+clearGif+'" width="' + (menuWidth-2) + '" height="1" /></td><td 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="'+clearGif+'" width="5" height="20" /></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"><img src="'+clearGif+'" width="' + (menuWidth-2) + '" height="1" /></td></tr>');
		wln('</table>');
		}
	}
}



