var cycleItems = new Array();
var currentShownItem = 0;

function startCycle(containerDivId) {
	var i=0;
	// Put all images in the container div into array
	$('#'+containerDivId+' img').each(function(index) {
		cycleItems[i] = $(this).attr('id');
		i++;
	});
	
	// Fade in first item
	
	doCycle();
}

function doCycle() {
	// Fade currently shown item
	$('#'+cycleItems[currentShownItem]).fadeOut(2000);
	
	
	$('#'+cycleItems[currentShownItem]).fadeOut('slow', function() {
		// Reset loop if needed
		currentShownItem++;
		if(currentShownItem == cycleItems.length) {
			currentShownItem = 0;
		}
		// Fade in next item
		$('#'+cycleItems[currentShownItem]).fadeIn('slow');
	});
	
	// Reactiveate the doCycle after a while
	setTimeout("doCycle();",5000);
}
