﻿/*
This file controls the Heavy Oil slideshow on the bottom-center part of the homepage.
At least for now, the selection of photos in the slideshow is hard-coded in this file;
it's not read dynamically from a directory.
*/

// Heavy Oil Slideshow
//--------------------

var ho_photos_ary = new Array();
var ho_disappearingIndex;   // index in the array of the picture that is about to 
                            // disappear (or disappearing, fading out) at any given moment.
                            
var ho_appearingIndex;  // index in the array of the picture that is about to 
                        // appear (or appearing, fading in) at any given moment.

var ho_fadeOutTimer;    // rate at which the disappearing photo's opacity is changed when it's fading out.
var ho_fadeInTimer;     // rate at which the appearing photo's opacity is changed when it's fading in.

var ho_fadeOutID;   // the HTML ID representing the container of the disappearing photo
var ho_fadeInID;    // the HTML ID representing the container of the appearing photo

var ho_smoothOrder = 0;	//may be 0 or 1... changing this value reverses the order of the fading

var theBrowser = "";    //used below to detect which brower is being used by the visitor


initializeAllPhotosArrays();

/*
function startAllSlideshows()
{
    ho_startSmoothSlideshow();
}
*/

function initializeAllPhotosArrays()//This shouldn't be here. ho_initializePhotosArray should be called directly above
{
    //alert('Initializing all photo arrays');
    ho_initializePhotosArray();
}


/*
Fill the array with the file names of the pictures in the slideshow and assign fading order
*/
function ho_initializePhotosArray()
{
	ho_photos_ary[0] = new Image();
	ho_photos_ary[1] = new Image();
	ho_photos_ary[2] = new Image();
	ho_photos_ary[3] = new Image();
	
	ho_photos_ary[0].src="/webMod/images/slideshows/heavy-oil/ss_ho1.JPG";
	ho_photos_ary[1].src="/webMod/images/slideshows/heavy-oil/ss_ho2.JPG";
	ho_photos_ary[2].src="/webMod/images/slideshows/heavy-oil/ss_ho3.JPG";
	ho_photos_ary[3].src="/webMod/images/slideshows/heavy-oil/ss_ho4.JPG";

	//The above will be in a loop which reads the files in a specific folder.
	//Therefore, we'll need to check whether there's anything in the array after that
	//with something like: if(photos_ary.length > 1)
	//(the folder could be empty)

	ho_disappearingIndex = 0;
	ho_appearingIndex = 1;
}

//prepare the next picture in the slideshow
function ho_updateSlideshowIndex()
{
	//update the indices of the appearing and disappearing photos
	ho_disappearingIndex++;
	ho_appearingIndex++;

	if(ho_appearingIndex == ho_photos_ary.length)
	{
		ho_appearingIndex = 0;//wrap around for the appearing photo
	}
	
	if(ho_disappearingIndex == ho_photos_ary.length)
	{
		ho_disappearingIndex = 0;//wrap around for the disappearing photo
	}
}

//store the HTML ID representing the container of the picture that will fade out
function ho_setFadeOutID(theID)
{
	ho_fadeOutID = theID;
}

//store the HTML ID representing the container of the picture that will fade in
function ho_setFadeInID(theID)
{
	ho_fadeInID = theID;
}

/*
Fades one pair of pictures, prepares the next pair, sets a time delay and then calls itself
*/
function ho_startSmoothSlideshow()
{
    detectBrowser();
    
    document.getElementById("ho_topLayerPhoto").src = ho_photos_ary[ho_disappearingIndex].src;
	document.getElementById("ho_projShowCol").style.backgroundImage = "url("+ho_photos_ary[ho_appearingIndex].src+")";

    if(theBrowser == "Not IE")
    {
        document.getElementById("ho_topLayerPhoto").style.opacity = 1;
    }
    else
    {
        document.getElementById("ho_topLayerPhoto").filters.alpha.opacity = 100;
    }
	
    //Fade one pair of pictures
	if(ho_smoothOrder == 0)
	{
		ho_setFadeOutID('ho_topLayerPhoto'); 
		ho_fadeOut();
	}
	else
	{
    //
	}
	//prepare the next pair of picture to fade
	ho_updateSlideshowIndex();
	
	//set time delay and make recursive call
	setTimeout("ho_startSmoothSlideshow()",4000);
}

//Stop the timer that fades out a picture
function ho_stopFadingOut()
{
	if(ho_fadeOutTimer)
	clearTimeout(ho_fadeOutTimer);
}

//Stop the timer that fades in a picture
function ho_stopFadingIn()
{
	if(ho_fadeInTimer)
	clearTimeout(ho_fadeInTimer);
}


//fades out a picture
function ho_fadeOut()
{
    if(theBrowser == "Not IE")
    {
        //reduce opacity
		document.getElementById(ho_fadeOutID).style.opacity += 0.001;
		document.getElementById(ho_fadeOutID).style.opacity *= 0.9;        
		
		//if opacity is negligible
		var checkFF = document.getElementById(ho_fadeOutID).style.opacity;
		if(checkFF < 0.05)
		{
			//make the opacity equal to zero
			document.getElementById(ho_fadeOutID).style.opacity = 0;
			checkFF = 0;
			
			//stop the fade-out process
			ho_stopFadingOut();
			return;
		}
    }
    else
    {
        //reduce opacity   
		document.getElementById(ho_fadeOutID).filters.alpha.opacity += 0.001;
		document.getElementById(ho_fadeOutID).filters.alpha.opacity *= 0.9;
		
		//if opacity is negligible
		var checkIE = document.getElementById(ho_fadeOutID).filters.alpha.opacity;
		if(checkIE < 5)
		{
			//make the opacity equal to zero
			document.getElementById(ho_fadeOutID).filters.alpha.opacity = 0;
			checkIE = 0;
			
			//stop the fade-out process
			ho_stopFadingOut();
			return;
		}
        
    }
        //time delay and recursive call
		ho_fadeOutTimer = setTimeout("ho_fadeOut()",50);
}

//fades in a picture
function ho_fadeIn()
{
        /* For browsers other than Internet Explorer */
        //increase opacity
		document.getElementById(ho_fadeInID).style.opacity += 0.01;
		document.getElementById(ho_fadeInID).style.opacity *= 1.1;
		
		//if opacity is close to 100%
		var checkFF = document.getElementById(ho_fadeInID).style.opacity;
		if(checkFF > 0.99)
		{
		    //make the opacity equal to 100%
			document.getElementById(ho_fadeInID).style.opacity = 1;
			checkFF = 1;
			
			//stop the fade-in process
			ho_stopFadingIn();			
			return;
		}
		
		
		/* For Internet Explorer */
		//increase opacity
		document.getElementById(ho_fadeInID).filters.alpha.opacity += 1;//this one is different (not 0.001) on purpose
		document.getElementById(ho_fadeInID).filters.alpha.opacity *= 1.1;
		
		//if opacity is close to 100%
		var checkIE = document.getElementById(ho_fadeInID).filters.alpha.opacity;
		if(checkIE > 99)
		{
		    //make the opacity equal to 100%
			document.getElementById(ho_fadeInID).filters.alpha.opacity = 100;
			checkIE = 100;
			
			//stop the fade-in process
			ho_stopFadingIn();			
			return;
		}
		
		ho_fadeInTimer = setTimeout("ho_fadeIn()",50);
}


function ho_startSwapSlideshow()
{
    document.getElementById("ho_topLayerPhoto").src = ho_photos_ary[ho_disappearingIndex].src;
	document.getElementById("ho_projShowCol").style.backgroundImage = "";

//	document.getElementById("ho_topLayerPhoto").style.opacity = 1;
//	document.getElementById("ho_topLayerPhoto").filters.alpha.opacity = 100;

//	if(ho_smoothOrder == 0)
//	{
		ho_setFadeOutID('ho_topLayerPhoto'); 
//		ho_fadeOut();
//	}
//	else
//	{
    //
//	}
	ho_updateSlideshowIndex();
	setTimeout("ho_startSwapSlideshow()",4000);
}


function detectBrowser()
{
    if(navigator.appVersion.indexOf("MSIE") == -1)
    {
        theBrowser = "Not IE";
    }
    else
    {
        theBrowser = "IE";
    }
}