
var group_delay = 2000;

(function(jQuery) {
jQuery.fn.fadeInSequence = function(fadeInTime, timeBetween)
{
	//Default Values
	timeBetween = 0;
	fadeInTime = 850;

	//The amount of remaining time until the animation is complete.
	//Initially set to the value of the entire animation duration.
	var remainingTime = jQuery(this).size() * (fadeInTime+timeBetween);

	var i=0; //Counter
	return jQuery(this).each(function()
	{
		//Wait until previous element has finished fading and timeBetween has elapsed
		jQuery(this).delay(i++*(fadeInTime+timeBetween));

		//Decrement remainingTime
		remainingTime -= (fadeInTime + timeBetween);
		
		jQuery(this).fadeIn(fadeInTime, function(){
			
			$(this).parent().find('div').not(this).fadeOut();
			
			if ($(this).hasClass('s6') && $(this).hasClass('g0')){
				//setTimeout("$('.i0').fadeOut(); $('.i1').fadeIn(function(){ $('.g1').fadeInSequence(); });",group_delay);
				setTimeout("$('.i0').fadeOut(function(){$('.i1').fadeIn(function(){ $('.g1').fadeInSequence(); });});",group_delay);
			}

			if ($(this).hasClass('s6') && $(this).hasClass('g1')){
				//setTimeout("$('.i1').fadeOut(); $('.i2').fadeIn(function(){ $('.g2').fadeInSequence(); });",group_delay);
				setTimeout("$('.i1').fadeOut(function(){$('.i2').fadeIn(function(){ $('.g2').fadeInSequence(); });});",group_delay);
			}			

			if ($(this).hasClass('s6') && $(this).hasClass('g2')){
				//setTimeout("$('.i2').fadeOut(); $('.i0').fadeIn(function(){ $('.g0').fadeInSequence(); });",group_delay);
				setTimeout("$('.i2').fadeOut(function(){$('.i0').fadeIn(function(){ $('.g0').fadeInSequence(); });});",group_delay);
			}			
		});	

		//Delay until the animation is over to fill up the queue.
		jQuery(this).delay(remainingTime+timeBetween);

	});	

};

})(jQuery);

$(document).ready(function(){
	
	$('.i0').show();
	// setTimeout("$('.g0').fadeInSequence();",200);
	setTimeout("$('.s1.g0,.s2.g0,.s3.g0,.s4.g0,.s5.g0,.s6.g0').fadeInSequence();",200);
	
}); 

