$(document).ready(function() {
	var path = $.url.attr("path");
	
	$('#header a').each(function(i) {
		if ($(this).attr("href") == path) {
			$(this).addClass("current");
		};
	});
	
	$('#nextCottage').click(function() {
		makeItScroll('#cottageImages', 'next');
	});
	
	$('#previousCottage').click(function() {
		makeItScroll('#cottageImages', 'previous');
	});
	
	$('#nextKipling').click(function() {
		makeItScroll('#kiplingImages', 'next');
	});
	
	$('#previousKipling').click(function() {
		makeItScroll('#kiplingImages', 'previous');
	});
	
	$('#nextBuell').click(function() {
		makeItScroll('#buellImages', 'next');
	});
	
	$('#previousBuell').click(function() {
		makeItScroll('#buellImages', 'previous');
	});
})

function makeItScroll(gallery, direction) {
	var gallery = $(gallery);
	if (direction == "next") {
		var current = gallery.children('.active').removeClass('active');
		var next = current.next('.imageGroup');
		easing = "easeOutBack";
		if (!next.hasClass('imageGroup')) {
			next = gallery.children('.imageGroup:first');
			easing = "";
		}
		next.addClass("active");
		$(gallery).scrollTo(next, "750", {
			'easing': easing
		});
	} else if (direction == "previous") {
		var current = gallery.children('.active').removeClass('active');
		var previous = current.prev('.imageGroup');
		easing = "easeOutBack";
		if (!previous.hasClass('imageGroup')) {
			previous = gallery.children('.imageGroup:last');
			easing = "";
		}
		previous.addClass("active");
		$(gallery).scrollTo(previous, "750", {
			'easing': easing
		});
	}
	
}
