// JavaScript Document

//************************************************//
//Global variables
loopMe 		= null;
rotating 	= false;

function beginRotation()
{				
	loopMe = setTimeout('homeRotation()',5000);	
}

function homeRotation()
{
	clearTimeout(loopMe);

	current  = 0;
	arrGroup = $A($$('#HomeHeader .homeGroup'));
	//arrPage  = $A($$('#HomeHeader .homePage'));
	//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($$('#HomeHeader .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()',5000);
			}
		})
	]);
}
