//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
///
/// This rollover file has been modified from the original to make its use
/// more efficient for the Softimage User's Site. Namely, the functions
/// that before too the URL as a first argument, and the image type as the
/// third argument have been rewritten to make these global.
///
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////


// GLOBAL VARIABLES
var _url = "http://archives.itg.uiuc.edu/softimage/images/";
var _ext = ".gif";
var _debug = 0;
var _debug_console = null;



// rollClick( name )
// Swaps in the "down" image. Used mainly with "onClick" method.
function rollClick( name ) {

	// Return immediately if browser can't support DOM images.
	if ( !document.images || document.layers || document.all ) return;
	if ( _debug ) debug( "rollClick( ", name, " )" );

	// Set the down image
	var src = _url + name + "-down" + _ext;
	document.images[ name ].src = src;
	if ( _debug ) debug( "   document.images[ ", name, " ].src = ", src );

	// Reset the up image with a delay of 100ms.
	src       = _url + name + "-up" + _ext;
	var dummy = setTimeout( "whichImg.src=\"" + src, 100 );
	if ( _debug ) debug( "   setTimeout( whichImg.src = ", src, ", 100 )" );
}



// rollOver( name, 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( name, over ) {

	// Return immediately if browser can't support DOM images.
	if ( !document.images ) return; 
	if ( _debug ) debug( "rollOver( ", name, ", ", over, " )" );

	// Determine which image to swap in or out
	var src = _url + name + ( ( over ) ? "-over" : "-up" ) + _ext;
	document.images[ name ].src = src;
	if ( _debug ) debug( "   document.images[", name, "].src = ", src );
}



// rollOverDown( name, 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( name, over ) {

	// Return immediately if browser can't support DOM images.
	if ( !document.images ) return; 
	if ( _debug ) debug( "rollOverDown( ", name, ", ", over, " )" );

	// Determine which image to swap in or out
	var src = _url + name + ( ( over ) ? "-over" : "-down" ) + _ext;
	document.images[ name ].src = src;
	if ( _debug ) debug( "   document.images[", name, "].src = ", src );
}



// rollPress( name, 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( name, down ) {

	// Return immediately if browser can't support DOM images.
	if ( !document.images ) return; 
	if ( _debug ) debug( "rollPress( ", name, ", ", down, " )" );


	// Determine which image to swap in or out
	var src = _url + name + ( ( down ) ? "-over" : "-over" ) + _ext;
	document.images[ name ].src = src;
	if ( _debug ) debug( "   document.images[", name, "].src = ", src );
}



// function preloadRolloverImages( names )
// 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( names ) {

	// Return immediately if browser can't support DOM images.
	if ( !document.images ) { return }; 
	if ( _debug ) debug( "function preloadRolloverImages( names )" );

	var src = null;
	var list = new Array( );
	for ( counter in names ) {
		src = _url + names[ counter ] + "-up" + _ext;
		list[counter*3]       = new Image( );
		list[counter*3].src   = src;

		src = _url + names[ counter ] + "-over" + _ext;
		list[counter*3+1]     = new Image( );
		list[counter*3+1].src = src;

		src = _url + names[ counter ] + "-down" + _ext;
		list[counter*3+2]     = new Image( );
		list[counter*3+2].src = src;

		if ( _debug ) {
			debug( "   list[", counter*3, "].src = ",
				   list[ counter*3 ].src );
			debug( "   list[", counter*3+1, "].src = ",
				   list[ counter*3+1 ].src );
			debug( "   list[", counter*3+2, "].src = ",
				   list[ counter*3+2 ].src );
		}
	};
};



// function preloadImages( names )
// Loads the images found in the array. This function assumes that
// the array contains URIs for the images needing to be preloaded.
function preloadImages( names ) {
	if ( !document.images ) { return }; 

	list = new Array( );
	for ( counter in names ) {
		list[ counter ]     = new Image( );
		list[ counter ].src = names[ counter ];
	};
};



//
// debug( message, ... )
// Opens a debugging console, and prints out the arguments listed.
//
function debug( ) {
	if ( ( _debug_console == null ) || ( _debug_console.closed ) ) {
		_debug_console = window.open(
									 "",
									 "debug",
									 "width=600,height=300,scrollbars=yes"
									 );
		_debug_console.document.open( "text/plain" );
	}
	for( var i = 0; i < arguments.length; i++ ) {
		_debug_console.document.write( arguments[ i ], " " );
	}
	_debug_console.document.write( "\n" );
}



// Preload document images to save time on rollover items
if (document.images) {
	names = new Array (
					   "home",
					   "xsi",
					   "3d",
					   "discussion",
					   "mental",
					   "particles",
					   "hardware",
					   "toonz",
					   "eddie",
					   "ds",
					   "3dgames",
					   "softimage",
					   "resources",
					   "software",
					   "search"
					   );
	preloadRolloverImages( names );
};
