// ROLLOVER FUNCTIONS
// The following set of functions perform the "rollover" image swapping
// found in the ITG menus. These rollover functions can be used any time
// the rollover effect is desired, irregardless of the presence of menus.
// Note that the image to be swapped must contain a unique "name" tag.
//
// For example, "menu_item" refers to this image in the HTML document:
//		<img src="menu_item-up.gif" name="menu_item" ...>
//
// Each function takes a similar set of arguments:
//
//		uri:	Uniform Resource Identifier
//				The location of the image. May be a complete URL or
//				just a relative reference.
//
//		name:	Image Name
//				The name of the image. Please note that the image
//				name must use the following conventions:
//				* Appended to the name are the extensions "-up",
//				  "-over", and "-down", to indicate the "position"
//				  of the image.
//
//		type:	Image Type / Extension
//				The type of the image. This allows one to swap images
//				of an arbitrary type. The type must reflect the file
//				extension used on the filename. E.g. ".gif", ".jpg", etc.
//
//		over:	Mouse Position Check
//				Indicates the position of the mouse: either over
//				the image or not over the image. "true" indicates
//				over, and will cause the "-over" image to be loaded.
//
//		down:	Mouse Up or Down Check
//				Indicates the setting of the mouse button: either up
//				or down. "true" indicates a "down" position, and will
//				cause the "-down" image to be loaded.
//
// These functions should be free from side-effects as they only influence
// the image source associated with a single document image.
//

// rollClick( uri, name, type )
// Swaps in the "down" image. Used mainly with "onClick" method.
function rollClick( uri, name, type ) {
	if ( !document.images || document.layers || document.all ) { return };
	whichImg = document.images[ name ];
	whichImg.src = uri + name + "-down" + type;
	dummy = setTimeout( "whichImg.src=\"" + uri + name + "-up\"" + type, 100 );
}

// rollOver( uri, name, type, over )
// Swaps in the "over" image if "over" or swaps in the "up" image 
// otherwise. Used mainly with the "mouseOver" and "mouseOut" events.
function rollOver( uri, name, type, over ) {
	if ( !document.images ) { return }; 
	whichImg = document.images[ name ];
	if ( over ) {
		whichImg.src = uri + name + "-down" + type;
	}
	else {
		whichImg.src = uri + name + "-up" + type
	}
}

// rollOverDown( uri, name, type, over )
// Swaps in the "over" image if "over" or swaps in the "down"
// image otherwise. Used mainly with the "mouseOver" and "mouseOut"
// events when the starting image is already "down".
function rollOverDown( uri, name, type, over ) {
	if ( !document.images ) { return }; 
	whichImg = document.images[ name ];
	if ( over ) {
		whichImg.src = uri + name + "-down" + type
	}
	else {
		whichImg.src = uri + name + "-down" + type
	}
}

// rollPress( uri, name, type, down )
// Swaps in the "down" image if "down" or swaps in the "over"
// image otherwise. Used mainly with the "mouseDown" and "mouseUp"
// events.
function rollPress( uri, name, type, down ) {
	whichImg = document.images[ name ];
	if ( down ) {
		whichImg.src = uri + name + "-down" + type
	}
	else {
		whichImg.src = uri + name + "-down" + type
	}
}




// PRELOADING FUNCTIONS
// The following functions are designed to preload the list of images
// from the URIs as specified.
//
// The arguments to the functions are as follows:
//	uri:		Uniform Resource Identifier
//			The base location of the images found in the array.
//
//	array:	Image Array
//			The list of image names. Note that the extension is not
//			given in the array, nor are the automatically appended
//			types given, in the array used by the function
//			preloadRolloverImages.
//
//	type:		The Image Type
//			Used to specify the type of images included in the array.
//

// function preloadRolloverImages( uri, array, type )
// Loads the images found at the base URI, named by the names contained
// in the image array of the specified type. Appended to the image name
// are the extensions "-up", "-over", and "-down".
function preloadRolloverImages( uri, array, type ) {
	list = new Array( );
	for ( counter in array ) {
		list[ counter*3 ] = new Image( );
		list[ counter*3 ].src = uri + array[ counter ] + "-up" + type;
		list[ counter*3+1 ] = new Image( );
		list[ counter*3+1 ].src = uri + array[ counter ] + "-down" + type;
	};
};


// function preloadImages( array )
// Loads the images found in the array. This function assumes that
// the array contains URIs for the images needing to be preloaded.
function preloadImages( array ) {
	list = new Array( );
	for ( counter in array ) {
		list[ counter ] = new Image( );
		list[ counter ].src = array[ counter ];
	};
};




// HEADER IMAGES
// This javascript segment preloads all of the images found in the
// standard document header including the ITG name, the Beckman
// Institute name, the VMIL name, and the Microscopy Suite name.

// Preload document images to save time on rollover menus
// if (document.images) {
// 	headerArray = new Array	(
// 							 "header-itg",
// 							 "header-bi",
// 							 "header-vmil",
// 							 "header-ms"
// 							 );
// 	preloadRolloverImages( "/newimages/", headerArray, ".gif" );
// };
