function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator1 ul li').css({opacity: 0.0});
	$('div#rotatetext ul li').css({opacity: 0.0});
	$('div#rotator2 ul li').css({ opacity: 0.0 });
	$('div#rotator3 ul li').css({ opacity: 0.0 });
	$('div#rotator4 ul li').css({ opacity: 0.0 });
	$('div#rotator5 ul li').css({ opacity: 0.0 });
$('div#rotator ul li').css({opacity: 0.0});
	
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator1 ul li:first').css({opacity: 1.0});
	$('div#rotatetext ul li:first').css({opacity: 1.0});
	$('div#rotator2 ul li:first').css({ opacity: 1.0 });
	$('div#rotator3 ul li:first').css({ opacity: 1.0 });
	$('div#rotator4 ul li:first').css({ opacity: 1.0 });
	$('div#rotator5 ul li:first').css({ opacity: 1.0 });
	$('div#rotator ul li:first').css({opacity: 1.0});
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',5000);
	
}

function rotate() {	
	//Get the first image
	var current1 = ($('div#rotator1 ul li.show')?  $('div#rotator1 ul li.show') : $('div#rotator1 ul li:first'));
	var currenttext = ($('div#rotatetext ul li.show')?  $('div#rotatetext ul li.show') : $('div#rotatetext ul li:first'));
	var current2 = ($('div#rotator2 ul li.show') ? $('div#rotator2 ul li.show') : $('div#rotator2 ul li:first'));
	var current3 = ($('div#rotator3 ul li.show') ? $('div#rotator3 ul li.show') : $('div#rotator3 ul li:first'));
	var current4 = ($('div#rotator4 ul li.show') ? $('div#rotator4 ul li.show') : $('div#rotator4 ul li:first'));
	var current5 = ($('div#rotator5 ul li.show') ? $('div#rotator5 ul li.show') : $('div#rotator5 ul li:first'));
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotato ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next1 = ((current1.next().length) ? ((current1.next().hasClass('show')) ? $('div#rotator1 ul li:first') :current1.next()) : $('div#rotator1 ul li:first'));	
	var nexttext = ((currenttext.next().length) ? ((currenttext.next().hasClass('show')) ? $('div#rotatetext ul li:first') :currenttext.next()) : $('div#rotatetext ul li:first'));
	var next2 = ((current2.next().length) ? ((current2.next().hasClass('show')) ? $('div#rotator2 ul li:first') : current2.next()) : $('div#rotator2 ul li:first'));
	var next3 = ((current3.next().length) ? ((current3.next().hasClass('show')) ? $('div#rotator3 ul li:first') : current3.next()) : $('div#rotator3 ul li:first'));
	var next4 = ((current4.next().length) ? ((current4.next().hasClass('show')) ? $('div#rotator4 ul li:first') : current4.next()) : $('div#rotator4 ul li:first'));
	var next5 = ((current5.next().length) ? ((current5.next().hasClass('show')) ? $('div#rotator5 ul li:first') : current5.next()) : $('div#rotator5 ul li:first'));	
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next1.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	
	nexttext.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	next2.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);
	next3.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);
	next4.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);
	next5.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);


	//Hide the current image
	current1.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	currenttext.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	current2.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');
	current3.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');
	current4.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');
	current5.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});

