/*	Name:		Scott Ash JS Menu Image Swap	Type:		Object	Created:	12/20/2004	Modified:	03/02/2005	Version:	1.1	Updates:	12/20/2004 (v1.0)					first release into build of a website. 				03/02/2005 (v1.1)					updated swap() and load_array() functions to determine "this.base" based on image					object attributes in html document. This requires that this module be called on an 					onload event so that the methods can locate the image objects on the page. Added function					revert() to force images to default state for browser cache issues. Renamed to Menu 					Image Swap	Author:		Scott A. Ash	Copyright:	Scott Ash	Functions:	init()				load_array()				swap()								.init():				This is used to initialize the properties of the object. Each property is set 				one at a time by calling [object].init([a],[b]) and passing it the property name [a]				and the property setting [b]. Initializing a nonexistant property of the object will				result in an error message.								.load_array():				This function requires that the object be initialized before being called. Once called 				this function loads the specified image files into memory for fast swapping. This 				function is not necessary for the swap() function to work.								.swap();				This swaps the image based on an image name passed to it. An image name must be passed				or the function will return an error alert. The function finds which image to replace				based on the current url of the referenced image and the object "over" and "dormant" settings.								.revert()				This method forces all swappable images back to their default state. It is intended to be 				used on page unload() in the body tag. It takes no parameters but relies on the object being 				fully created.						Uses:		solo	Required:	This object must be initialized in the master site script or page head script before 				being used.					Settings:	None*/function sa_image_swap(){	// constructor	function init(item,val)	{		// set only legal properties of object		if(item == "graphics")			this.graphics = val;		else if(item == "over")			this.over = val;		else if(item == "dormant")			this.dormant = val;		else if(item == "base")			this.base = val;		else if(item == "types")			this.types = val;		else			alert("ERROR!\nsa_image_swap.init():\n\"" + item + "\" is not a property of this object.");	}		function load_array()	{			// test for image ability		var isAllowed = (document.images);				if(isAllowed)		{			// create image memory arrays			this.overs = new Array();			this.dormants = new Array();						// load images into memory			for(var i=0;i<this.graphics.length;i++)			{				if(document[this.graphics[i]])				{					temploc = document[this.graphics[i]].src.split(this.graphics[i]);					this.base = temploc[0];										this.overs[i] = new Image();					this.overs[i].src = this.base + this.graphics[i] + this.over + '.' + this.types;										this.dormants[i] = new Image();					this.dormants[i].src = this.base + this.graphics[i] + this.dormant + '.' + this.types;				}else				{					alert("ERROR!\nsa_image_swap.load_array():\nThe image \"" + this.graphics[i] + "\" cannot be found in the page.");				}			}		}	}		function swap_image(imgName)	{		// test for image swap ability		var isAllowed = (document.images);						if(isAllowed)		{			// find image in array			theImg = 0;	// Netscape and IE don't like variables declared without values (i.e. theImg;)			flag = 0;			for(i=0;i<this.graphics.length;i++)			{				if(imgName == this.graphics[i])				{					theImg = i;	// the image has been found!					flag = 1;	// set the flag to allow continuation of function					break;		// break out of the loop to discontinue search				}			}					// swap image			if(flag)			{				if(document[imgName].src.indexOf(this.over) != -1)				{					document[imgName].src = this.dormants[theImg].src;				}else				{					document[imgName].src = this.overs[theImg].src;				}				//alert(document[imgName].src);			}else			{				alert("ERROR!\nsa_image_swap.swap_image():\n\"" + imgName + "\" could not be set.");			}		}	}		function revert()	{		// test for image swap ability		var isAllowed = (document.images);				if(isAllowed)		{			// reset images to dormant state for browser back button returns			for(i=0;i<this.graphics.length;i++)			{				if(document[this.graphics[i]])				{					// test this function by setting all graphics to a non-dormant state and					// clicking the browser back/forward button with the alert below activated					document[this.graphics[i]].src = this.dormants[i].src;				}			}						// alert("onunload() called");		}	}		// properties	this.graphics;	this.over;	this.dormant;	this.base;	this.types;		// created properties	this.overs;	this.dormants;		// methods	this.init = init;	this.swap = swap_image;	this.load_array = load_array;	this.revert = revert;}