// 
//  script.js
//  trunk
//  
//  Created by Callum Wilson on 2011-08-07.
//  Copyright 2011 The Working Party. All rights reserved.
// 
$(document).ready(function() {
	$('.gallery li:gt(0)').hide();
	setInterval(function(){
		$('.gallery li:first-child').fadeOut(3000).next('li').fadeIn(3000).end().appendTo('.gallery');
	}, 4000);
	$('#projects #description').hide();
	$('.gallery-manual li:first-child').addClass('active');
	// ========================================================================
	// = Move to the next image. If none there, move to the start of the list =
	// ========================================================================	
	$('#next, .next-lg').click(function(){
		$('.gallery-manual').show();
		$('#description').hide();
		last = $('.gallery-manual li:last-child');
		if (last.hasClass ("active")) {
			$('.gallery-manual li:last-child').removeClass("active");
			$('.gallery-manual li:first-child').addClass("active");
			$('.current-count').text("1");
		} else {
			$('.gallery-manual li.active:not(:last-child)').removeClass("active").next().addClass("active");
			var newCount = $('.gallery-manual li.active span.this-count').text();
			$('.current-count').text(newCount);
		}
		return false;
	});
	// ==========================================================================
	// = Move to the previous image. If none there, move to the end of the list =
	// ==========================================================================
	$('#prev, .prev-lg').click(function(){
		$('.gallery-manual').show();
		$('#description').hide();
		first = $('.gallery-manual li:first-child');
		if (first.hasClass ("active")) {
			$('.gallery-manual li:first-child').removeClass("active");
			$('.gallery-manual li:last-child').addClass("active");
			var newCount = $('.gallery-manual li:last-child span.this-count').text();
			$('.current-count').text(newCount);
		} else {
			$('.gallery-manual li.active:not(:first-child)').removeClass("active").prev().addClass("active");
			var newCount = $('.gallery-manual li.active span.this-count').text();
			$('.current-count').text(newCount);
		}
		return false;
	});
	
	$('#desc').click(function(){
		$('.gallery-manual').hide();
		$('#description').show();
		// $('#description h2').prepend('<a id="back" href="#">Back</a>');
		$('.controls').hide();
		return false;
	});
	$('#back').click(function(){
		$('.gallery-manual').show();
		$('#description').hide();
		$('.controls').show();
		return false;
	});
});

