var Arr2 = { 'clock' : null, 'fade' : true, 'count' : 1 }
iPad=0;
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {iPad=1;}

function Xfade()
{
	//if the timer is not already going
	if (iPad==1) {Arr2.obj = arguments[0]; Arr2.src = arguments[1]; Arr2.obj.src = Arr2.src;} else {
	if(Arr2.clock == null)
	{
		
		Arr2.obj = arguments[0];
		Arr2.src = arguments[1];
		
			//faid speed and resolution
			Arr2.length = 100;
			Arr2.resolution = 50;
			Arr2.clock = setInterval('Arr2.Xfade()', Arr2.length/Arr2.resolution);
	}
	}
};


//Xfade timer function
Arr2.Xfade = function()
{
	//increase or reduce the counter on an exponential scale
	Arr2.count = (Arr2.fade) ? Arr2.count * 0.9 : (Arr2.count * (1/0.9)); 
	
	//if the counter has reached the bottom
	if(Arr2.count < (1 / Arr2.resolution))
	{
		clearInterval(Arr2.clock);
		Arr2.clock = null;

		//do the image swap
		Arr2.obj.src = Arr2.src;

		//reverse the fade direction flag
		Arr2.fade = false;
		
		//restart the timer
		Arr2.clock = setInterval('Arr2.Xfade()', Arr2.length/Arr2.resolution);

	}
	
	//if the counter has reached the top
	if(Arr2.count > (1 - (1 / Arr2.resolution)))
	{
		clearInterval(Arr2.clock);
		Arr2.clock = null;

		//reset the fade direction flag
		Arr2.fade = true;
		
		//reset the counter
		Arr2.count = 1;
		
		//Xfade1();
	}

	//set new opacity value on element
	Arr2.obj.style.opacity = Arr2.count;
	Arr2.obj.style.MozOpacity = Arr2.count;
	Arr2.obj.style.filter = 'alpha(opacity=' + (Arr2.count*100) + ')';
};
