
// jquery code to support the rotation of the images on the home page
//
var photoNum = 1;
var timerId = 0;

$(document).ready(function() {
	// Preload images not included in the HTML markup
	//
	imgPhoto2 = new Image(876, 278);
	imgPhoto2.src = '/cmspages/getfile.aspx?aliaspath=/images/rotator/home-image-2';
	imgPhoto3 = new Image(876, 278);
	imgPhoto3.src = '/cmspages/getfile.aspx?aliaspath=/images/rotator/home-image-3';

	imgOne = new Image(17, 20);
	imgOne.src = '/site-images/home-navigation-1.gif';
	imgTwo = new Image(17, 20);
	imgTwo.src = '/site-images/home-navigation-2-on.gif';
	imgThree = new Image(17, 20);
	imgThree.src = '/site-images/home-navigation-3-on.gif';

	// Set up timer event to rotate photos
	//
	timerId = setTimeout('rotatePhoto();', 5000);

	// Control events for navigation
	//
	$('#Nav1').click(function() {
		clearTimeout(timerId);

		var oldPhotoNum = photoNum;
		photoNum = 1;

		switchPhotos(oldPhotoNum, photoNum);
	});

	$('#Nav2').click(function() {
		clearTimeout(timerId);

		var oldPhotoNum = photoNum;
		photoNum = 2;

		switchPhotos(oldPhotoNum, photoNum);
	});

	$('#Nav3').click(function() {
		clearTimeout(timerId);

		var oldPhotoNum = photoNum;
		photoNum = 3;

		switchPhotos(oldPhotoNum, photoNum);
	});

	$('#NavDown').click(function() {
		clearTimeout(timerId);

		var oldPhotoNum = photoNum;
		photoNum = photoNum + 1;
		if (photoNum > 3)
			photoNum = 1;

		switchPhotos(oldPhotoNum, photoNum);
	});

	$('#NavUp').click(function() {
		clearTimeout(timerId);

		var oldPhotoNum = photoNum;
		photoNum = photoNum - 1;
		if (photoNum < 1)
			photoNum = 3;

		switchPhotos(oldPhotoNum, photoNum);
	});
});

// Timer event triggered.  Move to the next photo
//
function rotatePhoto() {
	clearTimeout(timerId);

	var oldPhotoNum = photoNum;

	photoNum = photoNum + 1;
	if (photoNum > 3)
		photoNum = 1;

	switchPhotos(oldPhotoNum, photoNum);
}

// Switch old photo out for new photo and restart timer
//
function switchPhotos(oldNum, newNum) {
	$('#Nav' + oldNum.toString()).attr('src', '/site-images/home-navigation-' + oldNum.toString() + '.gif');
	$('#Nav' + newNum.toString()).attr('src', '/site-images/home-navigation-' + newNum.toString() + '-on.gif');

	$('#rotator-image-' + newNum.toString()).fadeIn('fast');
	$('#rotator-image-' + oldNum.toString()).fadeOut('fast', function() {
		timerId = setTimeout('rotatePhoto();', 5000);
	});
}
