/*	First Release: 01/04/2002, phaedrus										*/
/*	Release Version: 1.0													*/
/*	Requires: YMobjects.js													*/

// netscape navigator 4.x has some problems that require workarounds
if((navigator.appName=='Netscape') && (parseInt(navigator.appVersion)==4))
{
	// Every page has a search field.  In netscape 4.x, the border
	// appears wrong, so set the color to the background color.
	document.classes.searchfield.INPUT.borderColor = document.classes.search.TD.backgroundColor;
	document.tags.ul.position = "relative";
	document.tags.ul.left = "-3.6em";
	
	initYMObj(window);
			
	window.YM.set("pgW",window.innerWidth); 
	window.YM.set("pgH",window.innerHeight);
			
	window.YM.addHandler("onresize","YM_NSCssFix();");
}

function YM_NSCssFix(init)
// If the version of the browser has the NS resize bug, record the current
// window width and height and set resize events to be handled by the 
// YM_NSCssFix() function.
{		
	if(window.innerWidth!=YM.get("pgW") || window.innerHeight!=dYM.get("pgH"))
	{	
			window.location.reload();
	}
}	// end function YM_NSCssFix(init)

function YM_preloadImgs()
// pre loads images into the browser's cache for later use
{
	//	expects series of image URLs to be cached

	// check to make sure that images are supported in the DOM.
	if(!document.images)	
	{
		return false;
	}
	
	initYMObj(document);
	document.YM.set("loadedImages",new Array());
	
	// Loop through all the parameters.
	var argLength = YM_preloadImgs.arguments.length;		
	for(var lcv=0;lcv<argLength;lcv++)
	{
		// For each parameter, create a new image.
		document.YM.loadedImages[lcv] = new Image();
		
		// Set the source of the image to the current parameter.
		document.YM.loadedImages[lcv].src = YM_preloadImgs.arguments[lcv];		
	}	
}	// end function YM_preloadImgs(url1,url2,url3,...)

function YM_swapImgs()
/* Changes the source of one or more images.
 *
 * The original source is kept in a parameter called YM.restoreSrc to support
 *	restoring the image to its' original state.
 *
 * A parameter called YM.swapCounter is a counter of how many times in a row
 *	the image has been switched to this src.  This is used so that the image
 *	will only be restored when it has been requested the same number of times.
 *
 * If the image has been changed before and NOT restored, it will be changed
 *	again with the YM.restoreSrc being reset to the latest source.
*/
{
	// expects series of name/source pairs where name is the name of the 
	// image to be changed and source is the new source for the image to display

	// check to make sure that images are supported in the DOM.
	if(!document.images)	
	{
		return false;
	}
	
	var theImg;		// image name for current image being changed
	var theSrc;		// new source for current image being changed
	var lcv;		// loop control variable for looping through arguments
	var argLength;	// total number of arguments	
	var tempImg = new Image();	// a temporary image object
	
	// loop through the argument pairs
	argLength = YM_swapImgs.arguments.length;		
	for(lcv=0;lcv<argLength;lcv=lcv+2)
	{
		theImg = YM_swapImgs.arguments[lcv];
		theSrc = YM_swapImgs.arguments[lcv+1];
		
		// check if theImg is an object with src property
		if((typeof(theImg) == 'object') && theImg.src)
		{
			// make sure the image has a YM object
			initYMObj(theImg);
			
			// if the image does not currently have a restoreSrc parameter
			// create it and set the swapCounter to 1
			if(!theImg.YM.restoreSrc)
			{
				theImg.YM.set("restoreSrc",theImg.src);
				theImg.YM.set("swapCounter",1);
			}	
			else if(navigator.appName=='Netscape')
			{
				// the next block of script does not work for netscape yet as
				// netscape doesn't handle comparing the sources as gracefully.
				// for now, always increment the swap counter, do not reset the
				// restore source
				theImg.YM.set("swapCounter",theImg.YM.get("swapCounter")+1);
			}
			else
			{
				// we need to do a source comparison, but we don't know what
				// type of reference the input uses, so assigning the source to
				// a temp image will fully qualify it
				tempImg.src = theSrc;
				
				// if the current source is the same as the new source, and the
				// swap counter is defined, increment the swapCounter				
				if((theImg.src == tempImg.src) && theImg.YM.swapCounter)
				{
					theImg.YM.set("swapCounter",theImg.YM.get("swapCounter")+1);
				}
				else
				// otherwise, set the swap counter to 1.
				{
					theImg.YM.set("restoreSrc",theImg.src);
					theImg.YM.set("swapCounter",1);
				}
			}
			
			// swap the image source
			theImg.src = theSrc;
		}
	}
}	// end function YM_swapImgs(imgName1,imgSrc1,imgName2,imgSrc2,...)

function YM_restoreImgs()
/* Changes the source of one or more images.
 *
 * The original source is kept in a parameter called YM.restoreSrc
 *
 * A parameter called YM.swapCounter is a counter of how many times in a row
 *	the image has been switched to this src.  Each time a restore is called, 
 *	this counter is decremented.  If it is greater than zero, the image will not
 *	be restored.  Once it reaches zero, it will be restored and YM.restoreSrc
 *	will be set to null.
*/
// Restores the source of one or more images.  
{
	// expects series of image names. each image needs a YM.restoreSrc property
	
	// check to make sure that images are supported in the DOM.
	if(!document.images)	
	{
		return false;
	}
	
	var theImg		// image name for current image being changed
	var lcv			// loop control variable for looping through arguments
	var argLength	// total number of arguments	
	
	// loop through the argument pairs
	argLength = YM_restoreImgs.arguments.length;		
	for(lcv=0;lcv<argLength;lcv++)
	{
		theImg = YM_restoreImgs.arguments[lcv];
		
		// ensure we have an object with a restoreSrc properties		
		if((typeof(theImg.YM) == 'object') && theImg.YM.restoreSrc)
		{
			// if there is a swap counter, decrement it.
			if(theImg.YM.swapCounter)
			{
				theImg.YM.set("swapCounter",theImg.YM.get("swapCounter")-1);
			}
			
			// if the swap counter is zero or nonexistant, restore the image
			// and set the restoreSrc and swapCounter parameters to null
			if(!theImg.YM.swapCounter || (theImg.YM.get("swapCounter") == 0))
			{
				theImg.src = theImg.YM.get("restoreSrc");
				theImg.YM.set("restoreSrc",null);
				theImg.YM.set("swapCounter",null);
			}
		}
	}
}	// end function YM_restoreImgs(imgName1,imgName2,imgName3,...)

