$(document).ready(function() {

	function startClosed(sender) {
		
    	var btnID = "#" + sender;
		var tabID = "#" + sender + "-tab";
		
		var offset = $(btnID).offset();
		
		// All tabs start closed
		// Click opens one while closing any others, sets height to 645
		// Click on active closes it and shortens page
		if ($(btnID).hasClass("active")) {
			$(btnID).removeClass("active");
			$(tabID).slideUp("slow");
			$(".bottom-content").animate({ 
        		height: 187,
     		}, "slow" );
		} else {
			$(".active").removeClass("active");
			$(".tab:visible").slideUp("slow");
			$(btnID).addClass("active");
			
			$(tabID).slideDown("slow", function() {
				$(".bottom-content").css("height", 665);
				$.scrollTo(offset.top - 10, 800, {axis:'y'});
			});
		};
	};
	
	function startOpen(sender) {
    	var btnID = "#" + sender;
		// All tabs start open and active
		// Click closes or opens all
		if ($(btnID).hasClass("active")) {
			$(".button").removeClass("active");
			$(".tab").slideUp("slow");
			$(".bottom-content").animate({ 
        		height: 187,
     		}, "slow" );
		} else {
			$(".button").addClass("active");
			$(".tab").slideDown("slow", function() {
				$(".bottom-content").css("height", 645);
			});
		};
	};
	
    $("h1.open").click(function () {
    	startOpen($(this).attr("id"));
    });
    
    $("h1.close").click(function () {
    	startClosed($(this).attr("id"));
    });
});