$(document).ready(function () {
	var M = $("#menu");
	if ($.browser.msie && $.browser.version==6) {M.add("li", M).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});}

	$("#sub-menu ul ul").each(function() {
		if(!$(this).prev().hasClass("open")) {$(this).hide();}
	}).prev().click(function() {
		if($(this).hasClass("open")) {
			var T = $(this);
			T.next().slideUp(function() {T.removeClass("open");});
		}
		else {
			$(this).addClass("open").next().slideDown();			
		}
		return false;
	});

	var S = $("#sections");
	var timeout;
	
	$("dd", S).hide();
	$("dt", S).hover(function() {
		clearTimeout(timeout);
		n = $(this).next();
		tp = $(this).parent();
		slideBlock = function() {
			$(".open", tp).removeClass("open");
			if(n.is(":visible")) {
				$(".first", tp).animate({marginTop:"139px"}, 300);
				n.animate({height:0}, 300, function() {$(this).hide();});
			}
			else {
				$(".first", tp).animate({marginTop:0}, 300);
				$("dd:visible", tp).animate({height:0}, 300, function() {$(this).hide();});
				n.show().animate({height:"139px"}, 300).prev().addClass("open");
			}
		};
		timeout = setTimeout("slideBlock()", 100);
	}, function() {clearTimeout(timeout);});
	$("h2 a", S).bind("mouseenter", function() {
		n = $(this).parent().next().find("dd:visible");
		if(n.get(0)) {
			tp = n.parent();
			slideBlock();
		}
	});

	var D = $("#directory");
	$("p:not(:first)", D).hide();
	var Dl = $("li", D);
	Dl.click(function() {
		$("li", D).removeClass("open");
		$(this).addClass("open");
		$("p", D).hide().eq(Dl.index($(this))).show();
	});

	var tc = $(".alphabet").nextAll(".two-columns");
	var aa = $(".alphabet a");
	aa.click(function() {
		aa.removeClass("open");
		$(this).addClass("open");
		tc.hide().eq(aa.index($(this))).show();
		return false;
	});

	$(".answer").not(":first").hide();
	$(".question:first").addClass("open");
	$(".question").click(function() {
		var n = $(this).next();
		if(n.is(":visible")) {
			n.slideUp("normal", function() {$(this).prev().removeClass("open");});
		}
		else {
			$(".answer:visible").slideUp("normal").prev().removeClass("open");
			n.slideDown("normal").prev().addClass("open");
		}
	});

});
