jQuery(document).ready(function() {
	var $ = jQuery;

	var lis = [];
	var number_sponsors = $('#sponsors ul li:not(.persistent):not(.optional)').length;
	$('#sponsors ul li:not(.persistent)').each(function( i, li ) {
		lis.push( $(this) );
	});

	var randomsort = function() {return Math.random() > 0.5 ? 1 : -1;};
	lis.sort( randomsort );

	for( var x = 0; x < lis.length; x++ ) {
		var li = lis[x];
		li.remove();
		if ( x < number_sponsors ) {
			li.removeClass('optional').removeClass('last');
			
			if ( x == number_sponsors - 1 ) {
				li.addClass('last');
			}
			$('#sponsors ul').append( li );
		}

	}
});
