	var ie6 = false;
	if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version == '6') ie6 = true;
	jQuery.event.add(window, "scroll", scrollLeftNavMenu);
	jQuery.event.add(window, "resize", resizeFrame);
	// autorun
	jQuery(function() { autoSelectMenuItem(); });
	
	var menuHeight = $('#core-leftmenunav').height();
	var menuTopInitial = $('#core-leftmenunav').offset().top;
	var menuLeftInitial = $('#core-leftmenunav').offset().left;
	//var menuTopInitial = $('#core-leftmenunav').position().top;
	//var menuLeftInitial = $('#core-leftmenunav').position().left;
	var menuBottomInitial = menuTopInitial + menuHeight;
	if (ie6)
		var marginTopInitial = $('#core-leftmenunav').css('marginTop');
	
	function resizeFrame() {
		scrollLeftNavMenu();
	}
	
	function menuHighlightByIndex(index) {
		$('#core-leftmenunav .current_subtab').css('background-color', '#FFFFFF');
		$('#core-leftmenunav .current_subtab').css('font-weight', 'normal');
		if ($('#core-leftmenunav .current_subtab')[index]) {
			$($('#core-leftmenunav .current_subtab')[index]).css('background-color', '#F5F7E9');
			$($('#core-leftmenunav .current_subtab')[index]).css('font-weight', 'bold');
		}
	}
	
	function autoSelectMenuItem() {
		var selected = null;
		var index = -1;
		var onscreen = false;
		jQuery('.section-title').each( function(key, item) {
			if (jQuery(document).scrollTop() >= jQuery(item).offset().top ) {
				index++;
			} else {
				if ( (jQuery(document).scrollTop() + jQuery(window).height()) < parseInt(jQuery(item).offset().top)) {
					return;
				}
				index++;
			}
		});
		
		if (index == -1)
		{
			index = 0;
		}
		
		menuHighlightByIndex(index);
	}
	
	function scrollLeftNavMenu() {
		autoSelectMenuItem();

		windowTop = $(window).scrollTop();
		windowHeight = $(window).height();
		windowBottom = windowTop + windowHeight;
		menuTop = $('#core-leftmenunav').offset().top;
		//menuTop = document.getElementById('core-leftmenunav').style.top;
		menuBottom = menuTop + menuHeight;

		// fits on screen
		if (menuHeight < windowHeight) {
			// stick to top
			if (windowTop >= menuTopInitial) {
				if (ie6)
					$('#core-leftmenunav').css('marginTop', (document.documentElement.scrollTop-menuTopInitial+12) + "px");
				else {
					$('#core-leftmenunav').css('position', 'fixed');
					$('#core-leftmenunav').css('top', '0');
				}
				$('#core-leftmenunav').css('left', menuLeftInitial);
			}
			// or return to normal
			else if (windowTop < menuTopInitial) {
				$('#core-leftmenunav').css('position', 'static');
				if (ie6)
					$('#core-leftmenunav').css('marginTop', marginTopInitial);
				else
					$('#core-leftmenunav').css('top', menuTopInitial);
			}
		}
		
		// doesn't fit on screen
		if (menuHeight >= windowHeight) {
			//stick menu to the screen bottom by changing menu.top
			if (windowBottom >= menuBottomInitial) {
				marginTop = parseInt($('#core-leftmenunav').css('marginTop').replace("px", ""));
				if (ie6) {
					//if ( document.documentElement.scrollTop-menuTopInitial-(menuHeight - windowHeight)-12 + document.documentElement.clientHeight+100 < document.body.scrollHeight)
					newMarginTop = (document.documentElement.scrollTop-menuTopInitial-(menuHeight - windowHeight)-12);
					if ( newMarginTop + menuHeight + $('#core-footer').height() +75 < $('#core-footer').offset().top )
						$('#core-leftmenunav').css('marginTop', newMarginTop + "px");
					//alert( (newMarginTop + menuHeight) + ' ' + $('#core-footer').offset().top);
					//alert( (document.documentElement.scrollTop-menuTopInitial-(menuHeight - windowHeight)-12) + ' ' + document.body.scrollHeight);
				}
				else {
					$('#core-leftmenunav').css('position', 'fixed');
					$('#core-leftmenunav').css('top', -(menuHeight - windowHeight) );
				}
				$('#core-leftmenunav').css('left', menuLeftInitial);
			}
			// return to normal
			else {
				$('#core-leftmenunav').css('position', 'static');
				if (ie6)
					$('#core-leftmenunav').css('marginTop', marginTopInitial);
				else
					$('#core-leftmenunav').css('top', menuTopInitial);
			}
		}
		
		// BUGFIX: menu sticks to top of page
		if (menuTop < menuTopInitial-1) {
			if (ie6)
				$('#core-leftmenunav').css('marginTop', marginTopInitial);
			else
				$('#core-leftmenunav').css('top', menuTopInitial);
		}
	}


