
/*
 * This is just a simple but powerful function that makes image swapping more conveninent
 * The Initial Developer of the Original Code is Leon S. Koshelev <leon_koshelev@yahoo.com>
 * Contributor(s): Andy V. Ivanov <iav@webmaster.spb.ru>
 * Version 1.1 public beta 27/08/01 PL1 27/08/01
 * Visit http://www.web-master.spb.ru/free_lib/ for the latest version of this software.
 * Copyright (c) 2001 Leon S. Koshelev, Web-Master Co., Saint-Petersburg, Russia. All Rights Reserved.
 * This library is opensource software and distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
 * Permission to use, copy, modify, and distribute this software for any purposes and without fee is hereby granted provided that this copyright notice appears in all copies.
 */

//-----------------------------------------------------------------------

// This script still work in Navigator 3+, Explorer 4+, Opera 5+.

/*
Example of use:

 <Script Language="JavaScript" Src="imgSwap.js"></Script>

 <A HRef="javascript:void(0)" onMouseOver="imgSwap('prev')" onMouseOut="imgSwap('prev')">
	<Img Name=prev Src="images/prev0.jpg" LowSrc="images/prev1.jpg" Border=0
		onLoad="imgPreload(this.name)"></A>

*/

//-----------------------------------------------------------------------

function imgSwap(imgName, winObj) // this function does all
{
	var obj = ( winObj!=null ? winObj : self ) . document[imgName];

	if (!obj.tumbler)
	{
		obj.defsrc=obj.src; obj.tumbler=false;
	}

	with(obj)
	{
		// if .lowsrc exists, if tumbler is off, sets the .src property of obj to .lowsrc
		// otherwise, sets the .src property of obj to .defsrc
		// if .lowsrc is not exists, do nothing
		if (lowsrc && complete) src = ( ( tumbler=!tumbler ) ? lowsrc : defsrc );
	}

	return (true);
}

function imgPreload(imgName, winObj) // new
{
	var obj = ( winObj!=null ? winObj : self ) . document[imgName];

	obj.onload = new Function('return false');

	var tmp = new Image(); tmp.src=obj.lowsrc; obj.lowsrc=tmp.src;

	obj.src=obj.src;
}

