homepageDuration = 3000;		// ms to fade
homepageTimeout = 1500;			// ms after last image loads (window.load)
contentDuration = 400;			// large image slide

$(document).ready(function()
{
	// Project category list page navigation animation.
	$('nav.image li').hover(
		function() {
			$(this).find('a.text').css('color', '#ffffff');
			$(this).find('a.image').css({ height: $(this).height() + 30 });
			$(this).find('a.image img.inactive').hide();
			$(this).find('a.image img.active').show();
		},
		function() {
			$(this).find('a.text').css('color', '#ccc');
			$(this).find('a.image').css({ height: $(this).height() - 30 });
			$(this).find('a.image img.active').hide();
			$(this).find('a.image img.inactive').show();
		}
	);

	// Project category page sliding animation.
	sliderTransition("categoryPageTransition");

	// Animation for the project category list page.
	$('nav.image a').click(function() {
		className = $(this).parent().attr('id');
		sliderTransition(className);
		return false;
	});

	// Trigger category list page slider animation if page is loaded with an active category.
	$('div.slider.active').each(function() {
		sliderTransition("active");
	});

	// Reverse the slider transition on the project category list page.
	$('a.categoriesList.previousPage').click(function() {
		$("div.slider.active nav").animate(
			{ left: '-' + $(this).width() },
			contentDuration,
			function() {
				$("div.slider.active").animate(
					{ left: '805px' },
					contentDuration,
					function() {
						$(this).removeClass("active");
					}
				);
			}
		);
		$(this).fadeOut();

		return false;
	});

	function sliderTransition(className)
	{
		$('div.slider.' + className).animate(
			{ left: '0px' },
			contentDuration,
			function() {
				$(this).find('nav').animate({ left: '0px' }, contentDuration);
				$("a.previousPage").fadeIn();
			}
		);
		$('div.slider.' + className).addClass("active");
	}

	// Manually add the class to every 4th paragraph as the content is coming out 
	// in an html blob.
	$(".columns p").each(function(index) {
		if((index + 1) % 4 == 0)
			$(this).addClass("right");
	});
});

$(window).load(function() {
	
	// Slideshow specific initialisation.
	$('.slideshow:not(.singleImage)').nivoSlider(
		{
			effect:			'slideInLeft',
			manualAdvance:	true,
			animSpeed:		170,
			directionNav:	false,
			captionOpacity: 1,
			afterLoad: function() {
				$(".slideshow").show();
			}
		}
	);

	$('.slideshow.singleImage').nivoSlider(
		{
			manualAdvance:	true,
			directionNav:	false,
			controlNav:		false,
			captionOpacity: 1,
			afterLoad: function() {
				$(".slideshow").show();
			}
		}
	);

	// home fading
	setTimeout(
		function() {
			$('body.home img.white').animate(
				{ opacity: 0 },
				homepageDuration
			);

			$('body.home img.black').animate(
				{ opacity: 1 },
				homepageDuration
			);

			$('body.home').animate(
				{ 'backgroundColor': 'black' },
				homepageDuration
			);

			$('body.home header nav li a').animate(
				{ color: '#ccc' },
				homepageDuration
			);

			$('body.home header nav li').animate(
				{ borderBottomColor: '#aaa' },
				homepageDuration
			);
		},
		homepageTimeout
	);
});

