$(document).ready(function() {

	// 코너가 둥근 박스만들기
	$("#header .login").corner();
	$("#header .find_idpw").corner();

	//로그인
	$("#header .snb .list li.first a").click(function() {
		$("#header .login").fadeIn(130);
		document.login_form.login_id.focus();
	});
	$("#header .login .close a").click(function() {
		$("#header .login").fadeOut(130);			
	});

	//로그인 포커스 되었을 때 배경 없애기
	$("#header .login .login_field .id input, #header .login .login_field .pw input ").bind({
		focus: function() {	
			$(this).addClass("no_bg");
		},
		blur: function() {
			var THIS_VAL = $.trim($(this).val());
			if ( THIS_VAL == "" ) {
				$(this).removeClass("no_bg");
				$(this).val("");
			} 
		},
		keyup: function() {
			if (event.keyCode == 13)
			{
				var ret = check_login_form(document.login_form);
				if (ret == true) document.login_form.submit();
			}
		}

	});

	//아이디_비밀번호 찾기
	$("#header .login a.get").click(function() {
		$("#header .find_idpw").fadeIn(130);
	});
	$("#header .find_idpw .close a").click(function() {
		$("#header .find_idpw").fadeOut(130);			
	});

	//GNB
	GNB();

	//따라다니는 스크롤
	SCROLL_TOP();

	IMG_HOVER(".body_box01 .numbering a");

	//프리뷰 - 추천회원보기
	$(".poplayer_recommend_member").click(function() {
		$(this).parent().parent().parent().next(".recommend_member_layer").fadeIn(130);
		return false;
	});	
	$(".recommend_member_layer .close a").click(function() {
		$(this).parent().parent().fadeOut(130);
		return false;
	});

	$(".preview_list01 .recommend_member_layer:eq(0)").css("top","60px");
	$(".preview_list01 .recommend_member_layer:eq(1)").css("top","170px");
	$(".preview_list01 .recommend_member_layer:eq(2)").css("top","280px");
	$(".preview_list01 .recommend_member_layer:eq(3)").css("top","390px");
	$(".preview_list01 .recommend_member_layer:eq(4)").css("top","500px");

	$(".recommend_member_preview_layer .close a").click(function() {
		$(this).parent().parent().fadeOut(130);
		return false;
	});
});

//이미지 온오프
function IMG_HOVER(OBJ) {
	$(OBJ).hover(
		function() {
			var IMG_ON = $(this).find("img").attr("src").replace("_off","_on");
			$(this).find("img").attr("src", IMG_ON);
		},
		function() {
			if ( $(this).attr("class") != "selected" )
			{
				var IMG_OFF = $(this).find("img").attr("src").replace("_on","_off");
				$(this).find("img").attr("src", IMG_OFF);	
			}
		}
	);
}

//GNB
function GNB() {
	IMG_HOVER("#header .gnb .list li a");

	

	$("#header .gnb .order01 a").hover(
		function() {
			$("#header .gnb .sub_menu").hide();
			$("#header .gnb .sub01").show();			
		},
		function() {
			if ( $(this).attr("class") != "selected" ) {
				$("#header .gnb .sub01").hide();			
			}
			if ( $("#header .gnb .order02 a").attr("class") == "selected" ) {
				$("#header .gnb .sub02").show();			
			}
		}
	);

	$("#header .gnb .sub01").hover(
		function() {
			var IMG_ON = $("#header .gnb .list .order01 a img").attr("src").replace("_off","_on");
			$("#header .gnb .list .order01 a img").attr("src", IMG_ON);
			$("#header .gnb .sub02").hide();
			$("#header .gnb .sub01").show();			
		},
		function() {			
			if ( $("#header .gnb .list .order01 a").attr("class") != "selected" )
			{
				var IMG_OFF = $("#header .gnb .list .order01 a img").attr("src").replace("_on","_off");
				$("#header .gnb .list .order01 a img").attr("src", IMG_OFF);
				$("#header .gnb .sub01").hide();
			}	
			if ( $("#header .gnb .order02 a").attr("class") == "selected" ) {
				$("#header .gnb .sub02").show();			
			}
			
		}
	);

	$("#header .gnb .order02 a").hover(
		function() {
			$("#header .gnb .sub_menu").hide();
			$("#header .gnb .sub02").show();			
		},
		function() {
			if ( $(this).attr("class") != "selected" ) {
				$("#header .gnb .sub02").hide();			
			} 
			if ( $("#header .gnb .order01 a").attr("class") == "selected" ) {
				$("#header .gnb .sub01").show();			
			}
		}
	);

	$("#header .gnb .sub02").hover(
		function() {
			var IMG_ON = $("#header .gnb .list .order02 a img").attr("src").replace("_off","_on");
			$("#header .gnb .list .order02 a img").attr("src", IMG_ON);
			$("#header .gnb .sub01").hide();
			$("#header .gnb .sub02").show();			
		},
		function() {			
			if ( $("#header .gnb .list .order02 a").attr("class") != "selected" )
			{
				var IMG_OFF = $("#header .gnb .list .order02 a img").attr("src").replace("_on","_off");
				$("#header .gnb .list .order02 a img").attr("src", IMG_OFF);
				$("#header .gnb .sub02").hide();				
			}	
			if ( $("#header .gnb .order01 a").attr("class") == "selected" ) {
				$("#header .gnb .sub01").show();			
			}
			
		}
	);

}


// 따라다니는 스크롤
function SCROLL_TOP() {
  var $doc           = $(document);
  var position       = 0;
  var top = $doc.scrollTop(); //현재 스크롤바 위치
  var screenSize     = 0;        // 화면크기
  var halfScreenSize = 0;    // 화면의 반

  /*사용자 설정 값 시작*/
  var pageWidth      = 1000; // 페이지 폭, 단위:px
  var leftOffet      = 490;  // 중앙에서의 폭(왼쪽 -, 오른쪽 +), 단위:px
  var leftMargin     = 909; // 페이지 폭보다 화면이 작을때 옵셋, 단위:px, leftOffet과 pageWidth의 반만큼 차이가 난다.
  var speed          = 1500;     // 따라다닐 속도 : "slow", "normal", or "fast" or numeric(단위:msec)
  var easing         = 'swing'; // 따라다니는 방법 기본 두가지 linear, swing
  var $layer         = $('#floating'); // 레이어 셀렉팅
  var layerTopOffset = 188;   // 레이어 높이 상한선, 단위:px
  $layer.css('z-index', 10);   // 레이어 z-인덱스
  /*사용자 설정 값 끝*/

  //좌우 값을 설정하기 위한 함수
  function resetXPosition()
  {
    $screenSize = $('body').width();// 화면크기
    halfScreenSize = $screenSize/2;// 화면의 반
    xPosition = halfScreenSize + leftOffet;
    if ($screenSize < pageWidth)
      xPosition = leftMargin;
    $layer.css('left', xPosition);
  }

  // 스크롤 바를 내린 상태에서 리프레시 했을 경우를 위해
  if (top > 0 )
    $doc.scrollTop(layerTopOffset+top);
  else
    $doc.scrollTop(0);

  // 최초 레이어가 있을 자리 세팅
  $layer.css('top',layerTopOffset);
  resetXPosition();
  //윈도우 크기 변경 이벤트가 발생하면
  $(window).resize(resetXPosition);

  //스크롤이벤트가 발생하면
  $(window).scroll(function(){
    yPosition = $doc.scrollTop()+layerTopOffset;
    $layer.animate({"top":yPosition }, {duration:speed, easing:easing, queue:false});
  });
}

//로그인 팝업
function login_popup()
{
	window.open("../member/member_LoginForm.php","loginform" , "width=400px,height=300px;");
}
