var loop_count = 0;

function homepageSequence(cursor) {
	var fade_to_white_duration = 2500;
	var fade_from_white_duration = 2500;
	var frame_hold_duration = 2500;
	
	// loop (if necessary)
	if (!isSet(gallery[cursor + 1])) {
		cursor = 0;
	}
	
	if (loop_count == 0) {
		jQuery('#singleGallery').css('height', '273px');
		jQuery('#singleGallery').css('width', '923px');
		jQuery('#singleGallery').css('background-image', 'url('+ gallery[cursor] +')');
		
		// cache all images
		jQuery.cacheImage(gallery);
		
		setTimeout("homepageSequence(" + cursor + ")", frame_hold_duration / 2);
	} else {
		jQuery('#singleGallery').find('.flash').animate({opacity: 1.0}, fade_to_white_duration, 'linear',  
			function () {
				jQuery('#singleGallery').css('background-image', 'url('+ gallery[cursor] +')');
				jQuery('#singleGallery').find('.flash').animate({opacity: 0.0}, fade_from_white_duration, 'linear', 
					function () {
						setTimeout("homepageSequence(" + cursor + ")", frame_hold_duration);
				});
			});
	}
	
	// repeat
	cursor ++;
	loop_count ++;
	
}