/*-----------------------------------------------------------------------------
	Special Offers
-----------------------------------------------------------------------------*/
	
	$(document).ready(function() {
		var container = $('ul.books');
		
		var toggleSlides = function(direction) {
			container.addClass('locked');
			
			if (direction == 'prev') {
				var active = container.find('li.active');
				var next = active.prev().not('.active');
			} else {
				var active = container.find('li.active');
				var next = active.next().not('.active');
			}
			
			if (next.length == 0) return;
			
			active
				.fadeOut()
				.removeClass('active');
				
			next
				.fadeIn(function() {
					container.removeClass('locked');
				})
				.addClass('active');
				
			if (direction == 'prev') {
				next
					.prev()
					.fadeIn()
					.addClass('active');
			} else {
				next
					.next()
					.fadeIn()
					.addClass('active');
			}
			
			toggleArrows();
		}
		
		var toggleArrows = function() {
			var active = container.find('li.active');
			
			// Hide the prev arrow:
			if (active.prev('li').not('.active').length == 0) {
				container.find('.prev').fadeOut();
				
			} else {
				container.find('.prev').fadeIn();
			}
			
			// Hide the next arrow:
			if (active.next('li').not('.active').length == 0) {
				container.find('.next').fadeOut();
				
			} else {
				container.find('.next').fadeIn();
			}
			
			container.focus();
		}
		
		// Hide all authors, except the first:
		container
			.find('li')
			.hide();
		
		container
			.find('li:first, li:first + li')
			.show()
			.addClass('active');
		
		// Add prev next links:
		container
			.append('<span class="formatted"><a style="display: none;" class="next" href="#">Next</a></span>');
		container
			.append('<span class="formatted"><a style="display: none;" class="prev" href="#">Previous</a></span>');
		
		// Give next slide focus:
		container.find('.next').click(function() {
			if (!container.hasClass('locked')) {
				toggleSlides('next');
			}
			
			return false;
		});
		
		// Give prev slide focus:
		container.find('.prev').click(function() {
			if (!container.hasClass('locked')) {
				toggleSlides('prev');
			}
			
			return false;
		});
		
		toggleArrows();
	});
	
/*---------------------------------------------------------------------------*/