// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing.easeOutQuart = function(x, t, b, c, d) {
    return -c * ((t = t / d - 1) * t * t * t - 1) + b;
};

jQuery(function($) {

	$('#slideshow li h2').fadeOut();

	$('#slideshow').serialScroll({
		items: 'li.slider',
		prev: '#screen2 a.prev',
		next: '#screen2 a.next',
		offset: -260, //when scrolling to photo, stop 230 before reaching it (from the left)
		start: 0, //we have the fake, so start at the start
		duration: 1200,
		force: true,
		stop: true,
		interval: 8500,
		lock: false,
		cycle: true, //don't pull back once you reach the end
		easing: 'easeOutQuart', //use this easing equation for a funny effect
		jump: false, //click on the images to scroll to them,
		onBefore: function(e, elem, $pane, $items, pos) {
			$(elem)
				.siblings()
					.children('h2')
						.fadeOut()
					.end()
				.end()
				.children('h2').fadeIn();
			$("#buttons .slidernum")
				.removeClass('selected')
				.eq(pos)
					.addClass('selected');

		},
		onAfter: function(elem) {
			$(elem)
				.children('h2').fadeIn(); // Do it here too for the first element
		}
	});

	$("#buttons .slidernum").click(function(event) {
		event.preventDefault();
		$(this)
			.siblings()
				.removeClass('selected')
			.end()
			.addClass('selected');
		var index = $(this).attr("href").substr(1, 1) - 1;
		$("#slideshow").trigger('goto', [index]);
	});

});