﻿// Heavy Oil Slideshow
//--------------------

var ho_photos_ary = new Array();
var ho_disappearingIndex;
var ho_appearingIndex;

var ho_curSrc;
var ho_smoothTimer;
var ho_fadeOutTimer;
var ho_fadeInTimer;

var ho_fadeOutID;
var ho_fadeInID;

var ho_smoothOrder = 0;	//may be 0 or 1

var theBrowser = "";

//should initializeAllPhotosArrays be declared and called in this file? maybe not. Looks like it should be declared or imitated in index.htm
initializeAllPhotosArrays();

ho_curSrc = ho_photos_ary[0].src;

function startAllSlideshows()
{
    ho_startSmoothSlideshow();
}

function initializeAllPhotosArrays()
{
    //alert('Initializing all photo arrays');
    ho_initializePhotosArray();
}

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;
}

function ho_updateSlideshowIndex()
{
	ho_disappearingIndex++;
	ho_appearingIndex++;


	if(ho_appearingIndex == ho_photos_ary.length)
	{
		ho_appearingIndex = 0;
	}//wrap around for the disappearing photo
	
	if(ho_disappearingIndex == ho_photos_ary.length)
	{
		ho_disappearingIndex = 0;
	}
}


function ho_setFadeOutID(theID)
{
//		alert("ho_fadeOutID = "+ho_fadeOutID);
	ho_fadeOutID = theID;
}

function ho_setFadeInID(theID)
{
//	alert("ho_fadeInID = "+ho_fadeInID);
	ho_fadeInID = theID;
}

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;
    }
	

	if(ho_smoothOrder == 0)
	{
		ho_setFadeOutID('ho_topLayerPhoto'); 
		ho_fadeOut();
	}
	else
	{
    //
	}
	ho_updateSlideshowIndex();
	setTimeout("ho_startSmoothSlideshow()",4000);
}

/*************************/

function ho_stopSmoothSlideshow()
{
	if(ho_smoothTimer)
	clearTimeout(ho_smoothTimer);	
}


function ho_stopFadingOut()
{
	if(ho_fadeOutTimer)
	clearTimeout(ho_fadeOutTimer);
}

function ho_stopFadingIn()
{
	if(ho_fadeInTimer)
	clearTimeout(ho_fadeInTimer);
}


function ho_fadeOut()
{
    if(theBrowser == "Not IE")
    {
		document.getElementById(ho_fadeOutID).style.opacity += 0.001;
		document.getElementById(ho_fadeOutID).style.opacity *= 0.9;        
		
		var checkFF = document.getElementById(ho_fadeOutID).style.opacity;
		if(checkFF < 0.05)
		{
			//alert("stopfadingout FF");
			document.getElementById(ho_fadeOutID).style.opacity = 0;
			checkFF = 0;
			ho_stopFadingOut();
			return;
		}
    }
    else
    {
		document.getElementById(ho_fadeOutID).filters.alpha.opacity += 0.001;
		document.getElementById(ho_fadeOutID).filters.alpha.opacity *= 0.9;
		var checkIE = document.getElementById(ho_fadeOutID).filters.alpha.opacity;
		if(checkIE < 5)
		{
			//alert("stopfadingout IE");
			document.getElementById(ho_fadeOutID).filters.alpha.opacity = 0;
			checkIE = 0;
			ho_stopFadingOut();
			return;
		}
        
    }
		ho_fadeOutTimer = setTimeout("ho_fadeOut()",50);
}
/******************************/

function ho_fadeIn()
{
		document.getElementById(ho_fadeInID).style.opacity += 0.01;
		document.getElementById(ho_fadeInID).style.opacity *= 1.1;
		var checkFF = document.getElementById(ho_fadeInID).style.opacity;
		if(checkFF > 0.99)
		{
			document.getElementById(ho_fadeInID).style.opacity = 1;
			checkFF = 1;
			ho_stopFadingIn();			
			return;
		}
		
		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;
		var checkIE = document.getElementById(ho_fadeInID).filters.alpha.opacity;
		if(checkIE > 99)
		{
			document.getElementById(ho_fadeInID).filters.alpha.opacity = 100;
			checkIE = 100;
			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";
    }
}