document.observe(
	"dom:loaded",
	function()
	{
		// Only invoke the spinner if there is something to spin!
		if(typeof featuredProducts !== "undefined" && featuredProducts !== null && featuredProducts.length > 1)
		{
			currentInterval = setInterval('rotateImages();', 5000);
			currentSpinner = 0;
			document.getElementById('slideShowStatusLinksDivEl').innerHTML = '';
			i=0;
			$(featuredProducts).each(
				function(item)
				{
					var newDivEl = document.createElement('div');
					newDivEl.id = 'spinnerSmallBox' + i;
					
					newDivEl.className = 'statusBox';
					
					if(i == 0)
					{
						newDivEl.className = 'statusBox active first';
					}
					
					document.getElementById('slideShowStatusLinksDivEl').appendChild(newDivEl);
					$(newDivEl).observe(
						'click',
						function()
						{
							setCurrent(newDivEl);
						}
					);
					i++;
				}
			);
		}
	}
);

rotateImages = function()
{
	currentSpinner++;
	if(currentSpinner == featuredProducts.length)
	{
		currentSpinner = 0;
	}

	new Effect.Appear(
		'spinnerImgEl',
		{
			duration:1,
			from:1.0,
			to:0,
			afterFinish: function()
			{
				actives = $('slideShowStatusLinksDivEl').getElementsByClassName('active');
				$(actives[0].id).removeClassName('active');
				$('spinnerImgEl').src = featuredProducts[currentSpinner].image;
				$('spinnerSmallBox'+currentSpinner).addClassName('active');

				new Effect.Appear(
					'spinnerImgEl',
					{
						duration:1,
						from:0,
						to:1.0
					}
				);
			}
		}
	);
}

setCurrent = function(newCurrent)
{
	clearInterval(currentInterval);
	newCurrent = newCurrent.id.replace(/spinnerSmallBox/, '');
	new Effect.Appear(
		$('spinnerImgEl'),
		{
			duration:1,
			from:1.0,
			to:0,
			afterFinish: function()
			{
				actives = $('slideShowStatusLinksDivEl').getElementsByClassName('active');
				$(actives[0].id).removeClassName('active');
				$('spinnerImgEl').src = featuredProducts[newCurrent].image;
				$('spinnerSmallBox'+newCurrent).addClassName('active');

				new Effect.Appear(
					$('spinnerImgEl'),
					{
						duration:1,
						from:0,
						to:1.0
					}
				);
			}
		}
	);

	currentSpinner = newCurrent;
	currentInterval = setInterval('rotateImages();', 5000);
}

