
$(function(){


	$(".chapter .body").each(function(i) {
		$(this).hide();
	});

	$(".chapter h2").each(function(i) {
		$(this).attr("class", "close");
	});

//	$("#chapter000 .body").slideDown(1000);
//	$("#chapter000 h2").attr("class", "open");


	var data_file = "guide1.dat";
	$("#guide1").load(data_file, function() {
		$(".chapter-sub").each(function(i) {
			$(this).hide();
		});
			$("#chapter-sub000").show();
			$("#guide1 li").click(function(){
				target = "#" + $(this).attr("rel");
				$($("#guide1 li").get()).removeClass("active");
				$(this).attr("class", "active");
				$(".chapter-sub").each(function(i) {
					$(this).hide();
				});
				$(target).fadeIn();
			});
	});


	function scroll(target){
		var targetOffset = $(target).parent().prev().offset().top;
		$('html,body').animate({scrollTop: targetOffset}, 500);
	}

	$(".chapter h2").click(function(){
		target = $(this).siblings(".body");
		$(target).slideToggle(200, scroll(this));

		now_status = $(this).attr("class");


		if (now_status == "close") {
			$(".chapter h2.open").each(function(i) {
				target = $(this).siblings(".body");
				$(target).slideUp(300);
				$(this).attr("class", "close");
			});
			$(this).attr("class", "open");

		}
		else {
			$(this).attr("class", "close");
		}
	});


	$(".chapter .btclose").click(function(){
		target = $(this).parent(".body");
		$(target).slideToggle(200);

		$(target).prev("h2").attr("class", "close");

	}).hover(
	function(){
		$(this).css("cursor", "pointer");
	},
	function(){
		$(this).css("cursor", "default");
	});


});


$(window).load(function(){
	$("#chapter000 .body").slideDown(500);
	$("#chapter000 h2").attr("class", "open");
});

