var scrolling;

$(document).ready(function () {

$('#main_nav li').hover(
	function () {
		$(this).addClass('active');
		var child = $('> ul', this).show().get(0);
		if (child) {
			var depth = getScreenY(child) + child.clientHeight - getScreenHeight();
			if (getScrollY() < depth) {
				$('.scrollTarget', child).show();
			} else {
				$('.scrollTarget', child).hide();
			}
		}
	},
	function () {
		$(this).removeClass('active');
		$('> ul', this).hide();
	}
);

$('#main_nav .scrollTarget').hover(
	function() {
		var target = this;
		var list = this.parentNode;
		var depth = getScreenY(list) + list.clientHeight - getScreenHeight();
		if (getScrollY() < depth) {
			scrolling = setInterval(
				function() {
					if (getScrollY() < depth) {
						window.scrollBy(0, Math.min(depth - getScrollY() + 6, 26));
					} else {
						clearInterval(scrolling);
						$(target).hide();
					}
				},
				200
			);
		}
	},
	function() {
		clearInterval(scrolling);
	}
);

});


