//	Slideshow script


//Images to be used in slideshow
//	More images may be added to the slideshow by simply adding elements to this array
imgArray = new Array();
imgArray[0] = 'images/custom/home_img3.jpg';
imgArray[1] = 'images/custom/home_img.jpg';
imgArray[2] = 'images/custom/home_img2.jpg';


// Preload the images
var len = imgArray.length;
var preLoad = new Array();

for(i = 0; i < len; i++)
{
	preLoad[i] = new Image(100, 100);
	preLoad[i].src = imgArray[i];
}

//Duration each image will show before transition
slideShowSpeed = 4000;


//Current position in the array.
currentPos = 0;

// method to start/run the slideshow
function runSlideShow() {
	
	//increase the current position each time this method is called. 
	//	the '%imgArray.length' keeps the current position within the bounds of the array.
	currentPos = ++currentPos%imgArray.length;
	
	//call blendimage function. 
	//	1st argument = id of 1st div tag (current image)
	//	2nd argument = id of 2nd div tag (for the new image)  
	//	3rd argument = path of new image - from the array.
	//	4th argument = duration of the transition
	blendimage('main-banner','main-banner2',imgArray[currentPos],700);
	
    t = setTimeout('runSlideShow()', slideShowSpeed);
}


function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);	/* CSS Compliant style */
	object.MozOpacity = (opacity / 100);	/* Legacy Mozilla style */
	object.KhtmlOpacity = (opacity / 100);	
	object.filter = "alpha(opacity=" + opacity + ")";  /* IE style */
}

//parameters:  divid = id of 1st div, imageid = id of 2nd div, imagefile = path of new image, millisec = transition duration
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = document.getElementById(imageid).style.backgroundImage;
		
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).style.backgroundImage = "url(" + imagefile + ")";

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}
