
// position:fixed logic

$(function(){
	var _contentsTop;
	var _pdtMenuHeight;
	var _footerTop;
	
// side menu, show and hide
	$("#catlist li.cat_l2").hide();
	//$("#catlist li li").css("display","none");

	$("#catlist li.cat_l1").hover(function(){
		$(this).find("li").show("fast");
	},function(){
		$(this).find("li").hide("fast");
	});


//init
	$(window).load(function(){
		_contentsTop = $("#container").position().top;
		_pdtMenuHeight =$("#side").height();
		_footerTop = $("#footer").position().top;
	});
	
//scroll event
	$(window).scroll(function(){
		var scroll_T = $(window).scrollTop();
		var scroll_L = $(window).scrollLeft();
		var win_width_s = $(window).width() - 960;

	// side menu
		if ((_pdtMenuHeight + scroll_T) > _footerTop) {
			$("#side").css("position", "relative")
				.css("top", _footerTop - _pdtMenuHeight - _contentsTop - 20)
				.css("left", "0");
			
		} else if (scroll_T > _contentsTop){
			$("#side").css("position", "fixed")
				.css("top", "0");
			$("#side").css("left", (win_width_s > 0) ? (win_width_s / 2 - scroll_L) : (-scroll_L));
			
		} else {
			$("#side").css("position", "static")
				.css("top", "0")
				.css("left", "0");
		}
	}); 
						   
//resize event
	$(window).resize(function(){
		var scroll_T = $(window).scrollTop();
		var scroll_L = $(window).scrollLeft();
		var win_width_s = $(window).width() - 960;

	// side menu
		if ((_pdtMenuHeight + scroll_T) > _footerTop) {
			$("#side").css("position", "relative")
				.css("top", _footerTop - _pdtMenuHeight - _contentsTop - 20)
				.css("left", "0");
			
		} else 	if  (scroll_T > _contentsTop){
			$("#side").css("left", (win_width_s > 0) ? (win_width_s / 2 - scroll_L) : (-scroll_L));
		}
	});

});
