  	jQuery(document).ready(function($) {
  	
 	$('div.quickNav2 a:last-child').mouseover(function() {
  			$('.rightNavHighlight').css('display', 'inline');
  		}).mouseout(function() {
  			$('.rightNavHighlight').css('display', 'none');
  		});
		
  	
		var fadeTimer = null;
			
			
			// make the little linkies.
		$('div.slideshowItems').each(function()
		{
			var out = '',
				j = $(this),
				count = j.children('div.item').length;
			
			for (var i = 0; i < count; i++)
				out += "<div class='imageIndex'>" + (i + 1) + "</div>"; // 1-indexed!!
			
			j.next('div.imageIndices').html(out);
		});
		
		var imageIndexSelector = 'div.imageIndices div.imageIndex';
		
		$(imageIndexSelector).click(function(e)
		{
			e.preventDefault();
			
			// TODO - calculate my index
			var myIndex = $(this).index(imageIndexSelector);
			
			fadeToImage(myIndex, 200);
		});
		
		

		function fadeInNext() {
		
			fadeToImage();
		}

		function fadeToImage(n, fadeTime) {
		
			if (fadeTimer)
				clearTimeout(fadeTimer);
			
			if ( fadeTime == undefined )
				fadeTime = 600;
			
			$('div.blackout').stop().fadeTo(fadeTime, 1.0, function() {  // fade in the black
				// this code here gets executed AFTER the fade on the above line is complete
				var current = $('div.slideshowItems div.item:visible');  // get the current element
				
				var next;
				
				if (n !== undefined)
				{
					next = $('div.slideshowItems div.item:eq(' + n + ')');
				}
				else
				{
					next = current.next('div.item');  // get the next element
					
					if (!next.length)
						next = $('div.slideshowItems div.item').first();  // get the first one instead
				}
					
				current.hide();
				next.show();
				
				var nextIndex = next.index('div.slideshowItems div.item');

				$( imageIndexSelector + ':eq(' + nextIndex + ')')
					.addClass('active')
					.siblings('div.imageIndex')
					.removeClass('active');
				
				$('div.blackout').fadeTo(fadeTime * 2, 0, function() { // fade out the black
					// this code here gets executed AFTER the fade on the above line is complete
					fadeTimer = setTimeout(fadeInNext, 8000);
				});
			});
		}

		fadeInNext(); // get started
	});

