// rollovers.js
//
// Purpose: Easy, organized rollover support for web pages.
//
// Definitions: A rollover is a set of elements in an HTML document
// consisting of:
//
//     An HTML anchor tag which conatains a named image and whose onMouseover 
//         and onMouseout event handlers have been set to javascript functions 
//         that control the state of the named image.
//
//     The named image, with its source set to the path of 
//         an initial image file, which is also called the 'out' image.
//
//     A javascript rollover object having the same name as the named image
//         and holding the paths to the 'over', 'out', and 'locked'
//         image paths.
//
//     Javascript methods for creating rollover objects, setting the state
//         of the named image, and for setting user-specified rollover images
//         to a 'locked' state.
// 
// A Super Rollover is a rollover that controls two named images - the primary, 
// mousing over which causes an image swap, and a linked image that changes 
// as the primary changes. Mousing over the linked image does nothing. An image 
// of a link/image combo that is serving as a linked image within a Super Rollover, can 
// itself be defined as the primary image in another Super Rollover, or as the 
// only image in a standard rollover.
//    
// To use this file, include it as Javascript source in your HTML file. Your
// HTML file will define the rollovers using these data types and methods.
//
// Author: David DeMello (ddd1@cornell.edu) 7/28/99.
//
// Revised to include "Super Rollovers" by DD, 11/23/99.
//
// Revised to sense browser type and to include Layer Rollovers by DD, 3/6/2000.
//
// Revised to allow for killing the over state of a locked rollover by DDD, 2/16/2001.

// -----------------------------------------------------------------------
   

// Sense browser type.
var isNav, isIE;

if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true;
	} else {
		isIE = true;
	}
}

// Functions to show and hide CSS-P layers by name.
var activeLayer = "";

function hideLayer(layerName) {
	if (isNav) eval("document."+layerName+".visibility = 'hidden'");
	if (isIE) eval("document.all."+layerName+".style.visibility = 'hidden'");
}

// showLayer() first hides the currently active layer.
function showLayer(layerName) {
	if (activeLayer != "") hideLayer(activeLayer);
	if (isNav) eval("document."+layerName+".visibility = 'visible'");
	if (isIE) eval("document.all."+layerName+".style.visibility = 'visible'");
	activeLayer = layerName;
}

// rollovers is an associative array to contain all of the rollover objects
// for a document and to allow them to be referenced by name.

var rollovers = new Object();

// createRollover() creates a new rollover object and sets its name,
// the paths to its rollover and rollout images (overImg and outImg),
// and optionally, a path to a third image (lockedImg) to be used
// when the rollover is locked into an 'on' state, as one might do
// when a rollover is referencing the current page. If the lockedImg
// parameter is omitted, overImg will be used in its place for locked rollovers.

function createRollover(name, outImg, overImg, lockedImg, lockedImgFinal) {

	var theArgs = createRollover.arguments;
		
	if (theArgs.length < 3) {
	
		alert("createRollover() was called with too few arguments.");
		return false;				
	}
	
	rollovers[name] = new Object();
	
	rollovers[name].out = outImg;
	
	// The image for 'out' gets loaded in the browser by the <IMG> tag. 
	// For 'over' and 'locked', we create and load their images
	// as part of this rollover object. This is done to force the
	// browser to preload these images so that there is no delay
	// the first time the user rolls over an image.
			
	rollovers[name].over = new Image();
	rollovers[name].over.src = overImg;
	
	if (theArgs.length > 3) {
	
		rollovers[name].locked = new Image();
		rollovers[name].locked.src = lockedImg;
		
	}
	
	if (theArgs.length > 4) {
		rollovers[name].lockedImgFinal = lockedImgFinal;
	} else {
		rollovers[name].lockedImgFinal = "false";
	}
	
	return true;
	
}
		
		
// createSuperRollover() creates a new super rollover object and sets its name,
// the paths to its rollover and rollout images (overImg and outImg),
// the name of its linked rollover (linkedName), and the paths to the rollover   
// and rollout images of its linked rollover (linkedOverImg and linkedOutImg).

function createSuperRollover(name, outImg, overImg, linkedName, linkedOutImg, linkedOverImg) {

	var theArgs = createSuperRollover.arguments;
		
	if (theArgs.length < 6) {
	
		alert("createSuperRollover() was called with too few arguments.");
		return false;				
	}
	
	rollovers[name] = new Object();
	
	rollovers[name].linkedName = linkedName;
	
	rollovers[name].out = outImg;
	rollovers[name].linkedOut = linkedOutImg;
	
	// The images for 'out' and 'linkedOut' get loaded in the browser by the <IMG> tag. 
	// For 'over' and 'linkedOver', we create and load their images
	// as part of this rollover object. This is done to force the
	// browser to preload these images so that there is no delay
	// the first time the user rolls over an image.
			
	rollovers[name].over = new Image();
	rollovers[name].over.src = overImg;
	
	rollovers[name].linkedOver = new Image();
	rollovers[name].linkedOver.src = linkedOverImg;
	
	return true;
	
}

// createLayerRollover() creates a new rollover object and sets its name,
// the paths to its rollover and rollout images (overImg and outImg),
// the name of an associated CSS-P layer (layerName), to be made visible by onMouseOver().
//
// Usage note: To position layers acurately across browsers, the body of the page is
// placed in an initial CSS-P layer with absolute positioning (rather than letting
// the browser place content arbitrarily without positioning). This way, subsequent layers 
// can be positioned absolutely with some assurance that they will line up with the
// content the same way in both browsers. These rollover functions support the existence 
// of that first base layer (imageLayer), and their NETSCAPE CALLS WILL BREAK if the
// the layer exists and is not specified when the rollover is created.
// (e.g., if the base layer is defined thus: <div id="base"></div>, then 'imageLayer'
// must be specified as either 'document.layers[0]' or 'document.base')

function createLayerRollover(name, outImg, overImg, layerName, imageLayer) {

	var theArgs = createLayerRollover.arguments;
		
	if (theArgs.length < 4) {
	
		alert("createLayerRollover() was called with too few arguments.");
		return false;				
	}
	
	rollovers[name] = new Object();
	
	rollovers[name].layerName = layerName;
	
	if (theArgs.length == 5) rollovers[name].imageLayer = imageLayer;
	else rollovers[name].imageLayer = "";
	
	rollovers[name].out = outImg;
	
	// The image for 'out' gets loaded in the browser by the <IMG> tag. 
	// For 'over', we create and load the image
	// as part of this rollover object. This is done to force the
	// browser to preload this image so that there is no delay
	// the first time the user rolls over the image.
			
	rollovers[name].over = new Image();
	rollovers[name].over.src = overImg;
	
	return true;
	
}
		
		
// msover sets the image src of a named rollover and its linked rollover 
// or associated layer (if it has one) to their 'over' states.
function msover(name) {
	
	if (rollovers[name].linkedName != null) {	
		var theLinkedName = rollovers[name].linkedName;		
		document[name].src = rollovers[name].over.src;
		document[theLinkedName].src = rollovers[name].linkedOver.src;
	} else if (rollovers[name].layerName != null) {
		if (isNav) eval(rollovers[name].imageLayer + ".document[name].src = rollovers[name].over.src");
		if (isIE) document[name].src = rollovers[name].over.src;
		showLayer(rollovers[name].layerName);
	} else {	
		document[name].src = rollovers[name].over.src;		
	}
}

// msout sets the image src of a named rollover and its linked rollover 
// (if it has one) to their 'out' states.
function msout(name) {

	if (rollovers[name].linkedName == null) {
		
		if (isNav && rollovers[name].layerName != null) eval(rollovers[name].imageLayer + ".document[name].src = rollovers[name].out");
		else document[name].src = rollovers[name].out;			
		
	} else {
	
		var theLinkedName = rollovers[name].linkedName;
		
		document[name].src = rollovers[name].out;
		document[theLinkedName].src = rollovers[name].linkedOut
	}
}

// lockRollovers() goes through all rollovers in the document and sets each  
// one whose name appears in 'nameList' to the 'locked' state. 'nameList' is 
// a string containing a list of rollover names separated by spaces.

function lockRollovers(nameList){

	var locked, Name = new String();	
			
	for (theImages in rollovers) {
	
		Name = theImages.toString();
		
		// If Name is in the list, set both 'out' and 'over' either to 
		// 'over', or to 'locked' if its available.
		
		if (nameList.indexOf(Name) != -1) {		
			locked = rollovers[Name].over.src;
			
			if (rollovers[Name].locked) {			
				locked = rollovers[Name].locked.src;
				//rollovers[Name].over.src = locked;
			}
			
			rollovers[Name].out = locked;
			document[Name].src = locked;
			
			if (rollovers[Name].lockedImgFinal == "true")  {
				rollovers[Name].over.src = locked;
			}
		}
	}
}

