﻿// Modular Slideshow
//--------------------

var mo_photos_ary = new Array();
var mo_disappearingIndex;
var mo_appearingIndex;

var mo_curSrc;
var mo_smoothTimer;
var mo_fadeOutTimer;
var mo_fadeInTimer;

var mo_fadeOutID;
var mo_fadeInID;

var mo_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();

mo_curSrc = mo_photos_ary[0].src;

function startAllSlideshows()
{
    mo_startSmoothSlideshow();
}

function initializeAllPhotosArrays()
{
    //alert('Initializing all photo arrays');
    mo_initializePhotosArray();
}

function mo_initializePhotosArray()
{
	mo_photos_ary[0] = new Image();
	mo_photos_ary[1] = new Image();
	mo_photos_ary[2] = new Image();
	mo_photos_ary[3] = new Image();
	mo_photos_ary[4] = new Image();
	
	mo_photos_ary[0].src="/webMod/images/slideshows/modular/ss_mo1.JPG";
	mo_photos_ary[1].src="/webMod/images/slideshows/modular/ss_mo2.JPG";
	mo_photos_ary[2].src="/webMod/images/slideshows/modular/ss_mo3.JPG";
	mo_photos_ary[3].src="/webMod/images/slideshows/modular/ss_mo4.JPG";
	mo_photos_ary[4].src="/webMod/images/slideshows/modular/ss_mo5.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)

	mo_disappearingIndex = 0;
	mo_appearingIndex = 1;
}

function mo_updateSlideshowIndex()
{
	mo_disappearingIndex++;
	mo_appearingIndex++;


	if(mo_appearingIndex == mo_photos_ary.length)
	{
		mo_appearingIndex = 0;
	}//wrap around for the disappearing photo
	
	if(mo_disappearingIndex == mo_photos_ary.length)
	{
		mo_disappearingIndex = 0;
	}
}


function mo_setFadeOutID(theID)
{
//		alert("mo_fadeOutID = "+mo_fadeOutID);
	mo_fadeOutID = theID;
}

function mo_setFadeInID(theID)
{
//	alert("mo_fadeInID = "+mo_fadeInID);
	mo_fadeInID = theID;
}


function mo_startSmoothSlideshow()
{
    detectBrowser();
    
    document.getElementById("mo_topLayerPhoto").src = mo_photos_ary[mo_disappearingIndex].src;
	document.getElementById("mo_projShowCol").style.backgroundImage = "url("+mo_photos_ary[mo_appearingIndex].src+")";

    if(theBrowser == "Not IE")
    {
        document.getElementById("mo_topLayerPhoto").style.opacity = 1;
    }
    else
    {
        document.getElementById("mo_topLayerPhoto").filters.alpha.opacity = 100;
    }
	

	if(mo_smoothOrder == 0)
	{
		mo_setFadeOutID('mo_topLayerPhoto'); 
		mo_fadeOut();
	}
	else
	{
    //
	}
	mo_updateSlideshowIndex();
	setTimeout("mo_startSmoothSlideshow()",4000);
}
/********************/

function mo_stopSmoothSlideshow()
{
	if(mo_smoothTimer)
	clearTimeout(mo_smoothTimer);	
}


function mo_stopFadingOut()
{
	if(mo_fadeOutTimer)
	clearTimeout(mo_fadeOutTimer);
}

function mo_stopFadingIn()
{
	if(mo_fadeInTimer)
	clearTimeout(mo_fadeInTimer);
}


function mo_fadeOut()
{
    if(theBrowser == "Not IE")
    {
		document.getElementById(mo_fadeOutID).style.opacity += 0.001;
		document.getElementById(mo_fadeOutID).style.opacity *= 0.9;        
		
		var checkFF = document.getElementById(mo_fadeOutID).style.opacity;
		if(checkFF < 0.05)
		{
			//alert("stopfadingout FF");
			document.getElementById(mo_fadeOutID).style.opacity = 0;
			checkFF = 0;
			mo_stopFadingOut();
			return;
		}
    }
    else
    {
		document.getElementById(mo_fadeOutID).filters.alpha.opacity += 0.001;
		document.getElementById(mo_fadeOutID).filters.alpha.opacity *= 0.9;
		var checkIE = document.getElementById(mo_fadeOutID).filters.alpha.opacity;
		if(checkIE < 5)
		{
			//alert("stopfadingout IE");
			document.getElementById(mo_fadeOutID).filters.alpha.opacity = 0;
			checkIE = 0;
			mo_stopFadingOut();
			return;
		}
        
    }
		mo_fadeOutTimer = setTimeout("mo_fadeOut()",50);
}
/*********************/


function mo_fadeIn()
{
		document.getElementById(mo_fadeInID).style.opacity += 0.01;
		document.getElementById(mo_fadeInID).style.opacity *= 1.1;
		var checkFF = document.getElementById(mo_fadeInID).style.opacity;
		if(checkFF > 0.99)
		{
			document.getElementById(mo_fadeInID).style.opacity = 1;
			checkFF = 1;
			mo_stopFadingIn();			
			return;
		}
		
		document.getElementById(mo_fadeInID).filters.alpha.opacity += 1;//this one is different (not 0.001) on purpose
		document.getElementById(mo_fadeInID).filters.alpha.opacity *= 1.1;
		var checkIE = document.getElementById(mo_fadeInID).filters.alpha.opacity;
		if(checkIE > 99)
		{
			document.getElementById(mo_fadeInID).filters.alpha.opacity = 100;
			checkIE = 100;
			mo_stopFadingIn();			
			return;
		}
		
		mo_fadeInTimer = setTimeout("mo_fadeIn()",50);
}

function mo_startSwapSlideshow()
{
    document.getElementById("mo_topLayerPhoto").src = mo_photos_ary[mo_disappearingIndex].src;
	document.getElementById("mo_projShowCol").style.backgroundImage = "";

	mo_setFadeOutID('mo_topLayerPhoto'); 

	mo_updateSlideshowIndex();
	setTimeout("mo_startSwapSlideshow()",4000);
}


function detectBrowser()
{
    if(navigator.appVersion.indexOf("MSIE") == -1)
    {
        theBrowser = "Not IE";
    }
    else
    {
        theBrowser = "IE";
    }
}