var $showing;

$(document).ready(function() {
	var $quotes = $('#rotating_items div.rotating_item');
	
	$showing = $('#rotating_items div.rotating_item:first-child'); // Initiate the 'showing' variable as the first rotating_item
	$showing.show(); // Hide all other rotating_items

	if ($quotes.length > 1) {
		var max_height = 0;
		$quotes.each(function() {
			$this = $(this);
			$this.css('position', 'absolute');
			if ($this.height() > max_height) {
				max_height = $this.height();
			}
		});
		$('#rotating_items').height(max_height + 'px');
		setInterval('show_next_rotating_item($showing)', 5000); // Set the rotate time to 5 seconds
	}
});

// Below is the code that picks an item at random to display
$.jQueryRandom = 0;
$.extend($.expr[':'], {
	random: function(a, i, m, r) {
		if (i == 0) {
			$.jQueryRandom = Math.floor(Math.random() * r.length);
		};
		return i == $.jQueryRandom;
	}
});

// The below function repeatedly gets called, to do the rotating
function show_next_rotating_item($t) {
	$t.fadeOut('slow');
	
	var $next_rotating_item = $t.siblings('.rotating_item:random');
	if(!$next_rotating_item.attr('class')) {
		$next_rotating_item = $('#rotating_items div.rotating_item:first-child');
	}
	$next_rotating_item.fadeIn('slow');

	$showing = $next_rotating_item;
}

