// JavaScript Document
var ShowRandomTextBlock = function()
{
  var blocks = new Array();
  function DoIt()
  {
    var d = document.getElementById('rotating_items').getElementsByTagName('div');
    for (var x=0, y=d.length; x < y; x++) {
      // capture the divs with the right class name
      if (d[x].className == 'rotating_item') { blocks.push(d[x]); }
    }
    // find random number
    var spot = Math.floor(Math.random() * blocks.length);
    // Set whether each div block should be seen or not
    for (var x=0, y=blocks.length; x < y; x++) {
      if (spot == x) { blocks[x].style.display = ''; }
      else { blocks[x].style.display = 'none'; }
    }
  }
  window.onload = DoIt;
}();

jQuery(document).ready(function(){
	showing = jQuery('#banners div.rotating:first'); // Initiate the 'showing' variable as the first rotating_item
	showing.siblings('div').hide(); // Hide all other rotating_items
	setInterval("show_next_rotating_item(showing)", 4000); // Set the rotate time to 5 seconds
});
// Below is the code that picks an item at random to display
jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
	random: function(a, i, m, r) {
		if (i == 0) {
			jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
		};
		return i == jQuery.jQueryRandom;
	}
});
// The below function repeatedly gets called, to do the rotating
function show_next_rotating_item(t){
	jQuery(t).fadeOut('slow');
	var next_rotating_item = jQuery(t).siblings('.rotating:random');
	if(!next_rotating_item.attr('class')){
		next_rotating_item = jQuery('#banners div.rotating:first');
	}
	next_rotating_item.fadeIn('slow');
	showing = next_rotating_item;
}

