function theRotator() {
	$('div.rotator ul li').css({opacity: 0.0});
	$('div.rotator ul li:first').css({opacity: 1.0});
	setInterval('rotate()',10000);
}

function rotate() {	
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));
	if ( current.length == 0 ) current = $('div.rotator ul li:first');
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	var sibs = current.siblings();
	var rndNum = Math.floor(Math.random() * sibs.length );
	var next = $( sibs[ rndNum ] );
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 3000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};
$(document).ready(function() {
		$.fn.shuffle = function() {
			return this.each(function(){
			var items = $(this).children();
			return (items.length)
			? $(this).html($.shuffle(items))
			: this;
		});
	}
	$.shuffle = function(arr) {
		for(
		var j, x, i = arr.length; i;
		j = parseInt(Math.random() * i),
		x = arr[--i], arr[i] = arr[j], arr[j] = x
		);
		return arr;
	}
	$.getJSON('banner_rotator/list.json', function(data) {
	var items = [];
	var DOMelement = [];
	$.each(data, function(key, val) {
		items.push(val);
	});
	items=$.shuffle(items);
	$.each(items, function(key, value) {
		if(key == 0){ opacity = 1; classe = 'class="show"' }else{ opacity = 0; classe = '' }
		$.each(value, function(index, value) { 
		  DOMelement.push('<li style="opacity: ' + opacity + ' ' + classe + ';"><a href="' + value + '" target="_parent"><img src="banner_rotator/' + index + '" width="900" height="250"  alt="banner" /> </a></li>');
		});
		//
	  });
	  $('div.rotator').html('<ul>' + DOMelement.join('') + '</ul>')
	});
	theRotator();
});

