// JavaScript Document

//Declare the global variables
loopMe		= null;
rotating	= false;

function beginRotation()
{
	loopMe = setTimeout('homeRotation()',3000);	
}

function homeRotation()
{
	clearTimeout(loopMe);

	current		= 0;
	arrGroup	= $A($$('#HomeSlideshow .homeGroup'));
	
	//get the current group
	arrGroup.each(function(item,index)
	{
		if(item.style.display == 'block')
		{
			current = index;
		}
	});
	
	//check the number of groups we have...
	count = arrGroup.length;
	
	//get the next group to show
	if(current < count-1)
	{
		next = current + 1;
	}
	else
	{
		next = 0;
	}
	
	arrGroup 	= $A($$('#HomeSlideshow .homeGroup'))
	objCurrent 	= arrGroup[current];
	objNext 	= arrGroup[next];
	
	new Effect.Parallel([
		new Effect.Fade(objCurrent,{}),
		new Effect.Appear(objNext,
		{
			beforeStart:function()
			{
				rotating = true;
				//arrPage[current].removeClassName('down');
			},
			afterFinish:function()
			{				
				rotating = false;
				objCurrent.style.display='none'
				objNext.style.display='block'
				//arrPage[next].addClassName('down');
				loopMe = setTimeout('homeRotation()',3000);
			}
		})
	]);
}
