﻿$(function() {
	// SNB Initialize
	function snbInit(dep1, dep2){
		var tDep1	= jQuery(".snb");
		var imgSrc 	= "";
		tDep1.find("li > ul").hide();
		tDep1.find("li."+ dep1 +" > ul").show();
		if(dep2 != ""){
			tDep1.find("li."+ dep1 +" > ul > li:eq("+ dep2 +")").addClass("on");
			imgSrc2 = tDep1.find(".on > a > img").attr("src");
			imgSrc2 = imgSrc2.replace("_act.gif","_off.gif");
			imgSrc2 = imgSrc2.replace("_off.gif","_act.gif");
			tDep1.find(".on > a > img").attr("src",imgSrc2)
		}
		for(var i=0; i<tDep1.find(">li").size(); i++){
			imgSrc = tDep1.find(">li:eq("+ i +") > a > img").attr("src");
			imgSrc = imgSrc.replace("_on.gif","_off.gif");
			tDep1.find(">li:eq("+ i +") > a > img").attr("src",imgSrc);
		}

		imgSrc = tDep1.find("."+ dep1 +" > a > img").attr("src");
		imgSrc = imgSrc.replace("_on.gif","_off.gif");
		imgSrc = imgSrc.replace("_off.gif","_on.gif");
		tDep1.find("."+ dep1 +" > a > img").attr("src",imgSrc);
	}

	jQuery("#header, #content, #footer").click(function(){
		try{
			snbInit(vDep1, vDep2);
		} catch(e){}
	});

	try{
		snbInit(vDep1, vDep2);
	} catch(e){}
});

jQuery(document).ready(function() {
	// SNB 마우스 오버시 색변환
	jQuery(".snb li ul li a").mouseover(function(){
		var temp = $(this).children();
		var oriImg = temp.attr("src");
		var currImg = oriImg.replace("_off.gif","_on.gif");
		temp.attr("src",currImg);
	}).focusin(function(){
		var temp = $(this).children();
		var oriImg = temp.attr("src");
		var currImg = oriImg.replace("_off.gif","_on.gif");
		if(oriImg.indexOf("_off.gif") != -1){
			temp.attr("src",currImg);
		}
	});
	jQuery(".snb li ul li a").mouseout(function() {
		var temp = $(this).children();
		var oriImg = temp.attr("src");
		var currImg = oriImg.replace("_on.gif","_off.gif");
		temp.attr("src",currImg);
	}).focusout(function(){
		var temp = $(this).children();
		var oriImg = temp.attr("src");
		var currImg = oriImg.replace("_on.gif","_off.gif");
		temp.attr("src",currImg);
	});
});


jQuery(document).ready(function() {
	// GNB 숨기기
	for(var i=1; i<=8; i++){
		$("#sNavi0" + i).hide();
	}
	$(".gnb_bg").hide();

	// GNB 열기
	$("#gNavi").children().mouseover(function(){gnbShow();}).focusin(function() {gnbShow();});
	
	// GNB 닫기
	$("#header h1 a").mouseover(function(){gnbHide();}).focusin(function() {gnbHide();});
	$("#header .main_banner").mouseover(function(){gnbHide();}).focusin(function() {gnbHide();});
	$("#global").mouseover(function(){gnbHide();}).focusin(function() {gnbHide();});
	$("#container").mouseover(function(){gnbHide();}).focusin(function() {gnbHide();});
	$("#footer").mouseover(function(){gnbHide();}).focusin(function() {gnbHide();});
	
	// GNB 마우스 오버시 색변환
	$("#gNavi ul li a").mouseover(function(){
		var temp 	= $(this).children();
		var oriImg	= temp.attr("src");
		var currImg	= oriImg.replace("_off.gif","_on.gif");
		temp.attr("src",currImg);
		
	}).focusin(function(){
		var temp 	= $(this).children();
		var oriImg	= temp.attr("src");
		var currImg	= oriImg.replace("_off.gif","_on.gif");
		if(oriImg.indexOf("_off.gif") != -1){
			temp.attr("src",currImg);
		}
	});
	$("#gNavi ul li a").mouseout(function() {
		var temp 	= $(this).children();
		var oriImg	= temp.attr("src");
		var currImg	= oriImg.replace("_on.gif","_off.gif");
		temp.attr("src",currImg);
	}).focusout(function(){
		var temp 	= $(this).children();
		var oriImg	= temp.attr("src");
		var currImg	= oriImg.replace("_on.gif","_off.gif");
		temp.attr("src",currImg);
	});
});

// GNB Show
function gnbShow(){
	if(gnbEffectFlag == 0){
		gnbEffectFlag = 1;
		$(".gnb_bg").slideDown("fast",function() {
			$("#gNavi").slideDown("fast").css("height","165px");
			$("#sNavi0" + i).show();
		});
		for(var i=1; i<=8; i++){
			$("#gNavi li ul").css("height","130px");
			$("#sNavi0" + i).show();
		}
	}
}

// GNB Hide
function gnbHide(){
	if(gnbEffectFlag == 1){
		for(var i=1; i<=8; i++){
			$("#sNavi0" + i).hide(function(){
				$("#gNavi li ul").slideUp("fast").css("height","0px");
				$(this).hide();
			});
		}
		$(".gnb_bg").slideUp(function(){
			gnbEffectFlag = 0;
			$("#gNavi").css("height","13px");
			$(this).hide();
		});
	}
}

// 입력폼 초기문구 셋팅 onfocus시
function tSetIn(obj){
	if (obj.value == obj.title){
		obj.value = "";
	}
}

// 입력폼 초기문구 셋팅 onblur시
function tSetOut(obj){
	if (obj.value == ""){
		obj.value = obj.title;
	}
}

$(document).ready(function() { // 페이지 로딩이 끝나면 처리합니다.
	$(".ifrm", parent.document).height($(document).height());  // 부모창에있는 아이프레임(클래스가 ifrm인) 높이 조절
});


//팝업 스크립트
function _popup(w_url, w_name, w_width, w_height) {
	var newwin,
		w_left = (screen.width - w_width)/2,
		w_top = (screen.height - w_height)/2,
		w_options = 'width='+ w_width +', height='+ w_height +', left='+ w_left +', top='+ w_top +', scrollbars=no';

	newwin = open(w_url, w_name, w_options);
	if(window.focus) newwin.focus();
	return false;
};




// 패밀리 사이트 롤링 배너
function fmRolling(chat, tmp){
	this.wrap = document.getElementById(chat);
	this.wrapBtn = this.wrap.getElementsByTagName("BUTTON");
	this.obj = document.getElementById(tmp);
	this.objLi = this.obj.getElementsByTagName("LI");
	this.course = "left";
	this.move = true;
	this.loop = 0;
	this.currentOver = 5;

	this.target = this.objLi[0].offsetWidth;
	this.obj.style.position = "absolute";
	this.obj.style.width = 3000 + "px";

	var func = this;
	this.actionMove = setInterval(function() { func.action() }, 30)
	this.fmPlay();
	for(i=0; i<this.wrapBtn.length; i++){
		this.wrapBtn[i].style.position = "absolute";
		this.wrapBtn[i].style.zIndex = 100;
	}
}
fmRolling.prototype.fmFrev = function(){
	this.course = "left";
	(this.loop == (this.currentOver - this.objLi.length)) ? this.loop = 0 : this.loop--;
}
fmRolling.prototype.fmStop = function(){
	clearInterval(this.changeMove);
	this.wrapBtn[1].style.zIndex = 99;
}
fmRolling.prototype.fmPlay = function(){
	var func = this;
	this.changeMove = setInterval(function() { func.change() }, 5000);
	this.wrapBtn[1].style.zIndex = 100;
}
fmRolling.prototype.fmNext = function(){
	this.course = "right";
	(this.loop == 0) ? this.loop = this.currentOver - this.objLi.length : this.loop++;
}
fmRolling.prototype.action = function(){
	var obj = this.obj;
	var course = this.course;
	var move = true;
	var loop = this.loop;
	var target = this.target;

	var curPosition = parseFloat(obj.style.left);
	var tarPosition = (course == "left") ? Math.floor(0.2 * ((target * loop) - curPosition)) : Math.ceil(0.2 * ((target * loop) - curPosition))
	obj.style.left = (parseFloat(obj.style.left) + tarPosition) + "px";
}
fmRolling.prototype.change = function(){
	if(this.course == "left"){
		(this.loop == (this.currentOver - this.objLi.length)) ? this.fmNext() : this.fmFrev();
	} else {
		(this.loop == 0) ? this.fmFrev() : this.fmNext();
	}
}

//롤오버 2차방법
function imgMenuOver(containderID) {
	var objwrap = document.getElementById(containderID);
	var imgMenu = objwrap.getElementsByTagName("li");
	
	for (i=0; i<imgMenu.length; i++) {
		if(imgMenu[i].getElementsByTagName("img").length == 0) continue;		

		if (imgMenu[i].getElementsByTagName("img")[0].src.indexOf("_over.gif") != -1 ) {		
			continue;
		}
		imgMenu[i].onmouseover = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
			//alert(subImage.src);
		}
		imgMenu[i].onfocus = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
			//alert(subImage.src);
		}
		imgMenu[i].onmouseout = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
		imgMenu[i].onblur = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
	}
}


jQuery(document).ready(function() {
	// 패밀리 사이트 레이어
	jQuery(".family_site .fs_list").hide();
	jQuery(".family_site .fs_btn").click(function() {
		jQuery(".family_site .fs_list").toggle();
		jQuery(this).focusin(function() {jQuery(".family_site .fs_list").hide();});
	});
	jQuery(".family_site .fs_list a").click(function() {
		jQuery(".family_site .fs_list").hide();
	});
	jQuery(".page_move li a").focusin(function() {jQuery(".fs_list").hide();});
	jQuery(".txt_size ul li button").focusin(function() {jQuery(".fs_list").hide();});
	jQuery("#wrapper").click(function() {jQuery(".family_site .fs_list").hide();});
	jQuery("#site_banner").click(function() {jQuery(".family_site .fs_list").hide();});
	/*$('.fs_subject').css({'width':$('.fs_list').width()})*/
});
