/**********************************************************************
	BioWare Javascript File
	
	File: rollover.js
	
	Description: Code for creating rollovers, and modified for use with HierMenus
	
	Created: Robin Mayne, April 11, 2002 Copyright 2002 BioWare Corp.
***********************************************************************	
	Version: 0.0.2
	
	Version History:
		0.0.1 / 11.04.02 / Created / RM
		0.0.2 / 23.09.03 / Added function swapImg() / RM

***********************************************************************/

// ------------------------ Rollover scripts ------------------------ 
var index = 0;
var imgobj = new Array();

function preloader(name, onimg, offimg) {
    imgobj[index] = new Array(3);
    imgobj[index][0] = new Image();
    imgobj[index][0].src = onimg;
    imgobj[index][1] = new Image();
    imgobj[index][1].src = offimg;
    imgobj[index][2] = name;
    index++;
}

var inimgobj = new Array();
var inindex = 0;
//preloader for Input image tags
function inputImgPreloader(id, onimg, offimg) {
    inimgobj[inindex] = new Array(3);
    inimgobj[inindex][0] = new Image();
    inimgobj[inindex][0].src = onimg;
    inimgobj[inindex][1] = new Image();
    inimgobj[inindex][1].src = offimg;
    inimgobj[inindex][2] = id;
    inindex++;
}

//Array Image Caching
// -allows caching of images in an array, 
var ImgArray = new  Array(); // generic 

//arrayloader
//	- preloads images into an array for a specified "group" 
//	- group name  (e.g. charindex) is used in setCharImg() to specify which sub array to load them from
//	- name must be unique for each entry in a group, since they are used to index array
// e.g. 		arrayloader("charindex", "ming", "images/charindex_pc_fm.gif");
function arrayloader(group, name, imgsrc) {
	if ( ImgArray[group] == null) 
	{ 
		//create the group sub array on the first call to arrayloader
		ImgArray[group] = new Array();
	}
	ImgArray[group][name] = new Image();
	ImgArray[group][name].src = imgsrc;
}

//setCharImg
//	- sets image
//	imgid : the id of the image on the page to be set
//	name : the image in charImgArray to set imgid to
// e.g. <a href="evil_magician.html" onmouseover="setArrayImg('villainimg', 'charindex', 'emagician');">Evil Magician</a>
function setArrayImg(imgid, group, name) {
	document.images[imgid].src = ImgArray[group][name].src;
}

function inputImgRoll(inputID, on) {
	for (i=0; i < inindex; i++){
		if (inputID == inimgobj[i][2]) document.getElementById(inputID).src = (on) ? inimgobj[i][1].src : inimgobj[i][0].src;
	}
}

//imgRoll
function imgRoll(name, on) {
	if (HM_NS4 && (!document.images[name]))
	{
		// Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs)
		for (a = 0; a < document.layers.length; a++) 
		{
			if (document.layers[a].document.images[name]) 
			{
				for (i = 0; i < index; i++) 
				{
					if (name == imgobj[i][2]) document.layers[a].document.images[imgobj[i][2]].src = (on) ? imgobj[i][1].src : imgobj[i][0].src;
				}
			return true;
			}
		}
	} else 
	{
		for (i = 0; i < index; i++) 
		{
			if (name == imgobj[i][2]) document.images[imgobj[i][2]].src = (on) ? imgobj[i][1].src : imgobj[i][0].src;
		}
	}
}

/*
Template code for image rollovers

For use with HierMenus:
<a href="#" onmouseover="onmouseSwitch('imagename','on','1',event)" onmouseout="onmouseSwitch('imagename','off','1')"><img border="0" name="imagename" src="path/to/image.gif" /></a>

Stand-alone use:
<a href="#" onmouseover="imgRoll('imagename',true)" onmouseout="imgRoll('imagename',false)"><img border="0" name="imagename" src="path/to/image.gif" /></a>

*/

// Determine whether mouseover will trigger Menu or rollover only (for those browsers unable to display menu)
function onmouseSwitch(strImageName, strOnOff, strMenuNum, eventObj) {
	if (strOnOff == "on") { 		// onmouseover
		if (HM_IsMenu) 
		{
			HM_f_PopUp('elMenu' + strMenuNum, eventObj); // Calling Menus
		}
		else 
		{
			imgRoll(strImageName,true); // Calling Rollover only
		}
	}
	else 
	{ 							// onmouseout
		if (HM_IsMenu) 
		{
			HM_f_PopDown('elMenu' + strMenuNum) // Calling Menus
		}
		else 
		{
			imgRoll(strImageName,false); // Calling Rollover only
		}
	}
	
}

// function for switching any image - created for Jade site eye movement
//  imgname : dom name of image to switch
//  imgsrc : url of image to replace it with
// e.g. swapImg('s_lefteye', '/_global/themes/jade1/images/s_nav_eyeleft11.jpg');
function swapImg(imgname, imgsrc) {
	//swappedimg = new Image();
  //swappedimg.src = imgsrc;	
	document.images[imgname].src = imgsrc;
	return true;
}


 