﻿var _autoPlayTimeout;
var _autoClickTimeout;
var _autoPlayTimerID = null;
var _autoClickTimerID = null;
var _fadeInTimerID = null;
var _fadeOutAnimation = null;
var _fadeInAnimation = null;
var _featuredPeopleAccordian;
var _featuredPeopleImages;

function paneChanging(sender, eventArgs)
{
	var oldIndex = eventArgs.get_oldIndex();
	var selectedIndex = eventArgs.get_selectedIndex();

	if (_fadeOutAnimation)
	{
		_fadeOutAnimation.dispose();
	}

	if (_fadeInAnimation)
	{
		_fadeInAnimation.dispose();
	}

	fadeOut(oldIndex);

	if (_fadeInTimerID)
	{
		window.clearTimeout(_fadeInTimerID);
	}
	_fadeInTimerID = window.setTimeout("fadeIn(" + selectedIndex + ");", 400);
}

function fadeOut(index)
{
	var imageIndices = new Array(0, 1, 2, 3);
	Array.removeAt(imageIndices, index);

	_featuredPeopleImages[index].style.display = "block";
	_featuredPeopleImages[imageIndices[0]].style.display = "none";
	_featuredPeopleImages[imageIndices[1]].style.display = "none";
	_featuredPeopleImages[imageIndices[2]].style.display = "none";
	_fadeOutAnimation = new AjaxControlToolkit.Animation.FadeOutAnimation(_featuredPeopleImages[index], .25, 30);
	_fadeOutAnimation.play();
}

function fadeIn(index)
{
	var imageIndices = new Array(0, 1, 2, 3);
	Array.removeAt(imageIndices, index);

	_featuredPeopleImages[index].style.display = "block";
	_featuredPeopleImages[imageIndices[0]].style.display = "none";
	_featuredPeopleImages[imageIndices[1]].style.display = "none";
	_featuredPeopleImages[imageIndices[2]].style.display = "none";
	_fadeInAnimation = new AjaxControlToolkit.Animation.FadeInAnimation(_featuredPeopleImages[index], .5, 30);
	_fadeInAnimation.play();
}

function startSlideShow(timeout)
{
	if (_autoPlayTimeout > 0)
	{
		_autoPlayTimerID = window.setTimeout("autoClick();", timeout);
	}
}

function stopSlideShow()
{
	if (_autoPlayTimerID)
	{
		window.clearTimeout(_autoPlayTimerID);
	}
	
	if (_autoClickTimerID)
	{
		window.clearTimeout(_autoClickTimerID);
	}
}

function autoClick()
{
	var currentPersonIndex = _featuredPeopleAccordian.AccordionBehavior.get_SelectedIndex();
	var newPersonIndex = (currentPersonIndex + 1) % _featuredPeopleAccordian.AccordionBehavior._panes.length;

	_featuredPeopleAccordian.AccordionBehavior.set_SelectedIndex(newPersonIndex);
	_autoClickTimerID = window.setTimeout("autoClick();", _autoClickTimeout);
}
