var Arr = { 'clock' : null, 'fade' : true, 'count' : 1 }
Arr.imgs = ['01','02','03','04','05','06','07','08'];
index=1;


//cache the images
Arr.imgsLen = Arr.imgs.length;
Arr.cache = [];
for(var i=0; i<Arr.imgsLen; i++)
{
	Arr.cache[i] = new Image;
	Arr.cache[i].src = 'fade/'+Arr.imgs[i]+'.jpg';
}

function Xfade1()
{
	name1=Arr.imgs[index];
	setTimeout("Xfade(document.getElementById('img'), 'fade/'+name1+'.jpg')", 3000);
	index++;
	if (index>=Arr.imgs.length) {index=0;};
}


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


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

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

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

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

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

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


