var mac = (navigator.userAgent.indexOf("Mac") > 0) ? 1 : 0;

var ns4up = (document.layers) ? 1 : 0;

var ie4up = (document.all) ? 1 : 0;

var dom = (document.getElementById&&!document.all) ? 1 : 0;



var lefts = new Array();

var widths = new Array();



function closeLayer()	{

	if (ns4up) {

		document.write('</LAYER>\n');

	} else {

		document.write('</DIV>\n');

	}

}



function initNavigation()	{



	var padding = 7; // total letter padding in a button e.g. 5 = 2.5 each side

	var docContent = "";

	var letterCount = 0;

	var widthTotal = 0;

	

	for (i=0; i<navItems.length; i++)

	{

		letterCount+= navItems[i].length + padding;

	}

	

	for (i=0; i<navItems.length; i++)

	{

		thisWidth = ((navItems[i].length + padding) / letterCount) * Global_Max_Width;

		thisWidth = Math.floor(thisWidth);

		if(i == (navItems.length-1))

		{

			thisWidth = (Global_Max_Width - widthTotal);

		}

		widths[i] = thisWidth;

		lefts[i] = widthTotal;

		widthTotal += thisWidth;

		

		var thisName = navNames[i] + "tab";

		var thisNav = navNames[i];

		if (ns4up) {

			toWrite = '<LAYER NAME="' + thisNav + '" LEFT="' + lefts[i] + '" TOP="' + TopNavigationGlobalTop + '" VISIBILITY="SHOW" Z-INDEX="10">\n';

		} else {

			toWrite = '<DIV ID="' + thisNav + '" STYLE="position:absolute;left:' + lefts[i] + 'px; top:' + TopNavigationGlobalTop + 'px;z-index:10;visibility:visible;">\n';

		}

		toWrite += '<TABLE WIDTH="' + thisWidth + '" CELLPADDING="0" CELLSPACING="0" BORDER="0" BGCOLOR="' + TopNavButtonBG + '" HEIGHT="' + navHeight + '" ID="TopNavButtonBG0' + thisNav + '">\n';

		toWrite += '<TR>\n';

		toWrite += '<TD BGCOLOR="' + TopNavButtonTop + '" WIDTH="1" COLSPAN="3" ID="TopNavButtonTop0' + thisNav + '"><IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>\n';

		toWrite += '</TR>\n';

		toWrite += '<TR>\n';

		toWrite += '<TD BGCOLOR="' + TopNavButtonHighlight1 + '" WIDTH="1" COLSPAN="2" ID="TopNavHighlight10' + thisNav + '"><IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>\n';

		toWrite += '<TD BGCOLOR="' + TopNavButtonBG + '" WIDTH="1"><IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0" ID="TopNavButtonBG1' + thisNav + '"></TD>\n';

		toWrite += '</TR>\n';

		toWrite += '<TR>\n';

		toWrite += '<TD BGCOLOR="' + TopNavButtonHighlight2 + '" HEIGHT="' + (navHeight-3) + '" ID="TopNavHighlight20' + thisNav + '"><IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" WIDTH="1" HEIGHT="' + (navHeight-3) + '" BORDER="0"></TD>\n';

		toWrite += '<TD WIDTH="' + thisWidth + '" BGCOLOR="' + TopNavButtonBG + '" VALIGN="middle" ALIGN="center" HEIGHT="' + (navHeight-3) + '" ID="TopNavButtonBG2' + thisNav + '" class="buttonLink">' + navItems[i] + '</TD>\n';

		toWrite += '<TD BGCOLOR="' + TopNavButtonDimlight + '" HEIGHT="' + (navHeight-3) + '" ID="TopNavDimlight0' + thisNav + '"><IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>\n';

		toWrite += '</TR>\n';

		toWrite += '<TR>\n';

		toWrite += '<TD BGCOLOR="' + TopNavButtonBG + '" WIDTH="1" ID="TopNavButtonBG3' + thisNav + '"><IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>\n';

		toWrite += '<TD BGCOLOR="' + TopNavButtonDimlight + '" WIDTH="1" COLSPAN="2" ID="TopNavDimlight1' + thisNav + '"><IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>\n';

		toWrite += '</TR>\n';

		toWrite += '</TABLE>\n';

		document.write(toWrite);

		closeLayer();

	}

}

function navBarActivate()	{

	if (ns4up) {

		document.write('<LAYER NAME="topClear" LEFT="' + lefts[0] + '" TOP="' + TopNavigationGlobalTop + '" VISIBILITY="SHOW" Z-INDEX="11">\n');

document.write('<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD NOWRAP>\n');

	} else {

		document.write('<DIV ID="topClear" STYLE="position:absolute;left:' + lefts[0] + 'px; top:' + TopNavigationGlobalTop + 'px;z-index:11;visibility:visible;">\n');

document.write('<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD NOWRAP>\n');

	}

	for (i=0; i<navItems.length; i++)

	{

		var thisNav = navNames[i];

		if(menu[i].length > 0) document.write('<A HREF="' + topLevelLinks[i] + '" ONMOUSEOVER="layerOn(\'' + i + '\');topNavOn(true,\'' + thisNav + '\');" ONMOUSEOUT="slowLayerOff(\'' + i + '\');topNavOn(false,\'' + thisNav + '\');">');

		else document.write('<A HREF="' + topLevelLinks[i] + '" ONMOUSEOVER="topNavOn(true,\'' + thisNav + '\');" ONMOUSEOUT="topNavOn(false,\'' + thisNav + '\');">');

		document.write('<IMG SRC="http://www.britishcouncil.fi/images/spacer.gif" BORDER="0" WIDTH="' + widths[i] + '" HEIGHT="' + navHeight + '"></A>');

	}

	document.write('</TD></TR></TABLE>\n');

	closeLayer()

}



function topNavOn(on,nav) {

	if (ie4up)

	{

		document.all["TopNavButtonBG0" + nav].style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;

		document.all["TopNavButtonBG1" + nav].style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;

		document.all["TopNavButtonBG2" + nav].style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;

		document.all["TopNavButtonBG3" + nav].style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;

		document.all["TopNavButtonTop0" + nav].style.backgroundColor = (on) ? TopNavButtonOverTop : TopNavButtonTop;

		document.all["TopNavHighlight10" + nav].style.backgroundColor = (on) ? TopNavButtonOverHighlight1 : TopNavButtonHighlight1;

		document.all["TopNavHighlight20" + nav].style.backgroundColor = (on) ? TopNavButtonOverHighlight2 : TopNavButtonHighlight2;

		document.all["TopNavDimlight0" + nav].style.backgroundColor = (on) ? TopNavButtonOverDimlight : TopNavButtonDimlight;

		document.all["TopNavDimlight1" + nav].style.backgroundColor = (on) ? TopNavButtonOverDimlight : TopNavButtonDimlight;

	}

	else if(dom)

	{

		document.getElementById("TopNavButtonBG0" + nav).style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;;

		document.getElementById("TopNavButtonBG1" + nav).style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;;

		document.getElementById("TopNavButtonBG2" + nav).style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;;

		document.getElementById("TopNavButtonBG3" + nav).style.backgroundColor = (on) ? TopNavButtonOverBG : TopNavButtonBG;

		document.getElementById("TopNavButtonTop0" + nav).style.backgroundColor = (on) ? TopNavButtonOverTop : TopNavButtonTop;

		document.getElementById("TopNavHighlight10" + nav).style.backgroundColor = (on) ? TopNavButtonOverHighlight1 : TopNavButtonHighlight1;

		document.getElementById("TopNavHighlight20" + nav).style.backgroundColor = (on) ? TopNavButtonOverHighlight2 : TopNavButtonHighlight2;

		document.getElementById("TopNavDimlight0" + nav).style.backgroundColor = (on) ? TopNavButtonOverDimlight : TopNavButtonDimlight;

		document.getElementById("TopNavDimlight1" + nav).style.backgroundColor = (on) ? TopNavButtonOverDimlight : TopNavButtonDimlight;

	}

}

