// JavaScript Document
// 강태희
// gnb

$(function(){
	$('.total_sh .input_txt').one('focus',function(){
		$(this).attr('value','')
	})
	$('.total_menu').hide()
	$('.total_m a').click(function(){
		$('.total_menu').show()
		return false;
	})
	$('.total_menu .close').click(function(){
		$('.total_menu').hide()
	})

	var menuover=false; //메뉴가 활성화 되고있는지 파악
	var clearenter
	function imgOn(item){	//공통 이미지 변경
		var image = item.find("img");
		var imgsrc = $(image).attr("src");
		var on = imgsrc.replace(/_off.gif/,"_on.gif");
		$(image).attr("src",on);
	}
	function imgOff(item){
		var image = item.find("img");
		for(var i=0;i<image.length;i++){
			var imgsrc = $(image[i]).attr("src");
			var off = imgsrc.replace(/_on.gif/,"_off.gif");
			$(image[i]).attr("src",off);
		}
	}
	var gnb_link_depth1=$("#gnb>ul>li");	//해당 gnb
	var gnb_link_depth2=$("#gnb>ul>li>ul>li");	//해당 gnb
	$('#gnb>ul>li>ul').find('li:last').addClass('end')
	var lnb=$(".lnb li");	//해당 gnb

    gnb_link_depth1.each(function(){
        //add mouseOver
        $(this).bind('mouseenter keyup' , function()    {
            imgOff(gnb_link_depth1)
            clearTimeout(clearenter)
            imgOn($(this).find('>a'))
            $(this).addClass("on").siblings().removeClass("on");
            menuover=true;
        });

        //add mouseOut
        $(this).bind(' blur' , function()    {//mouseleave
//            imgOff($(this))
            menuover=false;
            clearenter = setTimeout(menuclear,1000)
        });
    });
    function menuclear(){
        if(!menuover){
	        gnb_link_depth1.removeClass("on"); //지워야할 클래스위치
			imgOff(gnb_link_depth1)
        }
    }

	gnb_link_depth2.each(function(){
        //add mouseOver
        $(this).bind('mouseover keyup' , function()    {
            clearTimeout(clearenter)
            imgOn($(this))
            $(this).addClass("on").siblings().removeClass("on");
            menuover=true;
        });

        //add mouseOut
        $(this).bind('mouseout blur' , function()    {
            imgOff($(this))
            menuover=false;
            clearenter = setTimeout(menuclear,1000)
        });
    });
	lnb.each(function(){
        //add mouseOver
        $(this).bind('mouseover keyup' , function()    {
           imgOff(lnb)
            imgOn($(this))
            $(this).addClass("on").siblings().removeClass("on");
        });
        //add mouseOut
        $(this).bind('mouseout blur' , function()    {
           // imgOff($(this))
           // $(this).parend().siblings().removeClass("on");

        });
    });

    $(".rv a").bind('mouseover keyup' , function()    { imgOn($(this))})     //roll over
    $(".rv a").bind('mouseout blur' , function()    { imgOff($(this))})

    var tablist = $(".notice_tab ul")    //tab ON OFF  - 최근게시물
    var tabtitlist = $(".notice_tab h2 a")
	$(tablist[0]).addClass('on')

    $(tabtitlist).each(function(){
        $(this).bind('keyup click' , function()    {
			var a = tabtitlist.index(this)+1
			$(this).parent().parent().removeClass()
			$(this).parent().parent().addClass('notice_tab_'+a+'_on notice_tab')
            $(this).parent().siblings().removeClass("on")
            $(this).parent().next().addClass("on")
				return false;
        })
    })

	var popupzone = $('.popupzone') // 팝업존
	var list_item = $('.popupzone_area li') // 리스트 아이템
    var list_ul =  $('.popupzone_area ul') // 리스트 포지션
    var movie_dep = 0 //position left value
    var dep_step = 363
    var dep_left = 0 // 현재위치
    var max = list_item.length

    var play_inter
	var list_num = $('.popupzone_number button')
	var delay_time = 20000
	$(list_num[0]).addClass('on')
	popupzone.each(function(){
		$(this).bind('mouseenter' , function()    {
			clearInterval(play_inter);
        })
		$(this).bind('mouseleave' , function(){
			play_inter = setInterval(popup_play,delay_time)
		})
	})
	list_num.each(function(){
		$(this).bind('click' , function()    {
			clearInterval(play_inter);
			movie_dep = -dep_step * $(list_num).index(this)
			list_ul.css("left",movie_dep)
			dep_left = $(list_num).index(this)
			$(this).parent().addClass('on').siblings().removeClass("on")
		})
	})

	$(".pop_right").click(function(){
		$('.area').scrollLeft(0);
		if (movie_dep >=  - dep_step * (max-2)){
			movie_dep = movie_dep - dep_step
			list_ul.css("left",movie_dep)
			dep_left += 1
			$(list_num[dep_left]).parent().addClass('on').siblings().removeClass("on")
		}else{
		}
		return false;
	  })
		$(".pop_left").click(function(){
			$('.area').scrollLeft(0);
			if (movie_dep >=0)
			{
			}else{
				movie_dep=movie_dep + dep_step
				list_ul.css("left",movie_dep)
				dep_left -= 1
				$(list_num[dep_left]).parent().addClass('on').siblings().removeClass("on")
			}
			return false;
		})
		$(".pop_play").bind('click' , function()    {
			clearInterval(play_inter);
			play_inter = setInterval(popup_play,delay_time) // 시간
		})
		$(".pop_stop").bind('click' , function()    {
			clearInterval(play_inter);
		})

		function popup_play(){
			if (movie_dep >=  - dep_step * (max-2)){
				movie_dep = movie_dep - dep_step
				list_ul.css("left",movie_dep)
				dep_left += 1
			}else{
				dep_left = movie_dep = 0
				list_ul.css("left",movie_dep)
			}
			$(list_num[dep_left]).parent().addClass('on').siblings().removeClass("on")
		}
	//$('.right').trigger("click"); //
	play_inter = setInterval(popup_play,delay_time) // 시간
});//ready
