/* functions for showing/hiding dropdown menus */
var hideTimeout = null;
var menu = null;
var dropdown = function() {
	if (navigator.appName=="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0) {
		var topMenu = document.getElementById("menu");
		if (topMenu) {
			var uls = topMenu.getElementsByTagName("ul");
			for (var i = 1; i < uls.length; i++) {
				uls[i].parentNode.onmouseover = function() {
					this.lastChild.style.display = "block";
					this.firstChild.className = "act";
				}
				uls[i].onmouseover=function() {
					if (hideTimeout) window.clearTimeout(hideTimeout);
					this.parentNode.firstChild.className = "act";
				}
				uls[i].parentNode.onmouseout=function() {
					menu = this;
					hideTimeout = window.setTimeout(function() {
						menu.lastChild.style.display = "none";
						menu.firstChild.className = "";
					}, 300);
				}
			}
		}
	}
}
window.onload = dropdown;

/* functions for showing/hiding tabbed content */
function showSheet(selectedSheetNo) {
	var sheetNo = 1;
	var tab = document.getElementById("div_tab" + sheetNo);
	var sheet = document.getElementById("div_sheet" + sheetNo);
	while (tab || sheet) {
		if (sheetNo == selectedSheetNo) {
			if (tab) tab.className = "active tab";
			if (sheet) sheet.className = "sheet";
		} else {
			if (tab) tab.className = "tab";
			if (sheet) sheet.className = "hidden sheet";
		}
		sheetNo++;
		tab = document.getElementById("div_tab" + sheetNo);
		sheet = document.getElementById("div_sheet" + sheetNo);
	}
}

/* functions for showing/hiding movies */
var movieDefaultWidth = 0;
var movieDefaultHeight = 0;

function showVideo1(page, customWidth, customHeight) {
	
	// This function works with 3 page elements:
	//   - "overlay" fills the screen with a semi-transparent colour to illustrate that the page cannot be used while the movie is visible.
	//   - "player" is a rectangle, horizontally and vertically centered within (and on top of) "overlay", consisting of a title bar and the movie itself.
	//   - "movie" is an iframe in which a page containing the movie is loaded. Using an iframe means we can load and unload any movie we like, just
	//     by changing the "src" attribute, rather than worrying about controlling an ActiveX object using Javascript.
	// Note that the descriptions above are not enforced by this function, this is how they need to be set up in the HTML and stylesheet.
	// At present, this function does not test that the 3 elements actually exist, so if they don't you'll get a runtime error.
	
	// This function can be called multiple times in one page, for movies of any size. If size is not specified then the default is applied, this default
	// being taken from the size of "movie" when the page first loaded. Thus it's recommended to set the default with a CSS rule applied to #iframe_video1.
	
	var overlay = document.getElementById("div_video1");
	var player = document.getElementById("div_video1_player");
	var movie = document.getElementById("iframe_video1");
	
	// set default width and height if this is the first run
	var movieCurrentWidth = movie.currentStyle ? parseInt(movie.currentStyle.width) : parseInt(window.getComputedStyle(movie, null).width);
	var movieCurrentHeight = movie.currentStyle ? parseInt(movie.currentStyle.height) : parseInt(window.getComputedStyle(movie, null).height);
	if (!movieDefaultWidth) movieDefaultWidth = movieCurrentWidth;
	if (!movieDefaultHeight) movieDefaultHeight = movieCurrentHeight;
	
	// set width and height to custom if specified, default otherwise
	var movieWidth = customWidth ? customWidth : movieDefaultWidth;
	var movieHeight = customHeight ? customHeight : movieDefaultHeight;
	movie.style.width = movieWidth + "px";
	movie.style.height = movieHeight + "px";
	
	// "player" is same width as "movie" but 20 pixels taller
	var playerWidth = movieWidth;
	var playerHeight = movieHeight + 20;
	player.style.width = playerWidth + "px";
	player.style.height = playerHeight + "px";
	
	// center the player vertically in the window
	var windowHeight = document.body.clientHeight; // Webkit browsers (Chrome 9, Safari 5)
	if (document.documentElement) windowHeight = document.documentElement.clientHeight; // Mozilla / Gecko browsers (IE6, IE8, Firefox 3.6, Opera 11)
	if (document.location.href.indexOf("DEBUG") > 0) {
		alert("windowHeight = " + windowHeight);
		alert("playerHeight = " + playerHeight);
	}
	var playerY = (windowHeight < playerHeight + 10) ? 10 : Math.ceil((windowHeight - playerHeight) / 2);
	player.style.top = playerY + "px";
	
	// finally, show the movie!
	overlay.style.display = "block";
	movie.src = page;
	
	// netInsight tracking
	if (typeof(ntptEventTag) =="function") ntptEventTag('ev=openvideo&videopage='+escape(page));
	
}

function hideVideo1() {
	document.getElementById("iframe_video1").src = "blank.html";
	document.getElementById("div_video1").style.display = "none";
}

function showVideo2(page) {
	// this is now just an alias for showVideo1
	showVideo1(page);
	/*
	var scrollTop = document.body.scrollTop; // Webkit browsers (Chrome 9, Safari 5)
	if (document.documentElement) scrollTop += document.documentElement.scrollTop; // Mozilla / Gecko browsers (IE6, IE8, Firefox 3.6, Opera 11)
	document.getElementById("div_video2").style.top = scrollTop + "px";
	document.getElementById("div_video2").style.display = "block";
	document.getElementById("iframe_video2").src = page;
	*/
}

function hideVideo2() {
	// this is now just an alias for hideVideo1
	hideVideo1();
	/*
	document.getElementById("iframe_video2").src = "blank.html";
	document.getElementById("div_video2").style.display = "none";
	*/
}

function playBOL() {
	document.getElementById("player").innerHTML = "";
	window.setTimeout("flowplayer('player', '_flash/flowplayer-3.2.5.swf')", 100);
}

