//====================================================================
//
//	Application	:	JavaScript Library
//
//	File		:	maelstrom2.js
//
//	Author		:	Tarique Naseem
//
//	Date		:	30/10/98
//
//	Copyright	:	Copyright (c) 1999, Maelstrom Virtual Productions
//					Ltd. All rights reserved. This program may in no
//					way be distributed without the express permission
//					of Maelstrom Virtual Productions Ltd.
//
//	Description	:	Handles image highlighting and text replacement
//
//====================================================================

//----- globals ------------------------------------------------------

imgOn		= new Array();		  			// 'on' image link list
imgOff		= new Array();		  			// 'off' image link list
imgList		= new Array();					// image list
textList	= new Array();					// text list

browser		= null;				  			// browser type


//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Check browser type.
//					NS		= Netscape			(Version 3.0 onwards)
//					IE		= Internet Explorer (Version 4.0 onwards)
//					None	= Browser cannot run JavaScripts
//
//	Parameters	:	None
//
//	Return		:	None
//
//====================================================================

function	GetBrowserType()
{
	browserName	= navigator.appName;
	browserVer	= parseInt(navigator.appVersion);

	if(browserName == "Netscape" && browserVer >= 3)
		browser = "NS";

	else if(browserName == "Microsoft Internet Explorer" &&
			browserVer	>= 4) {

		browser = "IE";
	}
	else
		browser = null;
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Pre-load the highlighted and unhighlighted images.
//					The filename for the images should be of the form:
//
//					Un-highlighted image	- <imgname><n>.gif
//					Highlighted image		- <imgname><n>a.gif
//
//					Where <imgname> is the group name and <n> is the
//					index number of the image (1 to <n>).
//
//	Parameters	:	grpName	-	Name of image group
//					grpCnt	-	Number of images to load
//
//	Return		:	None
//
//====================================================================

function	LoadImageLinks(grpName, grpCnt)
{
	//----- check for valid browser ----------------------------------

	if(browser == null)
		return;

	//----- preload 'off' & 'on' images ------------------------------

	for(i = 1; i < (grpCnt + 1); i++)
		LoadImageLink(grpName + i, grpName + i);
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Preload a specific image and store in the list.
//					The same filename rules as above must be observed.
//
//	Parameters	:	imgName	-	Image name to load
//					imgFile	-	Image filename
//
//	Return		:	None
//
//====================================================================

function	LoadImageLink(	imgName,
							imgFile)
{
	//----- check for valid browser ----------------------------------

	if(browser == null)
		return;

	//----- preload 'off' & 'on' image -------------------------------

	imgOn[imgName]		= new Image;
	imgOn[imgName].src	= "images//" + imgFile + "a.gif";

	imgOff[imgName]		= new Image;
	imgOff[imgName].src	= "images//" + imgFile + ".gif";
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Preload an image and store on the image list.
//
//	Parameters	:	imgName	-	Image name to load
//					imgFile -	Image filename
//
//	Return		:	None
//
//====================================================================

function	LoadImage(	imgName,
						imgFile)
{
	//----- check for valid browser ----------------------------------

	if(browser == null)
		return;

	//----- preload the image ----------------------------------------

	imgList[imgName]		= new Image;
	imgList[imgName].src	= "images//" + imgFile + ".gif";
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Show image
//
//	Parameters	:	imgPos	-	Image position name
//					imgName	-	Image name
//
//	Return		:	None
//
//====================================================================

function	ShowImage(	imgPos,
						imgName)
{
	//----- check for valid browser ----------------------------------

	if(browser == null)
		return;

	//----- display the image ----------------------------------------

	img = eval("imgList['" + imgName + "']");
	document[imgPos].src = img.src;
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Highlight the specified image
//
//	Parameters	:	imgName	-	Image name to highlight
//
//	Return		:	None
//
//====================================================================

function	TurnOnImage(imgName)
{
	//----- check for valid browser ----------------------------------

	if(browser == null)
		return;

	//----- select 'on' image ----------------------------------------

	img = eval("imgOn['" + imgName + "']");
	document[imgName].src = img.src;
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Un-highlight the specified image
//
//	Parameters	:	imgName	-	Image name to un-highlight
//
//	Return		:	None
//
//====================================================================

function	TurnOffImage(imgName)
{
	//----- check for valid browser ----------------------------------

	if(browser == null)
		return;

	//----- select 'off' image ---------------------------------------

	img = eval("imgOff['" + imgName + "']");
	document[imgName].src = img.src;
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Show layer
//
//	Parameters	:	objStr	-	Object string
//
//	Return		:	None
//
//====================================================================

function	ShowLayer(objStr)
{
	//----- check for valid browser ----------------------------------

	if(browser == null)
		return;

	//----- show netscape object -------------------------------------

	if(browser == "NS" && document.layers != null) {
		obj = eval("document.layers." + objStr);
		obj.visibility = 'show';
	}

	//----- show ie object -------------------------------------------

	else if(document.all != null) {
		obj = eval("document.all." + objStr);
		obj.style.visibility = 'visible';
	}
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Hide layer
//
//	Parameters	:	objStr	-	Object string
//
//	Return		:	None
//
//====================================================================

function	HideLayer(objStr)
{
	//----- check for valid browser ---------------------------------

	if(browser == null)
		return;

	//----- hide netscape object -------------------------------------

	if(browser == "NS") {
		obj = eval("document.layers." + objStr);
		obj.visibility = 'hide';
	}

	//----- hide ie object -------------------------------------------

	else {
		obj = eval("document.all." + objStr);
		obj.style.visibility = 'hidden';
	}
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Add text to image link text list. The first in the
//					list is a default text which comes up when no link
//					is selected. Make this a null string for no
//					default text.
//
//	Parameters	:	idx		-	Array index
//					text	-	Text to add
//					
//
//	Return		:	None
//
//====================================================================

function	AddToTextList(	idx,
							text)
{
	textList[idx] = text;
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Highlight the specified image and replace the
//					default text with one associated with the
//					highlighted link.
//
//	Parameters	:	imgName	-	Image name to highlight
//					idx		-	Index of text to display
//					dText	-	Text position name
//					dPos	-	Text cell position name
//
//	Return		:	None
//
//====================================================================

function	TurnOnText(imgName, idx, dText, dPos)
{
	//----- check if image needs to be highlighted -------------------

	if(imgName != null)
		TurnOnImage(imgName);

	//----- turn on text and reposition for Netscape -----------------

	if(browser == "NS") {
		document.layers[dText].document.open();

		document.layers[dText].document.write(textList[idx]);
		document.layers[dText].moveToAbsolute(
									document.layers[dPos].pageX,
									document.layers[dPos].pageY);

		document.layers[dText].visibility = 'show';
		document.layers[dText].document.close();
	}

	//----- turn on text for IE --------------------------------------

	else {
    	document.all[dText].innerHTML			= textList[idx];
		document.all[dText].style.visibility	= 'visible';
	}
}

//====================================================================
//
//	Author		:	Tarique Naseem
//
//	Description	:	Un-highlight the specified image and replace the
//					current text with the default text.
//
//	Parameters	:	imgName	-	Image name to un-highlight
//					dText	-	Text position name
//
//	Return		:	None
//
//====================================================================

function	TurnOffText(imgName, dText)
{
	//----- check if image needs to be un-highlighted ----------------

	if(imgName != null)
		TurnOffImage(imgName);

	//----- replace text with default text ---------------------------

	if(browser == "NS") {
		document.layers[dText].document.open();
		document.layers[dText].document.write(textList[0]);
		document.layers[dText].document.close();
	}
	else
		document.all[dText].innerHTML = textList[0];
}
