var counter = 1;
var timeIncrement = true;
function theRotator() {
	//Set the opacity of all images to 0
	$('#HomepageRotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('#HomepageRotator 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()', 8000);
}

function rotate() 
{	
	if (timeIncrement)
	{
		//Get the first image
		var current = ($('#HomepageRotator ul li.show')?  $('#HomepageRotator ul li.show') : $('#HomepageRotator ul li:first'));
	
		//Get next image, when it reaches the end, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#HomepageRotator ul li:first') :current.next()) : $('#HomepageRotator ul li:first'));	
		
		//Set the fade in effect for the next image, the show class has higher z-index
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);
	
		//Hide the current image
		current.animate({opacity: 0.0}, 1000)
		.removeClass('show');
		counter++;
		if (counter == 4)
		{
			counter = 1;
		}
		if (counter == 1)
		{
			$('#HRNum1').attr('src', "site_files/HomeRotatorNum01-1.png");
			$('#HRNum2').attr('src', "site_files/HomeRotatorNum02-0.png");
			$('#HRNum3').attr('src', "site_files/HomeRotatorNum03-0.png");
		}
		else
		{
			if (counter == 2)
			{
				$('#HRNum1').attr('src', "site_files/HomeRotatorNum01-0.png");
				$('#HRNum2').attr('src', "site_files/HomeRotatorNum02-1.png");
				$('#HRNum3').attr('src', "site_files/HomeRotatorNum03-0.png");
			}
			else
			{
				$('#HRNum1').attr('src', "site_files/HomeRotatorNum01-0.png");
				$('#HRNum2').attr('src', "site_files/HomeRotatorNum02-0.png");
				$('#HRNum3').attr('src', "site_files/HomeRotatorNum03-1.png");
			}
		}
	}
};

function rotateOne()
{
	timeIncrement = true;
	var numRot = 1 - counter;
	if (numRot < 0)
	{
		numRot = numRot + 3;
	}
	var whilePasses = 0;
	while (whilePasses != numRot)
	{
		rotate();
		whilePasses++;
	}
	timeIncrement = false;
}
function rotateTwo()
{
	timeIncrement = true;
	var numRot = 2 - counter;
	if (numRot < 0)
	{
		numRot = numRot + 3;
	}
	var whilePasses = 0;
	while (whilePasses != numRot)
	{
		rotate();
		whilePasses++;
	}
	timeIncrement = false;
}
function rotateThree()
{
	timeIncrement = true;
	var numRot = 3 - counter;
	if (numRot < 0)
	{
		numRot = numRot + 3;
	}
	var whilePasses = 0;
	while (whilePasses != numRot)
	{
		rotate();
		whilePasses++;
	}
	timeIncrement = false;
}
