// IXF1.11 :: Image cross-fade// *****************************************************// DOM scripting by brothercake -- http://www.brothercake.com///******************************************************var Ixf = function(pictures) {//global object  this.clock = null;  this.count =  1;  this.counter = 0;  this.currentNumber = 0;/***************************************************************************** List the images that need to be cached*****************************************************************************/  var oThis = this;  oThis.imgs = pictures;  this.cacheImages = function () {	/*****************************************************************************	*****************************************************************************/	//cache the images	oThis.imgsLen = oThis.imgs.length;	oThis.cache = [];	for(var i=0; i<oThis.imgsLen; i++)	{		oThis.cache[i] = new Image;		oThis.cache[i].src = oThis.imgs[i];	}  }//crossfade setup function  this.crossfade = function () {	oThis.counter++;	oThis.currentNumber = (oThis.counter%(oThis.imgsLen));	//if the timer is not already going	if(oThis.clock == null)	{		//copy the image object		oThis.obj = arguments[0];        //copy the image src argument		if(typeof arguments[3] != 'undefined' && arguments[3] != '') {    		oThis.src = oThis.imgs[arguments[3]];	    } else {            oThis.src = oThis.imgs[oThis.currentNumber];	    }		//store the supported form of opacity		if(typeof oThis.obj.style.opacity != 'undefined')		{			oThis.type = 'w3c';		}		else if(typeof oThis.obj.style.MozOpacity != 'undefined')		{			oThis.type = 'moz';		}		else if(typeof oThis.obj.style.KhtmlOpacity != 'undefined')		{			oThis.type = 'khtml';		}		else if(typeof oThis.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			oThis.type = (oThis.obj.filters.length > 0 && typeof oThis.obj.filters.alpha == 'object' && typeof oThis.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';		}		else		{			oThis.type = 'none';		}		//change the image alt text if defined		if(typeof arguments[2] != 'undefined' && arguments[2] != '')		{			oThis.obj.alt = arguments[2];		}		//if any kind of opacity is supported		if(oThis.type != 'none')		{			//create a new image object and append it to body			//detecting support for namespaced element creation, in case we're in the XML DOM			oThis.newimg = document.getElementsByTagName('body')[0].appendChild((typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'img') : document.createElement('img'));			//set positioning classname			oThis.newimg.className = 'idupe';			//set src to new image src			oThis.newimg.src = oThis.src			//move it to superimpose original image			oThis.newimg.style.left = oThis.getRealPosition(oThis.obj, 'x') + 'px';			oThis.newimg.style.top = oThis.getRealPosition(oThis.obj, 'y') + 'px';			//copy and convert fade duration argument			var kk = 1;			if ( typeof arguments[1] != 'undefined' && arguments[1] != '')			  kk = arguments[1];			else			  kk = 1;			oThis.length = kk * 1000;			//create fade resolution argument as 20 steps per transition			oThis.resolution = kk * 22;			//start the timer			oThis.clock = setInterval(oThis.crossfadestep, oThis.length/oThis.resolution);		}		//otherwise if opacity is not supported		else		{			//just do the image swap			oThis.obj.src = oThis.src;		}	}  }//crossfade timer function  this.crossfadestep = function() {	//decrease the counter on a linear scale	oThis.count -= (1 / oThis.resolution);	//if the counter has reached the bottom	if(oThis.count < (1 / oThis.resolution))	{		//clear the timer		clearInterval(oThis.clock);		oThis.clock = null;		//reset the counter		oThis.count = 1;		//set the original image to the src of the new image		oThis.obj.src = oThis.src;	}	//set new opacity value on both elements	//using whatever method is supported	switch(oThis.type)	{		case 'ie' :			oThis.obj.filters.alpha.opacity = oThis.count * 100;			oThis.newimg.filters.alpha.opacity = (1 - oThis.count) * 100;			break;		case 'khtml' :			oThis.obj.style.KhtmlOpacity = oThis.count;			oThis.newimg.style.KhtmlOpacity = (1 - oThis.count);			break;		case 'moz' :			//restrict max opacity to prevent a visual popping effect in firefox			oThis.obj.style.MozOpacity = (oThis.count == 1 ? 0.9999999 : oThis.count);			oThis.newimg.style.MozOpacity = (1 - oThis.count);			break;		default :			//restrict max opacity to prevent a visual popping effect in firefox			oThis.obj.style.opacity = (oThis.count == 1 ? 0.9999999 : oThis.count);			oThis.newimg.style.opacity = (1 - oThis.count);	}	//now that we've gone through one fade iteration	//we can show the image that's fading in	oThis.newimg.style.visibility = 'visible';	//keep new image in position with original image	//in case text size changes mid transition or something	oThis.newimg.style.left = oThis.getRealPosition(oThis.obj, 'x') + 'px';	oThis.newimg.style.top = oThis.getRealPosition(oThis.obj, 'y') + 'px';	//if the counter is at the top, which is just after the timer has finished	if(oThis.count == 1)	{		//remove the duplicate image		oThis.newimg.parentNode.removeChild(oThis.newimg);	}  }//get real position method  this.getRealPosition = function() {	this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;	this.tmp = arguments[0].offsetParent;	while(this.tmp != null)	{		this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;		this.tmp = this.tmp.offsetParent;	}	return this.pos;  }}
