$(document).ready(function(){
	$('#header .menu').autoPosition('#header', 20);
	$('#content .menu').autoPosition('#content', 65);
});
(function($){
	$.fn.autoPosition = function(containerId,fixedTop){
		var that = $(this);
		var container = $(containerId);
		var contBtm = container.offset().top+container.height()
		var initTop = that.css('top');
		var selfTop = that.offset().top;
		//fixedTop = initTop.split('px')[0];
		$(window).scroll(function () {
			var top = $(window).scrollTop()-selfTop+fixedTop;
			if (top >= 0 && $(that).css("position") != "fixed") {
				$(that).css({"position" : "fixed","top" : fixedTop});
			} else if (top < 0 && $(that).css("position") == "fixed") {
				$(that).css({"position" : "absolute","top" : initTop});
			}
		});
	}
})(jQuery)

