//PHOTO SLIDESHOW SCRIPT FILE

//Current option to start with *************************************************************
currentIndx=1;


//Variables for SlideShow Timer
var delay3 = 0;


//This function calls the SlideShow after a delay *************************************************************
function delaySS() {
	delay3 = setTimeout('runSlideShow()', SlideShowSpeed);
}


//This is for pre-loading the images *************************************************************
imagesPreloaded = new Array()
for (var i = 1; i < photo.length ; i++) 
{
	imagesPreloaded[i] = new Image(480,270)
imagesPreloaded[i].src=photo[i]
}

//Function that is called by the clickable links to change all parameters *************************************************************
function changeALL(value){

	document.getElementById('photo').src = "/television/specials/greenbuilders/slideshow/background.jpg";
	changeOpac(100, 'photo');
	document.getElementById('photos').style.backgroundImage = "url(" + imagesPreloaded[currentIndx].src + ")";
 
    var speed = Math.round(300 / 100); 
    var timer = 0;
	for(var i = 100; i >= 0; i--) { 
        setTimeout("changeOpac(" + i + ",'" + 'photo' + "')",(timer * speed)); 
        timer++; } 

document.getElementById('description').innerHTML=description[value]
}

//This function loads up the first array option *************************************************************
function showOne() {
document.getElementById('photo').src=imagesPreloaded[currentIndx].src
document.getElementById('description').innerHTML=description[currentIndx];
}


//This tells the page to call this function when loaded *************************************************************
window.onload=function(){
//blendimage('photos', 'photoname', imagesPreloaded[currentIndx].src, 600);
showOne();
delaySS();
}


//This function is for the automatic slideshow (1000 = 1 second) *************************************************************


//Fade function *************************************************************

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 10000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

function runSlideShow(){

document.getElementById('photo').src = imagesPreloaded[currentIndx].src;
changeOpac(100, 'photo');

if (currentIndx<imagesPreloaded.length-1){
currentIndx=currentIndx+1
}
else {
 currentIndx=1
}	

document.getElementById('photos').style.backgroundImage = "url(" + imagesPreloaded[currentIndx].src + ")";
 
    var speed = Math.round(300 / 100); 
    var timer = 0;
	for(var i = 100; i >= 0; i--) { 
        setTimeout("changeOpac(" + i + ",'" + 'photo' + "')",(timer * speed)); 
        timer++; } 

document.getElementById('description').innerHTML=description[currentIndx];
delay3 = setTimeout('runSlideShow()', SlideShowSpeed);
}



//Function to stop slide show *************************************************************
function stopSS() {
	if(delay3) {
      clearTimeout(delay3);
      timerID  = 0;
}}


//change the opacity for different browsers ********************************************************
function changeOpac(opacity, id) { 
	var object = document.getElementById(id).style; 
    object.opacity = (opacity / 101); 
    object.MozOpacity = (opacity / 101); 
    object.KhtmlOpacity = (opacity / 101); 
    object.filter = "alpha(opacity=" + opacity + ")";
} 