var TimelineSlider = {
	initialize: function(timeline, speed) {
		this.currentIndex = 0;
		this.speed = speed;
		this.timeline = $(timeline);
	},
	slide: function(slideCount) {
		var newIndex = this.currentIndex + slideCount;
		var element = this.timeline.find('li:eq(' + newIndex + ')');
		if(element.length) {
			this.timeline.scrollTo(element, this.speed);
			this.currentIndex = newIndex;
		}
	},
	nextYear: function() {
		this.slide(-1);
	},
	previousYear: function() {
		this.slide(1);
	}
};

$(document).ready(function() {
	TimelineSlider.initialize('#timeline .slideContainer', 1000);

	$('#timelineNewest').click(function(event) {
		event.preventDefault();
		TimelineSlider.nextYear();
	});
	
	$('#timelineOldest').click(function(event) {
		event.preventDefault();
		TimelineSlider.previousYear();
	});
	
	$('#timeline .monthContainer').click(function(event) {
		event.preventDefault();
		var link = $(this).find('a');
		if(link.length) {
			window.location = link[0].href;
		}
	});
});