// Below is the code that picks an item at random to display
$.$Random = 0;
$.extend($.expr[":"],
{
    random: function(a, i, m, r) {
        if (i == 0) {
            $.$Random = Math.floor(Math.random() * r.length);
        };
        return i == $.$Random;
    }
}); 
 
// 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 = $('#advert div.rotating_item:first');
	}
	next_rotating_item.fadeIn('slow');
 
	showing = next_rotating_item;
}

$(document).ready(function(){
	showing = $('#advert div.rotating_item:random'); // Initiate the 'showing' variable as the first rotating_item
	showing.siblings('div').hide(); // Hide all other advert
	setInterval("show_next_rotating_item(showing)", 5000); // Set the rotate time to 5 seconds
});
