// Set dropdown menus to inactive - onload makes them active

	var menuSystemActive = false;

// Set the window name

	window.name = "main";

// onload triggers

	function homepageTrigger() {
		menuSystemActive = true;
	}
	
	function subpageTrigger() {
		menuSystemActive = true;
	}

// Flash embedding function

	function embedFlashMovie(getPath,getWidth,getHeight,getTransparency) {
		// embed flash movie
		flashString = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='" + getWidth + "' height='" + getHeight + "'>";
		flashString += "<param name='movie' value='" + getPath + "'><param name='quality' value='high'>";
		if(getTransparency) flashString += "<param name='wmode' value='transparent'>";
		flashString += "<embed src='" + getPath + "' ";
		if(getTransparency) flashString += "wmode='transparent' ";
		flashString += "quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + getWidth + "' height='" + getHeight + "'><\/embed>";
		flashString += "<\/object>";
		document.write(flashString);
	}

// Flash header balloon

	function doFlashBalloon() {
		//if (flash.ver[6]) {
			//embedFlashMovie(getPath,getWidth,getHeight,getTransparency)
			//document.write(embedFlashMovie("\/flash\/usborne_header_balloon.swf",83,98,true));
		//} else {
			// use ballon GIF instead
			document.write("<img src='\/images\/common\/non_flash_header_balloon.gif' alt='Usborne balloon' width='83' height='98'>");
		//}
	}

// printing function

	function printPage() {
	  if (window.print) window.print()
	  else
		alert("Sorry, your browser doesn't support this feature. Use your standard print menu instead.");
	}

// Menu Stuff

if(navigator.userAgent.indexOf("Opera")!=-1) GetBrowserType = "opera"
else if(navigator.appName == "Microsoft Internet Explorer") GetBrowserType = "ie"
else if(navigator.appName == "Netscape") GetBrowserType = "ns";

safariMode = false;
if(navigator.userAgent.indexOf("AppleWebKit")!=-1) safariMode = true;

GetBrowserPlatform = "";
if(navigator.userAgent.indexOf("Mac_PowerPC")!=-1 || navigator.userAgent.indexOf("Macintosh")!=-1) GetBrowserPlatform = "mac";

storeMenuIndex = null;
storeButtonState = null;
storeThisElement = null;
menuActive = false;
menuTimeout = null;

function getMenuClass(src,hoverState) {
	if(hoverState) return "MenuOver"
	else {
		if(storeButtonState) return "MenuOn"
		else return "MenuOff";
	}
}

function showMenu(menuIndex,buttonState,thisElement) {
	if(menuSystemActive) {
		cancelHideMenu();
		if(menuActive && menuIndex!= storeMenuIndex) doHideMenu();
		if(!menuActive) {
			storeMenuIndex = menuIndex;
			storeButtonState = buttonState;
			storeThisElement = thisElement;
			thisElement.className = getMenuClass(thisElement,true);
			
			if(SubMenuStrings[menuIndex]) {
				
				// Work out menu position
				SubMenuWidth = document.getElementById('DropDownMenu').offsetWidth;
				MenuOffset = document.getElementById('centeredPage').offsetLeft + document.getElementById('headerArea').offsetLeft + document.getElementById('menuArea').offsetLeft;
				MenuAreaWidth = document.getElementById('menuArea').offsetWidth;
				ButtonOffset = thisElement.offsetLeft;
				xPos = ButtonOffset + MenuOffset - 1;
				MenuAlign = "left";
				if((ButtonOffset + SubMenuWidth) > MenuAreaWidth) {
					// Work menu position aligned right to next spacer div
					ButtonOffset = thisElement.offsetLeft + thisElement.offsetWidth;
					xPos = (ButtonOffset + MenuOffset) - (SubMenuWidth - 1);
					MenuAlign = "right";
				}
			
				// Write menu links
				buildMenu = "<DIV align='" + MenuAlign + "'><DIV id='DropDownMenuTop'></DIV><dl>" + SubMenuStrings[menuIndex] + "</dl></DIV>";
				document.getElementById('DropDownMenu').innerHTML = buildMenu;
				
				// Set position of menu + make visible
				if(GetBrowserType == "ns" || GetBrowserType == "opera") {
					document.getElementById('DropDownMenu').style.left = xPos + "px";
				} else {
					document.getElementById('DropDownMenu').style.posLeft = xPos;
				}
				document.getElementById('DropDownMenu').style.zIndex = 100;
				document.getElementById('DropDownMenu').style.visibility = "visible";
			
			}
			menuActive = true;
		}
	}
}

function hideMenu() {
	if(menuSystemActive) {
		refreshMenu();
		menuTimeout = setTimeout("doHideMenu();",200);
	}
}

function doHideMenu() {
	if(menuSystemActive && storeThisElement != null) {
		storeThisElement.className = getMenuClass(storeThisElement,false);
		document.getElementById('DropDownMenu').style.visibility = "hidden";
		storeMenuIndex = null;
		storeButtonState = null;
		storeThisElement = null;
		menuActive = false;
	}
}

function cancelHideMenu() {
	if(menuSystemActive) {
		clearTimeout(menuTimeout);
		menuTimeout = null;
	}
}

function doNoLink() {
	if(menuSystemActive) {
		clearTimeout(menuTimeout);
	}
}

function refreshMenu() {
	if(menuSystemActive && safariMode) document.getElementById('DropDownMenu').style.zIndex += 1;
}

function checkImageSize(srcImage,maxWidth,maxHeight) {
	if(document.images) {
		getWidth = srcImage.width;
		getHeight = srcImage.height;
		if(getWidth>maxWidth || getHeight>maxHeight) {
			widthVariance = maxWidth/getWidth;
			heightVariance = maxHeight/getHeight;
			if(widthVariance<=heightVariance) scalePercentage = getWidth/maxWidth;
			else scalePercentage = getHeight/maxHeight;
			srcImage.width = getWidth/scalePercentage;
			srcImage.height = getHeight/scalePercentage;
		}
	}
}
