$(document).ready(function() {
	
	// add one to the end
	$('#gallery').append( '<p>' + $('#gallery p').eq(0).html() + '</p>' )
	
	// set each z-index
	$('#gallery p').each(function(index) {
		$(this).css('z-index', 100 - index);
	});
	
	var all = $('#gallery p');
	var length = all.size();
	
	// scroll
	var gscroll = function() {
		var _this = $('#gallery p').not('.hide').eq(0);
		var _index = all.index(_this);
		if ( _index == length - 1 ) {
			all.show().removeClass('hide');
			gscroll();
		}
		
		_this.fadeOut( 800 , function() {
			if( _index == length - 1 ) _this.show();
			else  _this.addClass('hide');
		});
	};
	
	if ( length > 2 ) {
		setInterval( gscroll, 5000 );
	}	
});
