	var name = "#mainmenu";
	var menuYloc = null;
	
	$(document).ready(function(){
		menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")));
		// determine how much more until end of parent element
		mleftHeight = $("#mleft").height(); mrightHeight = $("#mright").height();
		maxHeight = Math.max(mleftHeight, mrightHeight);
		safeHeight = maxHeight - $(name).height();
		//alert(safeHeight);
		$(window).scroll(function () { 
			offset = menuYloc+$(document).scrollTop()+"px";
			offsetValue = menuYloc+$(document).scrollTop();
			if (offsetValue < safeHeight) {
				$(name).animate({top:offset},{duration:500,queue:false});
			} else {
				return false;
			}
		});
	}); 