

//set location of images
var frontImgBase = "/homeimages/";
//set image filenames
var frontImgs = Array("IMG_0052-2x.jpg","IMG_0109 copy 2ax.jpg","IMG_1700x.jpg","man2.jpg","IMG_5845x.jpg","IMG_6155x.jpg","bike2.jpg","small_IMG_0127.jpg");
//time to switch
frontChangeTime = 4100;
//opacity amount
frontChangeBy = 0.1;
//opacity timeout
frontChangeEvery = 100;

// NON CONFIGURABLE
//Preload image array
var frontPreload = Array();
//set current counter to 1 (ie 0 in the array)
var frontShow = 1;
//get containing div
var frontStage;
//set timeouts
var FrontT1;
var FrontT2;
var INT;
//values used to fade
FrontOutVal = 1;
FrontInVal = 0;

//shifting values
var secondImgTop = "-440px";



function startFrontShow()
				{
								
					//set switch period
					setInterval("loadNextFrontImg()",frontChangeTime);
					//get container div;
					frontStage = document.getElementById("front_slideshow");
					//preload images	
					for(i = 0; i < frontImgs.length; i ++){
						//create image
						frontPreload[i] = new Image();
						//set src to preload
						frontPreload[i].src = frontImgBase + frontImgs[i];
					
					}
				}
				
				
function loadNextFrontImg(){

	//get first image (loaded in html)
	if(document.getElementById("slideshow1")){
		var s1 = document.getElementById("slideshow1");
	}
	//try get the second "hidden" image
	if(document.getElementById("slideshow2"))
	{
		var s2 = document.getElementById("slideshow2");
		//set to next image
		s2.src = frontImgBase + frontImgs[frontShow - 1];
		//set invisable jic
		s2.style.opacity = "0";
		s2.style.filter = "alpha(opacity:0)";
	}
	//otherwise create it
	else{
		var s2 = document.createElement("img");
		//set the vclass
		s2.className = "slideshow_img";
		//give id
		s2.id = "slideshow2";
		//set to next image
		s2.src = frontImgBase + frontImgs[frontShow - 1];
		//set position
		s2.style.position = "relative";
		s2.style.top = secondImgTop;"  //-440px";
		s2.style.left = "0px";
		//set invisable
		s2.style.opacity = "0";
		s2.style.filter = "alpha(opacity:0)";
		//add it to the satge
		frontStage.appendChild(s2);
		
	}
	//increment the image count
	//if last image has been shown
	if(frontShow == frontImgs.length){
		//start again
		frontShow = 1;
	}
	//otherwise goto next image
	else{
		frontShow++;
	}
	
	//now fade in slide 2
	fadeOutFront(s1.id,s2.id);
	fadeInFront(s1.id,s2.id);
	//swicth the ids
	//FrontSwicthId(s1.id,s2.id);
}



function fadeOutFront(frontId,frontId2){
	clearTimeout(FrontT1);
	var front1 = document.getElementById(frontId)
	//if it is not faded
	if(FrontOutVal  > 0){
		//get new value
		var newFront = FrontOutVal - frontChangeBy;
		FrontOutVal = newFront;
		//set opacities
		front1.style.opacity = FrontOutVal;
		front1.style.filter = "alpha(opacity:" + (FrontOutVal * 100) + ")";
		//set loop
		FrontT1 = setTimeout("fadeOutFront('" + frontId + "','"+ frontId2 + "')",frontChangeEvery);
	}
	else
	{	
		//reset
		FrontOutVal = 1;
	}
	
}


function fadeInFront(frontId,frontId2){
	clearTimeout(FrontT2);
	var front2 = document.getElementById(frontId2)

	//if it is not faded
	if(FrontInVal  < 1){
	//alert("called");
		//get new value
		var newFront2 = FrontInVal + frontChangeBy;
		FrontInVal = newFront2;
		//set opacities
		front2.style.opacity = FrontInVal;
		front2.style.filter = "alpha(opacity:" + (FrontInVal * 100) + ")";
		//set loop
		FrontT2 = setTimeout("fadeInFront('" + frontId + "','"+ frontId2 + "')",frontChangeEvery);
	}
	else
	{	
		//reset
		FrontInVal = 0;
		FrontSwicthId(frontId,frontId2);
	}
	
}



function FrontSwicthId(first,second){
	//get images
	var switch1 = document.getElementById(first);
	var switch2 = document.getElementById(second);
	
	
	//switch ids
	switch1.id = second;
	switch2.id = first;
}

