function theRotator()
{
	//Set the opacity of all images to 0, then set first image to full opacity
	$('div#rotator ul li').fadeOut(0);
	$('div#rotator ul li:first').fadeIn(0);
		
	//Call the rotator function to run the slideshow, 5000 = change to next image after 5 seconds
	setInterval('rotate()',5000);
}

function rotate()
{	
	var fadeSpeed = 1000;	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator 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')) ? $('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
	next.addClass('show').fadeIn(fadeSpeed);
	//Fade out the current image
	current.fadeOut(fadeSpeed).removeClass('show');
};

$(document).ready(function() {
	//NavBar opacity set to 65%, set hover full opacity
	$('#navcontainer').css('opacity', 0.65);
	$('#navcontainer').hover(function(){
	$('#navcontainer').fadeTo("slow", 0.85); // This sets the opacity to 85% on hover
	},function(){
	$('#navcontainer').fadeTo("slow", 0.65); // This sets the opacity back to 65% on mouseout
	});
	//create loading screen
	var loadDiv = jQuery("<div id='loading'/>");
	$(document.body).append(loadDiv);
	//loading screen fadeout - make screen visible at 85% opacity
	$('#loading').css('display', 'block').css('opacity', 0.85);

	//fade effect for internal links - fade in loadingscreen to 85% opacity, then follow link
	$("a.internalLink").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("#loading").fadeTo(2000, .85, redirectPage);
	});	
	function redirectPage()
	{
		window.location = linkLocation;
	}

	//Load the slideshow
	theRotator();
	$("a[rel=fBox]").fancybox({

		'transitionIn'	:   'fade',
		'transitionOut'	:   'fade',
		'cyclic'    	:   true,
		'centerOnScroll':   true,
		'overlayColor'  :   '#000',
		'titleShow'     :   false,
		
	});

	
});

$(window).load(function() {
    //fade out loading screen when everything else is loaded
    $('#loading').fadeOut(2000);
});

