<!--
// --------------------------------------------------------------------
// $Id: ImageCommander.js,v 1.1 1999/02/06 03:49:46 burger Exp $
//
//	Object: ImageCommander
//	Author: Eugene Burger
//	Date: January 1999
//
//	Various methods to maniplulate images in a document with the onClikc and
//	onMouseOver event handlers
//	preloadImages()
//		Preload the images specified in the parameter list.
//	restoreImage()
//		Restore images that have been swapped with swapImageRestore().
//	swapImageRestore()
//		Do an image swap - and save information to be used for restore.		
// -------------------------------------------------------------------


// preload images as psecified in parameter list.
function preloadImages()
{
	if (this.thisDoc.images)
  	{
  		var newImages = preloadImages.arguments;
    	if (this.thisDoc.imageArray == null) this.thisDoc.imageArray = new Array();
	
    	var arrayLength = this.thisDoc.imageArray.length;
    	for (var j = 0; j < newImages.length; j++)
		{
      		this.thisDoc.imageArray[arrayLength] = new Image;
			//alert(newImages[j]);
      		this.thisDoc.imageArray[arrayLength++].src = newImages[j];
  		}
	}
}

// Use a global variable created with the last onMouseOver
// This way of restoring images got from MacroMedia Dreamweaver
// behaviours
// Save restoreData as variable[i] = image name, variable[i+1] = image src to replace
// current image src.
// It can handle multiple restores
function restoreImage()
{
	var i = 0;
	var imageName, imageObj;
	
	if (this.restoreData != null)
	{
	//	alert('restoreData is not null.');
		for (i = 0; i < (this.restoreData.length - 1); i+=2)
		{
			imageName = this.restoreData[i];
			imageObj = eval(this.thisDoc.images[imageName]);
		//	alert(this.restoreData[i]+' '+this.restoreData[i+1]);
			imageObj.src = this.restoreData[i+1].src;
		}
	}
}

// Will swap as many images as you like. Pass arguments
// as imageName, imageSrc, etc...
// this will not add images to the restore image array.
function swapImage()
{
//	alert("swapImage called");
	var i = 0;
	var imageName, imageObj;
	var imageSrc;
	if (this.thisDoc.images)
	{
		var imageSwapCount = swapImage.arguments;
		for (i = 0; i <= (imageSwapCount.length -2); i +=2)
		{
//			alert(imageSwapCount[i] + ' ' + imageSwapCount[i+1]);
			imageName = imageSwapCount[i];
			imageObj = eval(this.thisDoc.images[imageName]);
			imageSrc = imageSwapCount[i+1];		
			imageObj.src = imageSrc;
		}
	}
}

// do the image swap - but add the required information into an array
// to restore the image on for instance onMouseOut.
// Call swapImageRestore('imageName', imageFileName', ...);
function swapImageRestore()
{
	var i = 0;
	var imageName, imageSrc, imageObj, oldImage;
	var swapData = new Array();
	
	if (this.thisDoc.images)
	{
		var imageSwapCount = swapImageRestore.arguments;
		for (i = 0; i <= (imageSwapCount.length -2); i+=2)
		{
			oldImage = new Image();
			imageName = imageSwapCount[i];
			imageObj = eval(this.thisDoc.images[imageName]);
			imageSrc = imageSwapCount[i+1];
			// buffer the old image src
			oldImage.src = imageObj.src;
			imageObj.src = imageSrc;
			
			// imageObj.src = oldImage.src;
			// data for restoring images
			swapData[i] = imageName;
			swapData[i+1] = eval(oldImage);		
		}
		this.restoreData = swapData;		
	}
}

// the only parameter is a reference to 'this' document.
function ImageCommander(thisDoc)
{
	this.thisDoc = thisDoc;
	this.restoreData = null;

	this.preloadImages = preloadImages;
	this.swapImage = swapImage;
	this.swapImageRestore = swapImageRestore;
	this.restoreImage = restoreImage;
}
//-->