
var GenericSlideShowID = new Array(); // stores SlideShowID, for getting array index for the other arrays
var GenericSlideShowSelectedIndex = new Array(); // Current visible element index or null if none
var GenericSlideShowPlayPeriod = new Array(); // 0 for not playing or seconds between advancing on visible element
var GenericSlideShowTimerID = new Array();

function GenericSlideShowSelect(SlideShowID, ElementID, MinIndex, MaxIndex, Index, attrName, attrValueOn, attrValueOff)
{
	var nArrayIdx = GenericSlideShowFindIdx(SlideShowID);
	
	if (nArrayIdx == null)
	{
		nArrayIdx = GenericSlideShowID.length;
		GenericSlideShowID[nArrayIdx] = SlideShowID;
		GenericSlideShowSelectedIndex[nArrayIdx] = null;
		GenericSlideShowPlayPeriod[nArrayIdx] = 0;
		GenericSlideShowTimerID[nArrayIdx] = null;
	}
	else
	{
		var period = GenericSlideShowPlayPeriod[nArrayIdx];
		if (period != null)
			if (period > 0)
			{
				GenericSlideShowPlayPeriod[nArrayIdx] = 0;
				if (GenericSlideShowTimerID[nArrayIdx] != null)
				{
					window.clearTimeout(GenericSlideShowTimerID[nArrayIdx]);
					GenericSlideShowTimerID[nArrayIdx] = null;
				}
			}
	}
	
	var PreviousIndex = GenericSlideShowSelectedIndex[nArrayIdx];
	if (PreviousIndex != null)
	{
		if (GenericSlideShowSetElementAttribute(ElementID + '_' + PreviousIndex, attrName, attrValueOff))
			GenericSlideShowSelectedIndex[nArrayIdx] = null;
	}
	
	if (GenericSlideShowSetElementAttribute(ElementID + '_' + Index, attrName, attrValueOn))
		GenericSlideShowSelectedIndex[nArrayIdx] = Index;
}

function GenericSlideShowPlay(SlideShowID, ElementID, MinIndex, MaxIndex, Period, attrName, attrValueOn, attrValueOff)
{
	GenericSlideShowPlayEffects(SlideShowID, ElementID, MinIndex, MaxIndex, Period, attrName, attrValueOn, attrValueOff, null, null);
}

function GenericSlideShowPlayBlend(SlideShowID, ElementID, MinIndex, MaxIndex, Period, attrName, attrValueOn, attrValueOff, ContainerID, Duration)
{
	GenericSlideShowPlayEffects(SlideShowID, ElementID, MinIndex, MaxIndex, Period, attrName, attrValueOn, attrValueOff, ContainerID, "blendTrans(duration="+ Duration +")");
}

function GenericSlideShowPlayEffects(SlideShowID, ElementID, MinIndex, MaxIndex, Period, attrName, attrValueOn, attrValueOff, ContainerID, Filter)
{
	var nArrayIdx = GenericSlideShowFindIdx(SlideShowID);
	if (nArrayIdx == null)
	{
		nArrayIdx = GenericSlideShowID.length;
		GenericSlideShowID[nArrayIdx] = SlideShowID;
		GenericSlideShowSelectedIndex[nArrayIdx] = null;
		GenericSlideShowPlayPeriod[nArrayIdx] = 0;
		GenericSlideShowTimerID[nArrayIdx] = null;
	}
	
	GenericSlideShowPlayPeriod[nArrayIdx] = Period;
	
	var firstIndex = GenericSlideShowSelectedIndex[nArrayIdx];
	if (firstIndex == null)
		firstIndex = MinIndex;
	else
	{
		firstIndex++;
		if (firstIndex > MaxIndex)
			firstIndex = MinIndex;
	}
	
	GenericSlideShowSelectPlay(SlideShowID, ElementID, MinIndex, MaxIndex, firstIndex, attrName, attrValueOn, attrValueOff, ContainerID, Filter);
}

function GenericSlideShowStop(SlideShowID)
{
	var nArrayIdx = GenericSlideShowFindIdx(SlideShowID);
	if (nArrayIdx != null)
	{
		GenericSlideShowPlayPeriod[nArrayIdx] = 0;
		if (GenericSlideShowTimerID[nArrayIdx] != null)
		{
			window.clearTimeout(GenericSlideShowTimerID[nArrayIdx]);
			GenericSlideShowTimerID[nArrayIdx] = null;
		}
	}
}

// Returns boolean TRUE if attribute change was successfull
function GenericSlideShowSetElementAttribute(ElementID, attrName, attrValue)
{
	var bSuccess = false;
	 
	var item = document.getElementById(ElementID);
	if (item != null)
	{
		if (attrName.substr(0, 6).toLowerCase() == 'style.')
		{
			if (item.style.setAttribute)
				item.style.setAttribute(attrName.substr(6), attrValue, 0);
			else
				item.setAttribute('style', attrName.substr(6) + ':' + attrValue + ';', 0);
			bSuccess = true;
		}
		else
		{
			var attr = item.attributes[attrName];
			if (attr)
			{
				attr.nodeValue = attrValue;
				bSuccess = true;
			}
		}
	}
	return bSuccess;
}

// Returns true if slideshow ID is in play mode
function GenericSlideShowIsPlaying(SlideShowID)
{
	var bSuccess = false;

	var nArrayIdx = GenericSlideShowFindIdx(SlideShowID);
	if (nArrayIdx != null)
	{
		var period = GenericSlideShowPlayPeriod[nArrayIdx];
		if (period != null)
			if (period > 0)
				bSuccess = true;
	}
	
	return bSuccess;
}

// Returns true if specified element index is the selected element. use null as index to test is none is selected
function GenericSlideShowIsSelected(SlideShowID, index)
{
	var bSuccess = false;

	var nArrayIdx = GenericSlideShowFindIdx(SlideShowID);
	if (nArrayIdx != null)
	{
		if (GenericSlideShowSelectedIndex[nArrayIdx] == index)
			bSuccess = true;
	}
	
	return bSuccess;
}

function GenericSlideShowGetSelectedIndex(SlideShowID)
{
	var nSelectedIndex = null;
	var nArrayIdx = GenericSlideShowFindIdx(SlideShowID);
	if (nArrayIdx != null)
		nSelectedIndex = GenericSlideShowSelectedIndex[nArrayIdx];

	return nSelectedIndex;
}

function GenericSlideShowSelectPlay(SlideShowID, ElementID, MinIndex, MaxIndex, Index, attrName, attrValueOn, attrValueOff, ContainerID, Filter)
{

	var nArrayIdx = GenericSlideShowFindIdx(SlideShowID);
	var item = null;
	var PreviousIndex = null;
	var period = GenericSlideShowPlayPeriod[nArrayIdx];

	if (period != null)
	{
		if (period > 0)
		{
			if (nArrayIdx == null)
			{
				nArrayIdx = GenericSlideShowID.length;
				GenericSlideShowID[nArrayIdx] = SlideShowID;
				GenericSlideShowSelectedIndex[nArrayIdx] = null;
				GenericSlideShowPlayPeriod[nArrayIdx] = 0;
				GenericSlideShowTimerID[nArrayIdx] = null;
			}

			if ((Filter == null) || (Filter == ""))
				ContainerID = null;
			var container = null;
			PreviousIndex = GenericSlideShowSelectedIndex[nArrayIdx];
			if (PreviousIndex != null)
			{
				if (ContainerID != null)
				{
					try
					{
						container = document.getElementById(ContainerID);
						if (container != null)
						{
							container.style.filter = Filter;
							container.filters[0].apply();
						}
					}
					catch(e)
					{
					}
				}				

				if (GenericSlideShowSetElementAttribute(ElementID + '_' + PreviousIndex, attrName, attrValueOff))
					GenericSlideShowSelectedIndex[nArrayIdx] = null;
			}
			
			if (GenericSlideShowSetElementAttribute(ElementID + '_' + Index, attrName, attrValueOn))
				GenericSlideShowSelectedIndex[nArrayIdx] = Index;

			if (container != null)
			{
				try
				{
			        container.filters[0].play();
				}
				catch(e)
				{
				}
			}

			var firstIndex = GenericSlideShowSelectedIndex[nArrayIdx];
			if (firstIndex == null)
				firstIndex = MinIndex;
			else
			{
				firstIndex++;
				if (firstIndex > MaxIndex)
					firstIndex = MinIndex;
			}

			window.setTimeout("GenericSlideShowSelectPlay('"+SlideShowID+"','"+ElementID+"',"+MinIndex+","+MaxIndex+","+firstIndex+",'"+attrName+"','"+attrValueOn+"','"+attrValueOff+"','"+ContainerID+"', '"+ Filter +"')", period, 'javascript');
		}
	}
}

function GenericSlideShowFindIdx(SlideShowID)
{
	var bFound = false;
	var n = GenericSlideShowID.length-1;
	while ((n>=0) && !bFound)
	{
		if (GenericSlideShowID[n] == SlideShowID)
			bFound = true;
		else
			n--;
	}
	if (bFound)
		return n;
	else
		return null;
}

