// fbi - this is usually called once for each image availabe for fade loop
function fbi(d, i, to) {
	// d=the target DIV
	// i=the image being faded
	// to=an image reference from an array e.g. image1
	gd = d;	gi = i;
	if (document.getElementById(i).src.indexOf(eval(to+".src")) == -1) {
		so(0, i); document.getElementById(i).src = eval(to+".src");
		fes(i, 0, 100, 20);	 
	}
}

// fes - seems to trigger a controlled loop
function fes(i, a, z, n, zi,filetoload) {

	// i=the element being faded
	// a=number (0)
	// z=number (100)
	// n=number (20)
	fs = n;	fc = 0;
	fa = (a - z) / fs;
	if (filetoload) {
		ft = setInterval("fe('"+i+"',"+zi+",'"+filetoload+"')", 50);
	}

	else {
		ft = setInterval("fe('"+i+"',"+zi+")", 50);
	}
	
	// fe('fade_div_id',1);
	// fe('fade_div_id',1,filetoload);
}

function fes2(i2, a2, z2, n2, zi2,filetoload2) {
	fs2 = n2;	fc2 = 0;
	fa2 = (a2 - z2) / fs2;
	if (filetoload2) {
		ft2 = setInterval("fe2('"+i2+"',"+zi2+",'"+filetoload2+"')", 50);
	}

	else {
		ft2 = setInterval("fe2('"+i2+"',"+zi2+")", 50);
	}
	
	// fe('fade_div_id',1);
	// fe('fade_div_id',1,filetoload);
}

function fesf(i, a, z, n,filetoload) {
	fes(i, a, z, n, "1",filetoload);
}

function fesr(i, a, z, n) {
	fes(i, a, z, n, "-1");
}

function fe(i,zi,filetoload,reponse) {
	
	// i=the image being faded
	fc++;
	// fc seems to increase form 0
	if (fa < 0) 
		so(Math.abs(fc * fa), i);
		// fa
	else 
		so(100 - (fc * fa), i);
	
	if (fc == fs) {
		document.getElementById(i).style.zIndex=zi;
		clearInterval(ft);
		if (filetoload=="cacheit") {
			document.getElementById(i).innerHTML = document.getElementById('cachepacket').innerHTML;
			fes(i, 0, 100, 20);
		}
		else if (filetoload) {
			loadXMLDoc(filetoload, i,'fesr');
			//setTimeout("fesr('"+i+"',0,100,5)",200);
			//fesr(i,0,100,5);
		}
		// document.getElementById(gd).style.backgroundImage = "url(" + document.getElementById(gi).src + ")";
	}
}

function fe2(i2,zi2,filetoload2,reponse2) {
	fc2++;
	if (fa2 < 0) 
		so2(Math.abs(fc2 * fa2), i2);
	else 
		so2(100 - (fc2 * fa2), i2);
	
	if (fc2 == fs2) {
		clearInterval(ft2);
		document.getElementById(i2).style.display="none";
	}
}

// so - seems to set the opacity of an element to 0
function so(op, i) {
	// op=number (0)
	// i=the image being faded
	var o = document.getElementById(i).style;
	if (navigator.userAgent.indexOf("Firefox") != -1) {
		if (op == 100) { op = 99.999; }
	}
	o.filter = "alpha(opacity=" + op + ")";
	o.KhtmlOpacity = (op / 100); 
	o.MozOpacity = (op / 100);
	o.opacity = (op / 100);
}

function so2(op2, i2) {
	var o2 = document.getElementById(i2).style;
	if (navigator.userAgent.indexOf("Firefox") != -1) {
		if (op2 == 100) { op2 = 99.999; }
	}
	o2.filter = "alpha(opacity=" + op2 + ")";
	o2.KhtmlOpacity = (op2 / 100); 
	o2.MozOpacity = (op2 / 100);
	o2.opacity = (op2 / 100);
}

// looping crossfade function \\
/* function fadeORIG() { */
/*    i++; */
/*    fbi('homepagefader', 'fademe', 'image'+i); */
/*    if(i == n) i = 0; */
/*    setTimeout("fade()",10000); */
/* } */

// key IS fes

