// isf31.11 :: Image swap-fade // *****************************************************// DOM scripting by brothercake -- http://www.brothercake.com///******************************************************//global objectvar isf3 = { 'clock' : null, 'fade' : true, 'count' : 1 }/*******************************************************/***************************************************************************** List the images that need to be cached*****************************************************************************/isf3.imgs = [	'buttons/udm4-whitebutton88x31.gif',	'buttons/udm4-greenbutton88x31.gif',	'buttons/udm4-purplebutton88x31.gif'	];/**********************************************************************************************************************************************************///cache the imagesisf3.imgsLen = isf3.imgs.length;isf3.cache = [];for(var i=0; i<isf3.imgsLen; i++){	isf3.cache[i] = new Image;	isf3.cache[i].src = isf3.imgs[i];}//swapfade3 setup functionfunction swapfade3(){	//if the timer is not already going	if(isf3.clock == null)	{		//copy the image object 		isf3.obj = arguments[0];				//copy the image src argument 		isf3.src = arguments[1];				//store the supported form of opacity		if(typeof isf3.obj.style.opacity != 'undefined')		{			isf3.type = 'w3c';		}		else if(typeof isf3.obj.style.MozOpacity != 'undefined')		{			isf3.type = 'moz';		}		else if(typeof isf3.obj.style.KhtmlOpacity != 'undefined')		{			isf3.type = 'khtml';		}		else if(typeof isf3.obj.filters == 'object')		{			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)			//then the returned value type, which should be a number, but in mac/ie5 is an empty string			isf3.type = (isf3.obj.filters.length > 0 && typeof isf3.obj.filters.alpha == 'object' && typeof isf3.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';		}		else		{			isf3.type = 'none';		}				//change the image alt text if defined		if(typeof arguments[3] != 'undefined' && arguments[3] != '')		{			isf3.obj.alt = arguments[3];		}				//if any kind of opacity is supported		if(isf3.type != 'none')		{			//copy and convert fade duration argument 			//the duration specifies the whole transition			//but the swapfade3 is two distinct transitions			isf3.length = parseInt(arguments[2], 10) * 500;						//create fade resolution argument as 20 steps per transition			//again, split for the two distrinct transitions			isf3.resolution = parseInt(arguments[2], 10) * 10;						//start the timer			isf3.clock = setInterval('isf3.swapfade3()', isf3.length/isf3.resolution);		}				//otherwise if opacity is not supported		else		{			//just do the image swap			isf3.obj.src = isf3.src;		}			}};//swapfade3 timer functionisf3.swapfade3 = function(){	//increase or reduce the counter on an exponential scale	isf3.count = (isf3.fade) ? isf3.count * 0.9 : (isf3.count * (1/0.9)); 		//if the counter has reached the bottom	if(isf3.count < (1 / isf3.resolution))	{		//clear the timer		clearInterval(isf3.clock);		isf3.clock = null;		//do the image swap		isf3.obj.src = isf3.src;		//reverse the fade direction flag		isf3.fade = false;				//restart the timer		isf3.clock = setInterval('isf3.swapfade3()', isf3.length/isf3.resolution);	}		//if the counter has reached the top	if(isf3.count > (1 - (1 / isf3.resolution)))	{		//clear the timer		clearInterval(isf3.clock);		isf3.clock = null;		//reset the fade direction flag		isf3.fade = true;				//reset the counter		isf3.count = 1;	}	//set new opacity value on element	//using whatever method is supported	switch(isf3.type)	{		case 'ie' :			isf3.obj.filters.alpha.opacity = isf3.count * 100;			break;					case 'khtml' :			isf3.obj.style.KhtmlOpacity = isf3.count;			break;					case 'moz' : 			//restrict max opacity to prevent a visual popping effect in firefox			isf3.obj.style.MozOpacity = (isf3.count == 1 ? 0.9999999 : isf3.count);			break;					default : 			//restrict max opacity to prevent a visual popping effect in firefox			isf3.obj.style.opacity = (isf3.count == 1 ? 0.9999999 : isf3.count);	}};