$(document).ready(function() {
	$('.level2 a').hover(function() {
			opensubmenu($(this).next('.level3'));	
		},
		function() {
			closesubmenu($(this).next('.level3'));
		});
	$('.level3').hover(function() {
			opensubmenu($(this));	
		},
		function() {
			closesubmenu($(this));
		});
	//adds odd spacing above quicklinks
	$('#submenuBDA371C9-A5A7-DA51-0D8055AFFE71D2E6').prev('a').css({marginTop:"25px",fontWeight:"normal",fontSize:"12px"});
});
opensubmenu = function(menu) {
	if(menu.prev().offset()) {
		// menu position based on parent
		var ypos = menu.prev('a').offset().top-menu.prev('a').parent().offset().top;
		if (document.documentElement.scrollTop) 
			var scrolled = document.documentElement.scrollTop;
			else var scrolled = document.body.scrollTop;
		// if the bottom of the menu is below the scroll, move up
		if ((parseInt(menu.height()) + menu.prev('a').offset().top-scrolled) > $(window).height()) {
			menu.css('top',ypos-(menu.prev('a').offset().top+menu.height()-$(window).height()-scrolled)-10+'px');
			//window.alert(document.body.scrollTop);
		}
		// otherwise, place at regular position 
		else{
			menu.css('top',ypos+'px');
		}
		menu.show();
	}
};
closesubmenu = function(menu) {
	menu.hide();
}


