var captionChain = new Chain();
function RLStartRotation()
{
	captionChain.chain(
		function(){RLChangeNumber();},
		function(){RLLoadCaptionImage('dummyLoader');},
		function(){RLFadeImage(false);},
		function(){RLLoadCaptionImage('photoLoader');},
		function(){RLFadeImage(true);},
		function(){RLUpdateText();},
		function(){RLwait();}
	);
	captionChain.callChain();
}

function RLLoadCaptionImage(RLwhereTo)
{
	var RLdummyImage = $(RLwhereTo).set({
		//The 'events' property passes the object to Element:addEvents.
		'events': {
			'load': captionCallNextChain
		},
		//Any other property uses Element:setProperty.
		'src': cimages[startingpoint],
		'alt': ccaptions[startingpoint],
		'title': ccaptions[startingpoint]
	});
}

function RLFadeImage(inOut)
{
	var RLrealImage = new Fx.Tween('photoLoader');
	if(inOut)
	{
		RLrealImage.start('opacity', 0, 1).chain(function() {captionCallNextChain();});
	}
	else
	{
		RLrealImage.start('opacity', 1, 0).chain(function() {captionCallNextChain();});
	}
}

function RLUpdateText()
{
	$("photoframecaption").innerHTML = ccaptions[startingpoint];
	captionCallNextChain();
}
function RLChangeNumber()
{
	startingpoint = startingpoint + 1;
	if(startingpoint > (ccaptions.length - 1)){startingpoint = 0;}
	captionCallNextChain();
}
function RLwait()
{
	window.setTimeout('RLStartRotation()',5000);
	captionCallNextChain();
}

function captionCallNextChain()
{
	captionChain.callChain();
}
