/*
	Starts a timer and sets the timer hander function.
*/
function initTimer()
{
	window.setInterval( "timerHandler()", 1500 );
		
}

var curId = 9;
var maxPartner = 10;
var moveSlots = false;
var ticks     = 0;

/*
	Called every 2 seconds in response to a timer event.
	Does the partner image animation.
	
*/
function timerHandler()
{
	ticks = ( ticks + 1 )%5;
	if( moveSlots )
	{
		fadeIn()
	}
	else
	{
		if( ticks == 0 )
		{
			fadeOut();
		}
	}		
			
}

/*
	Fade out the partner images.
	
*/
function fadeOut()
{
	Effect.Fade( "slot_0" );
	Effect.Fade( "slot_1" );
	Effect.Fade( "slot_2" );
	moveSlots = true;
	
}

/*
	Move all images one slot up and copy the 
	next partner image into the last slot and 
	fade in all images.
*/
function fadeIn()
{
	slotData = $("slot_0" ).firstDescendant();
	
	if( slotData )
	{
		slotData.remove();	
	}
	
	slotData = $("slot_1").firstDescendant();
	if( slotData )
	{		
		$( "slot_0").insert( slotData );		
	}
	
	slotData = $("slot_2").firstDescendant();
	if( slotData )
	{
		$( "slot_1").insert( slotData );

	}
	
	copyToSlot();
	
	moveSlots = false;

	Effect.Appear( "slot_0" );	
	Effect.Appear( "slot_1" );		
	Effect.Appear( "slot_2" );

}

/*
	Copy the current partner image to the last slot.
*/
function copyToSlot()
{
	curElement = "partner_" + curId;
	partnerData = $( curElement ).firstDescendant();
	if( partnerData )
	{
		html = partnerData.cloneNode( true );
		
		$("slot_2").insert( html );
		
	}
	
	curId = ( curId + 1 )%maxPartner;
	
}