/******************************
Functions
******************************/
	
/*
Initiation function for this script.
*/

function initCommon()
	{
		window.onload = pageLoaded;
	}
	
/*
:TODO: look through this for all browser versions
*/

function openNewWindow(file, windowType, windowWidth, windowHeight, windowName)
	{
		// set defaults
		if (windowType != "min") windowType = "default";
		if (windowWidth == undefined) windowWidth = "600";
		if (windowHeight == undefined) windowHeight = "450";
		if (windowName == undefined) windowName = "defaultWindow";

		if (windowType == "min") window.open(file, windowName, "width=" + windowWidth + ", height=" + windowHeight + ", left=20, top=20, resizable=no, toolbar=no, scrollbars=yes, location=no, directories=no, status=no, menubar=no");
		else window.open(file, windowName, "width=" + windowWidth + ", height=" + windowHeight + ", left=20, top=20, resizable=yes, toolbar=yes, scrollbars=yes, location=yes, directories=yes, status=yes, menubar=yes");
	}

/*
ShowMenu hides all the menus to begin, then we display the navigation.
*/

function pageLoaded()
	{
		$("#navigation").css("display", "block");
		showMenu();
	}

/*
Hides or shows the selected menu item's sub menu items.
Begins by collapsing all sub menus and then expanding the selected set of sub menu items.
*/

function showMenu(selectedMenuItems) 
	{
		var currSubMenu;
		var subMenuSet = $("#submenu" + String(selectedMenuItems));

		for (var i = 0; i <= 10; i++)
		{
			currSubMenu = $("#submenu" + String(i));
			
			if (currSubMenu)
			{
				$("#mainmenu" + String(i) + " a").css("background-color", "#" + mainNavButtonColour);
				currSubMenu.css("display", "none");
			}
		}
		
		if (subMenuSet)
		{
			$("#mainmenu" + String(selectedMenuItems) + " a").css("background-color", "#" + mainNavButtonOverColour);
			subMenuSet.css("display", "block");
		}
	}
	
/*
Displays a video, accompanied by an initial image and play button.
	
	@videoId:String							unique id for the video
	@width:String								width of the video and image
	@height:String							height of the video and image
	@justification:String				left or right justification
	@videoPath:String						path to video
	@imagePath:String						path to start image
	@playButtonPath:String			path to play button image
	@controlsPath:String				path to video control panel
	@controlsColor:String				colour of video control panel
	@controlsAlpha:String				alpha of video control panel (0 to 1, for example: .5)
	@controlsHideDela:String		delay in secs before video control panel auto hides
*/

function displayVideo(
	videoId,
	width,
	height,
	justification,
	videoPath,
	imagePath,
	playButtonPath,
	controlsPath,
	controlsColor,
	controlsAlpha,
	controlsHideDelay
) 
	{
		// ensure that the default left justification is specified
		if (justification != "right") justification = "left";

		// ensure that the video path is either absolute or begins with a forward slash
		if (videoPath.indexOf("http:") == -1)
		{
			if (videoPath.indexOf("/") != 0) videoPath = "/" + videoPath;
		}
		
		if (justification == "left")
		{
			document.write('<div class="videoLeft">');
		}
		else
		{
			document.write('<div class="videoRight">');
		}		
		
		document.write('<div id="' + videoId + '"></div>');
		document.write('</div>');
		
		// add the developer's video info to the flash vars
		var flashvars = {
			videoPath:videoPath,
			imagePath:imagePath,
			playButtonPath:playButtonPath,
			controlsPath:controlsPath,
			controlsColor:controlsColor,
			controlsAlpha:controlsAlpha,
			controlsHideDelay:controlsHideDelay
		};

		// fixed params
		var params = {
			menu:"false",
			allowScriptAccess:"always",
			allowFullScreen:"true",
			salign:"tl",
			base:"",
			bgColor:"#000000"
		};

		var attributes = {};

		swfobject.embedSWF(
			"system/flash/video_loader.swf",
			videoId,
			width,
			height,
			"9.0.0",
			"system/flash/expressInstall.swf",
			flashvars,
			params,
			attributes
		);
	}

/******************************
First run
******************************/

initCommon();

