// --------------------------------------------------------------------------------
// Fades through a series of images defined in calling html page. 
//  In the calling page:
// 1: 	Define the reference arrIMAGES to use:
//			<SCRIPT Language='JavaScript'>
//			var arrIMAGES=new Array();
//			arrIMAGES[0]="image1.file;
//			arrIMAGES[1]="image2.file";
//			arrIMAGES[2]="image3.file";
//			  ...
//			arrIMAGES[N]="imageN.file";
//			</script>
//
// 2:	reference this js file:
//			<SCRIPT Language='JavaScript' src='fader.js'></script>
//
// 3:	place the arrIMAGES where you want them to appear with the ID's as:
//			<img id="image1" src="image1.file" height=200 style="position:absolute;filter:alpha(opacity=100);opacity: 1;">
//			<img id="image2" src="image1.file" height=200 style="position:absolute;filter:alpha(opacity=0);opacity: 0;">
//
// 4:   in <body> tag add:
//			<body onload="FNimageloop()" >
// --------------------------------------------------------------------------------

function getObj(name){
if (document.getElementById) { this.obj = document.getElementById(name); }
else if (document.all)       { this.obj = document.all[name];}
else if (document.layers)    { this.obj = document.layers[name];}
}

// --------------------------------------------------------------------------------
// Image pattern functions and variables for FADING in and out
// --------------------------------------------------------------------------------
var fadeSTEPS=30;												// fade flow
var timeout=3													// seconds between next image fade
var atIMG=0;													// image counter through arrIMAGES array
var fadeORDER=1													// 1=fade image1 to image2 or 2=image2 to image1
var fadeLOOP=0;													// fader loop step counter

// --------------------------------------------------------------------------------
function FNimageloop(){
fadeLOOP=0;
if (fadeORDER==1) {	FNfadepair("image1","image2");				// fading for image pair (image1 <-- image2)
			 	   	fadeORDER=2;
				  }			
else		 	  {	FNfadepair("image2","image1");				// fading for image pair (image2 <-- image1)
				  	fadeORDER=1;
				  }
atIMG=atIMG+1; 													// set next img for next time in
if (atIMG>=arrIMAGES.length) {atIMG=0;}						// loop the image array
setTimeout("FNimageloop()",timeout*1000);						// Set timer for next set fade
}


// --------------------------------------------------------------------------------
function FNfadepair(f1,f2) {
var fadeOUT=new getObj(f1);										// get the fade pair image objects (image1, image2)
var fadeIN =new getObj(f2);
					
if (fadeLOOP==0) {
	var nxtIMG=atIMG+1;											// get the next image to fadein
	if (nxtIMG>=arrIMAGES.length) {nxtIMG=0;}					// loop back to the 1st image
	fadeIN.obj.src            =arrIMAGES[nxtIMG];				// set src image for the fadeIN.
	fadeIN.obj.style.top      =fadeOUT.obj.style.top;			// ensure positions match	
	fadeIN.obj.style.left     =fadeOUT.obj.style.left;	
	fadeIN.obj.style.zIndex	  =3;
	fadeOUT.obj.style.zIndex  =2;
	fadeOUT.obj.style.opacity =1;								// first time in
	fadeOUT.obj.style.filter="alpha(opacity=100)";				// set the default opacities.
	}
if (fadeIN.obj.style.filter.length==0) {
	fadeIN.obj.style.opacity=0;
	fadeIN.obj.style.filter="alpha(opacity=0)";
	}


newopc	 =eval(fadeOUT.obj.style.opacity)-(1/fadeSTEPS);		// calculate new FADEOUT opacity
newfilter="alpha(opacity="+eval(100*newopc)+")";
fadeOUT.obj.style.opacity	=newopc;
fadeOUT.obj.style.filter	=newfilter;

newopc	 =eval(fadeIN.obj.style.opacity)+(1/fadeSTEPS);	 	    // calculate new FADEIN opacity
newfilter="alpha(opacity="+eval(100*newopc)+")";
fadeIN.obj.style.opacity	=newopc;
fadeIN.obj.style.filter		=newfilter;

if (fadeLOOP<=fadeSTEPS) { fadeLOOP=fadeLOOP+1;
				  		   setTimeout("FNfadepair('"+f1+"','"+f2+"')",20);
						 }
else					 { fadeLOOP=0;}	

}