// JavaScript Document

//PRELOAD IMAGES
var img1=new Image();
var img2=new Image();
var img3=new Image();
img1.src="images/scroller/mainpage_splash1.jpg";
img2.src="images/scroller/mainpage_splash2.jpg";
img3.src="images/scroller/mainpage_splash3.jpg";
img3.src="images/scroller/mainpage_splash4.jpg";

//ARRAY OF IMAGES TO USE
var image_array=new Array();
image_array[0]="mainpage_splash1.jpg";
image_array[1]="mainpage_splash2.jpg";
image_array[2]="mainpage_splash3.jpg";
image_array[3]="mainpage_splash4.jpg";


//FUNCTIONALITY
var galleryTimer;
var fadeSteps=20;
var stepSpeed=25;
var picDuration=6000;
var blankDuration=100;

var fadeIncrement=1/fadeSteps;
var fadeLevel=1;
var currImage=1;
var imageAmount=4;
var imageRef;
var imageID="mainpage-image";
//Fade step function
function fadeStep(step,functionAfter){
	//Step the opacity
	fadeLevel-=fadeIncrement;
	imageRef.style.opacity=fadeLevel;
	imageRef.style.filter="alpha(opacity="+(fadeLevel*100)+")";
	//Determine if we need another step
	if(step<=fadeSteps){
		//If so, call myself again
		galleryTimer=setTimeout("fadeStep("+(step+1)+",\""+functionAfter+"\")",stepSpeed);
	}
	else{
		//If not, call following function
		galleryTimer=setTimeout(functionAfter,stepSpeed);
		step=0;
		if(fadeIncrement<0)fadeIncrement=(-fadeIncrement);
	}
}
//Start the fade to transparency
function slideShow(){
	imageRef=document.getElementById(imageID);
	//Start fade to transparency
	galleryTimer=setTimeout("fadeStep(1,\"fadeToView()\")",picDuration);
}
function getStarted(){
	imageRef=document.getElementById(imageID);
	//Start fade to transparency
	galleryTimer=setTimeout("fadeStep(1,\"fadeToView()\")",picDuration);
}
//Change the image (and link) and start the fade to opacity
function fadeToView(){
	//Change image
	imageRef.src="images/scroller/"+image_array[currImage];
	//Change image to visible
	imageRef.style.visibility="visible";
	//Start fade to opaque
	fadeIncrement=(-fadeIncrement);
	currImage++;
	if(currImage==imageAmount){
		currImage=0;
	}
	galleryTimer=setTimeout("fadeStep(1,\"slideShow()\")",blankDuration);
}

