// ÀÌ¹ÌÁö ¿Â¿ÀÇÁ start
$(document).ready(function(){

 $("#gnb a, .lnb3 a, .content_top a, .nav a, .contents_1 a, .contents_2 a, .contents_3 a, .contents_4 a, .content_left a, .content_pop a, #snb a, .target_tab a, .quick a, .sub_main_contents a, #quick a, #lnb a").each(function(){
  var ele = $(this);
  var image = $(this).children("img");
  var imgsrc = $(image).attr("src");
  var ptn = /(_on)/g;
  if(ptn.test(imgsrc)){ // µðÆúÆ®·Î onÀÎ ÀÌ¹ÌÁö´Â º¯°æ ¾ÈµÇ°Ô
      $(image).addClass("on");
  }
  //add mouseOver
  $(this).mouseover(function(){
    if(typeof($(ele).children("img").attr("src")) == "undefined") return false; //ÀÌ¹ÌÁö ¾ø´Â ¸µÅ© Á¦¿Ü
    var on = imgsrc.replace(/_off/,"_on");
    if($(image).attr("class") != "on") $(image).attr("src",on);
  })
    //add mouseOut
  $(this).mouseout(function(){
    if(typeof($(ele).children("img").attr("src")) == "undefined") return false; //ÀÌ¹ÌÁö ¾ø´Â ¸µÅ© Á¦¿Ü
   var off = imgsrc.replace(/_on/,"_off");
    if($(image).attr("class") != "on") $(image).attr("src",off);
  })
  //add mouseDown
  $(this).mousedown(function(){
      if(typeof($(ele).children("img").attr("src")) == "undefined") return false; //ÀÌ¹ÌÁö ¾ø´Â ¸µÅ© Á¦¿Ü
   var dn = imgsrc.replace(/_off/,"_on");
   if($(image).attr("class") != "on") $(image).attr("src",dn);
  })

  $(this).focusin(function(){ $(this).trigger("mouseover"); }); // ÅÇÀ¸·Î Æ÷Ä¿½º ÀÌµ¿½Ã
  $(this).focusout(function(){ $(this).trigger("mouseout"); }); //ÅÇÀ¸·Î Æ÷Ä¿½º ¾Æ¿ô½Ã

 })
});
// ÀÌ¹ÌÁö ¿Â¿ÀÇÁ end

//jquery start
$(document).ready(function() {
//gnb, snb
$("#gnb li, .i_co1 a").hover(function() {
	$(this).find(".ul_ul, .la_pop, .ul_ul_wrap").show();
} , function() {
	$(this).find(".ul_ul, .la_pop, .ul_ul_wrap").hide();
});


$(document).ready(function() {
	//alert("<?=$top_menu?>");
});


$("#snb ul>li").hover(function() {
    $(this).find(".ul_ul").show()
  },
  function(){
     $(this).find(".ul_ul").hide()
    });

        //¾ÆÄÚµð¾ð
       $(".dl_click").each(function(){
            var dl = $(this);
            $(this).children("dd").css("display","none");
            $(this).children("dt").css("cursor","pointer");
            $(this).children("dt").bind("click", function(){

                if($(dl).children("dd").is(":visible")) {
                    $(dl).children("dd").slideUp();
                }else{
                    $(".dl_click dd:visible").slideUp();
                    $(dl).children("dd").slideDown();

                }
            });
        });

$(".btn_qu").hover(function() {
 $(".layer_pop_qu").show();
  },
  function(){
     $(".layer_pop_qu").hide()
    });

//¿Ã¸Þ´º
$(".btn_x").click(function() {
 $("#popup_view").toggle();
  });

});
// jquery end

//--------------------------------------------------------------------------------
// Quick Menu
//--------------------------------------------------------------------------------
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) - btmLimit - obj.offsetHeight;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {	//WebKit
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {	//WebKit
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}
//]]>
//ÀüÃ¼ ¹è°æ ·¹ÀÌ¾î ÆË¾÷ 
$(document).ready(function() {
$("#popup_bg").height($(document).height());
});

//--------------------------------------------------------------------------------
// ¿òÁ÷ÀÌ´Â ¹è³Ê(pop)
//--------------------------------------------------------------------------------
<!--
//<![CDATA[

function popImg() {
	var thisObj, args=popImg.arguments
	var tabObj = $(args[0]);
	var tabGroup = $(args[1]);
	var tabBase = $(args[2]);
	var tabBaseGroup = $(args[3]);
	var tabCount;

/*	for(i=0; i<tabGroup.length; i++){
		tabGroup[i].src = tabGroup[i].src.replace("on", "off");
		if(tabGroup[i] == tabObj[0]) tabCount = i;
	}
*/	$(tabGroup).each(function(i){
		tabGroup[i].src = tabGroup[i].src.replace("_on", "_off");
	});
	tabObj[0].src =  tabObj[0].src.replace("_off", "_on");
	if (args.length >2)
	{
		baseImg = tabBase[0].src;
		if(baseImg){
			tabBase[0].src =  baseImg.substring(0,baseImg.length-5)+(tabCount+1)+baseImg.substring(baseImg.length-4,baseImg.length);
		}
		else {
			$(tabBaseGroup).hide();
			$(tabBase[0]).show();
		}
	}
}


var curNotic = 1;
/* ÆË¾÷Á¸ ·Ñ °ü·Ã ½ºÅ©¸³Æ® */
var PopupItem = 1;
var popupMax = 7;
var timer = null;
function rollPopup(){
	var nextItem = PopupItem + 1;
	if(nextItem > popupMax ) nextItem = 1;
	showPop(PopupItem);
	PopupItem = nextItem;
}
function fnPopupMax(){
	$("ol.num>li>h2>a>img").each(function(){
		popupMax++;
	});
	popupMax = (popupMax - 1);
}
function popStart(){
	if(timer != null){
		popStop();
	}
	timer = setInterval("rollPopup()",3000);
}
function popStop(){
	clearInterval(timer);
	timer = null;
}
function showPop(s){
	var ar1 = $("ol.num>li>h2>a>img")[s-1];
	var ar2 = $("ol.num>li>h2>a>img");
	var ar3 = $("#img0"+s);
	var ar4 = $("ol.num>li>div");
	popImg(ar1,ar2,ar3,ar4);
	PopupItem = s;
}

$(document).ready(function(){
	$("ol.num>li>h2>a").focusin(function(){
		var obj = $(this)[0].firstChild;
		if(obj.alt != "stop" && obj.alt != "play"){
			var idx = obj.alt.replace("no0","");
			popStop();
			showPop(idx)
		}
	});
	$("ol.num>li>h2>a").mouseover(function(){
		var obj = $(this)[0].firstChild;
		if(obj.alt != "stop" && obj.alt != "play"){
			var idx = obj.alt.replace("no0","");
			popStop();
			showPop(idx)
		}
	});
	$("ol.num>li").mouseout(function(){
		popStart();
	});
	$("ol.num>li").mouseover(function(){
		popStop();
	});

	/* ÆË¾÷Á¸ ·Ñ ½ÃÀÛ */
	//popStart();
});
//]]>
//-->

//<![CDATA[
	// getElementsByClassName
	function getElementsByClassName(clsName,parentNode) {
		var arr = new Array();
		if (parentNode == null) {
			var elems = document.getElementsByTagName("*");
		} else {
			var elems = parentNode.getElementsByTagName("*");
		}
		for ( var cls, i = 0; ( elem = elems[i] ); i++ ) {
			if ( elem.className == clsName ) {
				arr[arr.length] = elem;
			}
		}
		return arr;
	}
	function tabDisplay(tab,content,num,type) {
		for (var i=0; i<content.length; i++) {
			var tab_off = tab[i].childNodes[0].getAttribute('src').replace(/_on|_off|_chk/i,'_off');
			var tab_on = tab[num].getElementsByTagName('img')[0].getAttribute('src').replace(/_on|_off|_chk/i,'_on');
			var tab_chk = tab[num].getElementsByTagName('img')[0].getAttribute('src').replace(/_on|_off|_chk/i,'_chk');
			tab[i].getElementsByTagName('img')[0].setAttribute('src',tab_off);
			tab[num].getElementsByTagName('img')[0].setAttribute('src',tab_chk);
			content[i].style.display = 'none';
			content[num].style.display = 'block';
		}
	}
	function tabAct(tab,content,num,type) {
		tab[num].onclick = function() {
			tabDisplay(tab,content,num);
			return false;
		}
		if (type == true) {
			var tabimg = tab[num].getElementsByTagName('img')[0];
			var tab_off = tabimg.getAttribute('src').replace(/_on|_off|_chk/i,'_off');
			var tab_on = tabimg.getAttribute('src').replace(/_on|_off|_chk/i,'_on');
			tab[num].onmouseover = function() {
				if (tabimg.getAttribute('src').indexOf('_chk') == -1) {
					tabimg.setAttribute('src',tab_on);
				}
			}
			tab[num].onmouseout = function() {
				if (tabimg.getAttribute('src').indexOf('_on') != -1) {
					tabimg.setAttribute('src',tab_off);
				}
			}
		}
	}
	//window.onload = tabMenu;  // ½ºÅ©¸³ÅÍ ¿À·ù·Î ¸·À½ (Àü½ÂÂù)
	function tabMenu() {
		var tabs = document.getElementById('tabmenu');
		var tab = tabs.getElementsByTagName('a'); // ÅÇ ¿ä¼Ò
		var contents = document.getElementById('tabcontents');
		var content = getElementsByClassName('tabcontent',contents); // ÄÁÅÙÃ÷ ¿ä¼Ò class
		var type = true; // ·Ñ¿À¹öÀÇ true / false
		for (var i=0; i<tab.length; i++) {
			tabDisplay(tab,content,0,true);
			tabAct(tab,content,i,type);
		}
	}
//]]>

$(document).ready(function(){
 $("#tab_menu h3 a").each(function(){
  $(this).css("cursor", "pointer");
  $(this).mouseover(function(){
   var index = $(this).parent().parent().index();
   var cnt = $("#tab_menu>ul>li").size();
  
   for(i = 0; i < cnt ; i++){
    $("#tab_menu>ul>li").eq(i).children("div").css("display","none");
    $("#tab_menu>ul>li").eq(i).children("h3").children("a").children("img").attr("src",$("#tab_menu>ul>li").eq(i).children("h3").children("a").children("img").attr("src").replace(/_on.gif/, "_off.gif")  )
   }
   $("#tab_menu>ul>li").eq(index).children("div").css("display","block");
    $("#tab_menu>ul>li").eq(index).children("h3").children("a").children("img").attr("src",$("#tab_menu>ul>li").eq(index).children("h3").children("a").children("img").attr("src").replace(/_off.gif/, "_on.gif")  )
  });
  $(this).bind("click focusin", function(){$(this).trigger("mouseover");});
 });
});
