// Initialize.
function init_rotator(div) {
	// Does element exist?
	if (!$(div).length) {
		// If not, exit.
		return;
	}

	// Rotate speed.
	var speed_fade = 2000;
	var speed_stay = 6000;
		
	// Hide all but first 
	$(div + ' img:first').show();

	// Wait for page load.
	$(window).load(function() {
		// Begin rotation.
		setTimeout( function() {
			rotate($(div + ' img:visible:first'));
			}, speed_stay);
	});
	
	// Rotator function.
	function rotate(element) {
		// Either the next /first
		var $next_img = $(element).next('img').length ? $(element).next('img') : $(div + ' img:first');

		// Continue.
		function doIt() {
			rotate($next_img);
		}

		// Fade out 
		$(element).fadeOut(speed_fade);
		
		// Show next 
		$($next_img).fadeIn(speed_fade, function() {
			// Slight delay.
			setTimeout(doIt, speed_stay);
		});
	}
}

// Kick things off.
$(document).ready(function() {
	new init_rotator('#ss_1');
});
