﻿// Oil & Gas Slideshow
//--------------------

var og_photos_ary = new Array();
var og_disappearingIndex;
var og_appearingIndex;

var og_curSrc;
var og_smoothTimer;
var og_fadeOutTimer;
var og_fadeInTimer;

var og_fadeOutID;
var og_fadeInID;

var og_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();

og_curSrc = og_photos_ary[0].src;

function startAllSlideshows()
{
    og_startSmoothSlideshow();
}

function initializeAllPhotosArrays()
{
    //alert('Initializing all photo arrays');
    og_initializePhotosArray();
}

function og_initializePhotosArray()
{
	og_photos_ary[0] = new Image();
	og_photos_ary[1] = new Image();
	og_photos_ary[2] = new Image();
	og_photos_ary[3] = new Image();
	
	og_photos_ary[0].src="/webMod/images/slideshows/oil-gas/ss_og1.JPG";
	og_photos_ary[1].src="/webMod/images/slideshows/oil-gas/ss_og2.JPG";
	og_photos_ary[2].src="/webMod/images/slideshows/oil-gas/ss_og3.JPG";
	og_photos_ary[3].src="/webMod/images/slideshows/oil-gas/ss_og4.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)

	og_disappearingIndex = 0;
	og_appearingIndex = 1;
}

function og_updateSlideshowIndex()
{
	og_disappearingIndex++;
	og_appearingIndex++;


	if(og_appearingIndex == og_photos_ary.length)
	{
		og_appearingIndex = 0;
	}//wrap around for the disappearing photo
	
	if(og_disappearingIndex == og_photos_ary.length)
	{
		og_disappearingIndex = 0;
	}
}


function og_setFadeOutID(theID)
{
//		alert("og_fadeOutID = "+og_fadeOutID);
	og_fadeOutID = theID;
}

function og_setFadeInID(theID)
{
//	alert("og_fadeInID = "+og_fadeInID);
	og_fadeInID = theID;
}

function og_startSmoothSlideshow()
{
    detectBrowser();
    
    document.getElementById("og_topLayerPhoto").src = og_photos_ary[og_disappearingIndex].src;
	document.getElementById("og_projShowCol").style.backgroundImage = "url("+og_photos_ary[og_appearingIndex].src+")";

    if(theBrowser == "Not IE")
    {
        document.getElementById("og_topLayerPhoto").style.opacity = 1;
    }
    else
    {
        document.getElementById("og_topLayerPhoto").filters.alpha.opacity = 100;
    }
	

	if(og_smoothOrder == 0)
	{
		og_setFadeOutID('og_topLayerPhoto'); 
		og_fadeOut();
	}
	else
	{
    //
	}
	og_updateSlideshowIndex();
	setTimeout("og_startSmoothSlideshow()",4000);
}


function og_stopSmoothSlideshow()
{
	if(og_smoothTimer)
	clearTimeout(og_smoothTimer);	
}


function og_stopFadingOut()
{
	if(og_fadeOutTimer)
	clearTimeout(og_fadeOutTimer);
}

function og_stopFadingIn()
{
	if(og_fadeInTimer)
	clearTimeout(og_fadeInTimer);
}



function og_fadeOut()
{
    if(theBrowser == "Not IE")
    {
		document.getElementById(og_fadeOutID).style.opacity += 0.001;
		document.getElementById(og_fadeOutID).style.opacity *= 0.9;        
		
		var checkFF = document.getElementById(og_fadeOutID).style.opacity;
		if(checkFF < 0.05)
		{
			//alert("stopfadingout FF");
			document.getElementById(og_fadeOutID).style.opacity = 0;
			checkFF = 0;
			og_stopFadingOut();
			return;
		}
    }
    else
    {
		document.getElementById(og_fadeOutID).filters.alpha.opacity += 0.001;
		document.getElementById(og_fadeOutID).filters.alpha.opacity *= 0.9;
		var checkIE = document.getElementById(og_fadeOutID).filters.alpha.opacity;
		if(checkIE < 5)
		{
			//alert("stopfadingout IE");
			document.getElementById(og_fadeOutID).filters.alpha.opacity = 0;
			checkIE = 0;
			og_stopFadingOut();
			return;
		}
        
    }
		og_fadeOutTimer = setTimeout("og_fadeOut()",50);
}


function og_fadeIn()
{
        if(theBrowser == "Not IE")
        {
		    document.getElementById(og_fadeInID).style.opacity += 0.01;
		    document.getElementById(og_fadeInID).style.opacity *= 1.1;
		    var checkFF = document.getElementById(og_fadeInID).style.opacity;
		    if(checkFF > 0.99)
		    {
			    document.getElementById(og_fadeInID).style.opacity = 1;
			    checkFF = 1;
			    og_stopFadingIn();			
			    return;
		    }
        }
        else
        {
            document.getElementById(og_fadeInID).filters.alpha.opacity += 1;//this one is different (not 0.001) on purpose
		    document.getElementById(og_fadeInID).filters.alpha.opacity *= 1.1;
		    var checkIE = document.getElementById(og_fadeInID).filters.alpha.opacity;
		    if(checkIE > 99)
		    {
    			document.getElementById(og_fadeInID).filters.alpha.opacity = 100;
			    checkIE = 100;
			    og_stopFadingIn();			
			    return;
		    }
        }
		
		og_fadeInTimer = setTimeout("og_fadeIn()",50);
}

function og_startSwapSlideshow()
{
    document.getElementById("og_topLayerPhoto").src = og_photos_ary[og_disappearingIndex].src;
	document.getElementById("og_projShowCol").style.backgroundImage = "";

	og_setFadeOutID('og_topLayerPhoto'); 

	og_updateSlideshowIndex();
	setTimeout("og_startSwapSlideshow()",4000);
}


function detectBrowser()
{
    if(navigator.appVersion.indexOf("MSIE") == -1)
    {
        theBrowser = "Not IE";
    }
    else
    {
        theBrowser = "IE";
    }
}