

function initCurrentMenu(parntObj){
	var $obj = $(parntObj);

	if ( $obj.is("li") )
	{
		initCurrentMenu($obj.parnt());
	}
	else if ( $obj.is("ul") )
	{
		$obj.show();
	}
}

// scrollTop button
$(document).ready(function() {
	var currentTop = parseInt($(".scrollTop").css("top"));
	$(window).scroll(function() {
		$(".scrollTop").stop().animate({"top": $(window).scrollTop()+currentTop+"px"}, 1000);
	});
});


// all Menu
$(document).ready(function() {
	$(".gnb ul li").mouseenter(function() {
	  $(".allmenuList, .allMenu_bg").show();
	  $(".mainbox1").css({"z-index":"10"});
	});
	$(".allmenuList, .allMenu_bg").mouseleave(function() {
	  $(".allMenu_bg, .allmenuList").hide();
	  $(".mainbox1").css({"z-index":"500"});
	});
	$(".closeBtn").click(function() {
	  $(".allmenuList, .allMenu_bg").css({"display":"none"});
	});
	$('.allmenuList ul li a').mouseover( function () {	
		var $child = $(this).find('img');
		var $src = $child.attr('src');
		$src = $src.replace("off", "on");
		$child.attr({'src':$src});
	});
	$('.allmenuList ul li a').mouseout( function () {
		var $child = $(this).find('img');
		var $src = $child.attr('src');
		$src = $src.replace("on", "off");
		$child.attr({'src':$src});
	});	
});



/* left Menu
$(document).ready(function() {
	initMenu();		
});
function initMenu() {
	$('ul.subMenu').hide();	
	
	// mouse over
	$('li.menu a').mouseover( function () {
		var $src = $(this).children().attr('src');
		$(this).children().hide();
		$src = $src.replace("off", "on");
		$(this).children().attr({'src':$src});
		$(this).children().stop().fadeTo(1000, 1);
	});

	// mouse out
	$('li.menu a').mouseout( function () {
		var $src = $(this).children().attr('src');
		$(this).children().hide();
		$src = $src.replace("on", "off");
		$(this).children().attr({'src':$src});
		$(this).children().stop().fadeTo('slow', 1);
	});
	
	// mouse click
	$('li.menu a').click( function () {
		var checkElement = $(this).next();
		if ((checkElement.is('ul')) && (checkElement.is(':visible')))
		{
			checkElement.stop().slideUp('slow');
			return false;
		}
		if ((checkElement.is('ul')) && (!checkElement.is(':visible')))
		{
			$('ul.subMenu:visible').slideUp('slow');
			checkElement.stop().slideDown('slow');
			return false;
		}
		else
		{
			$('ul.subMenu:visible').slideUp('slow');
		}
	});
}
*/

jQuery.fn.initMenu = function() {  
    return this.each(function(){
        var theMenu = $(this).get(0);
        $('.subMenu', this).hide();
        $('li.expand > .subMenu', this).show();
        $('li.expand > .subMenu', this).prev().addClass('active');
        $('li a', this).click(
            function(e) {
                e.stopImmediatePropagation();
                var theElement = $(this).next();
                var parent = this.parentNode.parentNode;
                if($(parent).hasClass('noaccordion')) {
                   
                	if(theElement[0] == undefined) {
                        // window.location.href = this.href;
                		return;
                    }
                    
                	// subMenuOn 이 아닌 경우만 토글 실행.
                	if ( !theElement.hasClass('subMenuOn') ){
	
	                    $(theElement).slideToggle('normal', function() {
	                        if ($(this).is(':visible')) {
	                            $(this).prev().addClass('active');
	                        }
	                        else {
	                            $(this).prev().removeClass('active');
	                        }    
	                    });
	                    return false;
                	}
                }
                else {
                	
                    if(theElement.hasClass('subMenu') && theElement.is(':visible')) {
                        if($(parent).hasClass('collapsible')) {
                            $('.subMenu:visible', parent).first().slideUp('normal', 
                            function() {
                                $(this).prev().removeClass('active');
                            }
                        );
                        return false;  
                    }
                    
                }
                
                /*
                if(theElement.hasClass('subMenu') && !theElement.is(':visible')) {         
                    $('.subMenu:visible', parent).first().slideUp('normal', function() {
                        $(this).prev().removeClass('active');
                    });
                    theElement.slideDown('normal', function() {
                        $(this).prev().addClass('active');
                    });
                    return false;
                }
                */
            }
        }
    );
});
};

$(document).ready(function() {
	$('.leftMenu').initMenu();
});


$(document).ready(function() {
	$('.leftMenu li a').mouseover( function () {	
		var $child = $(this).find('img');
		var $src = $child.attr('src');
		$src = $src.replace("off", "on");
		$child.attr({'src':$src});
	});
	// mouse out
	$('.leftMenu li a').mouseout( function () {
		var $child = $(this).find('img');
		if ( $child.hasClass("on") ){
			return;
		}
		
		var $src = $child.attr('src');
		$src = $src.replace("on", "off");
		$child.attr({'src':$src});
	});	
});


/* 탭 1 */
var tabToggleRolling = new Array();
function tabToggle(obj,tab,img,tnum,roll) {
	if(tab=='random'){
		var rnum = Math.floor(Math.random() * tnum) + 1;
		tab = rnum;
	}
	if(tab=='rolling'){
		tabToggleRolling[roll] = (!tabToggleRolling[roll])?1:tabToggleRolling[roll]+1;
		if(tabToggleRolling[roll]>tnum) tabToggleRolling[roll] = 1;
		tab = tabToggleRolling[roll];
	}
	if(tnum=='rolling'){
		tabToggleRolling[roll] = tab;
		tab = tabToggleRolling[roll];
	}
	var tab_list = document.getElementById(obj).getElementsByTagName('li');
	for(i=1;i<=tab_list.length;i++){
		(tab==i)?tab_list[i-1].className='on':tab_list[i-1].className='';
		document.getElementById(obj+'_'+i).style.display = (tab==i)?'':'none';
		if(img){
			var imgEl=tab_list[i-1].getElementsByTagName("img").item(0);
			//imgEl.src = (tab==i)? imgEl.src.replace("off.gif", "on.gif"):imgEl.src.replace("on.gif", "off.gif");
		}
	}
}

function tabToggleRoll(type,obj,tab,img,tnum,roll){
	eval("(type=='start')? ctr"+roll+" = setInterval(\"tabToggle('"+obj+"','"+tab+"','"+img+"','"+tnum+"','"+roll+"')\",2000) : clearTimeout(ctr"+roll+");");
}

/* 탭2 */
jQuery(function($){
	// List Tab Navigation
	var tab_list = $('div.contentTabList');
	var tab_list_i = tab_list.find('>ul>li');
	tab_list_i.find('>ul').hide();
	tab_list.find('>ul>li[class=active]').find('>ul').show();
	tab_list.css('height', tab_list.find('>ul>li.active>ul').height()+10);
	function listTabMenuToggle(event){
		var t = $(this);
		tab_list_i.find('>ul').hide();
		t.next('ul').show();
		tab_list_i.removeClass('active');
		t.parent('li').addClass('active');
		tab_list.css('height', t.next('ul').height()+10);
		return false;
	}
	tab_list_i.find('>a[href=#]').click(listTabMenuToggle).focus(listTabMenuToggle);
});

/* 탭 이미지 롤오버 */
$(document).ready(function(){
	$(".contentTabMenu ul li, .contactTab ul li, .business_bn ul li").each(function(){
		var link = $(this).children("a");
		var image = $(link).children("img");
		var imgsrc = $(image).attr("src");
		// add mouseover
		$(link).mouseover(function(){
			var on = imgsrc.replace("off", "on");
			$(image).attr("src",on);
		});
		// add mouse out
		$(link).mouseout(function(){
			$(image).attr("src",imgsrc);
		});
	});
});



/* Main Image Rolling */

function slideSwitch() {
    var $active = $('.rolling IMG.active');
    if ( $active.length == 0 ) $active = $('.rolling IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('.rolling IMG:first');
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 3300 );
});


$(function(){
	try{
		$('#slides').slides({
			preload: true,
			preloadImage: 'img/loading.gif',
			play: 5000,
			pause: 2500,
			hoverPause: true
		});
	}catch(e){}
});



// 영문메인 Photo Gallery
function initScrollContent(container, prevBtn, nextBtn) {
	var currentContentPage = 1;
	var contentElCount = 0;
	var content_x = 0;
	var slideContentTo = 0;
	var contentWidth = 450;
	var isImageBtn = true;
	var cont = container.getElementsByTagName("div");

	for (i=0; i<cont.length; i++) {
		if (cont[i].className == "slideContent") {
			contentElCount++;
			cont[i].style.left = contentWidth * (contentElCount - 1) + "px";
		}
	}

	setSlideBtn();

	function setSlideBtn() {
		if (contentElCount == 1) {
			setPrevBtn("off");
			setNextBtn("off");
		} else if (parseInt(currentContentPage) == 1) {
			setPrevBtn("off");
			setNextBtn("on");
		} else if (parseInt(currentContentPage) == contentElCount) {
			setPrevBtn("on");
			setNextBtn("off");
		} else {
			setPrevBtn("on");
			setNextBtn("on");
		}
	}
	function setPrevBtn(condition) {
		if (condition == "on") {
			prevBtn.onclick = viewPrev;
			if (isImageBtn) prevBtn.src = prevBtn.src.replace("_off.gif", ".gif");
			prevBtn.className = prevBtn.className.replace(" off", "");
			prevBtn.className += " on";
		} else {
			prevBtn.onclick = "";
			if (isImageBtn) prevBtn.src = prevBtn.src.replace(".gif", "_off.gif");
			prevBtn.className = prevBtn.className.replace(" on", "");
			prevBtn.className += " off";
		}
	}
	function setNextBtn(condition) {
		if (condition == "on") {
			nextBtn.onclick = viewNext;
			if (isImageBtn) nextBtn.src = nextBtn.src.replace("_off.gif", ".gif");
			nextBtn.className = nextBtn.className.replace(" off", "");
			nextBtn.className += " on";
		} else {
			nextBtn.onclick = "";
			if (isImageBtn) nextBtn.src = nextBtn.src.replace(".gif", "_off.gif");
			nextBtn.className = nextBtn.className.replace(" on", "");
			nextBtn.className += " off";
		}
	}
	function viewPrev() {
		slideContentTo += contentWidth;
		currentContentPage = parseInt(currentContentPage) - 1;
		setSlideBtn();
		startScroll();
	}
	function viewNext() {
		slideContentTo -= contentWidth;
		currentContentPage = parseInt(currentContentPage) + 1;
		setSlideBtn();
		startScroll();
	}
	function startScroll() {
		setTimeout(
			function slideContent() {
				if (Math.abs(content_x - slideContentTo) > 1) {
					content_x += (slideContentTo - content_x) * .15;
					container.style.left = content_x + "px";
					startScroll();
				} else {
					content_x = slideContentTo;
					container.style.left = content_x + "px";
				}
			}

		, 25);
	}
}


// Layer Popup Mask
$(document).ready(function(){
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn(80).css({ 'width': Number( popWidth ) }).prepend('');
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		//$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		//$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		return false;
	});
	/*Close Popups and Fade Layer
	$('.closeBtn').live('click', function() { //When clicking on the close or fade layer...
	  	$('.popupBox, #fade').fadeOut(function() {
			$('#fade, a.close').remove();
	}); //fade them both out
		
		return false;
	});*/
	$('.popopClose').click(function() {
		$('.mainLayerPopup').hide();
	});
});


// Main layer 팝업
function main_layer_popup() {
	var pop = document.getElementById("mainLayer1");
	var btn = document.getElementById("close");
	pop.style.display = "block";
	btn.onclick = function() {
		this,pop.style.display = "none";
	}
}

function main_layer_popup2() {
	var pop = document.getElementById("mainLayer2");
	var btn = document.getElementById("close2");
	pop.style.display = "block";
	btn.onclick = function() {
		this,pop.style.display = "none";
	}
}



// 영문 Main Icon Box
$(document).ready(function(){
	$(".iconlist_01").mouseover(function() {$(".cmt_01").show();});
	$(".iconlist_02").mouseover(function() {$(".cmt_02").show();});
	$(".iconlist_03").mouseover(function() {$(".cmt_03").show();});
	$(".iconlist_04").mouseover(function() {$(".cmt_04").show();});
	$(".iconlist_05").mouseover(function() {$(".cmt_05").show();});
	//$(".iconlist_06").mouseover(function() {$(".cmt_06").hide();});
	$(".iconlist_07").mouseover(function() {$(".cmt_07").show();});
	$(".iconlist_08").mouseover(function() {$(".cmt_08").show();});
	$(".iconlist_09").mouseover(function() {$(".cmt_09").show();});
	$(".iconlist_10").mouseover(function() {$(".cmt_10").show();});
	$(".iconlist_11").mouseover(function() {$(".cmt_11").show();});

	$(".iconlist_01").mouseout(function() {$(".cmt_01").hide();});
	$(".iconlist_02").mouseout(function() {$(".cmt_02").hide();});
	$(".iconlist_03").mouseout(function() {$(".cmt_03").hide();});
	$(".iconlist_04").mouseout(function() {$(".cmt_04").hide();});
	$(".iconlist_05").mouseout(function() {$(".cmt_05").hide();});
	//$(".iconlist_06").mouseout(function() {$(".cmt_06").show();});
	$(".iconlist_07").mouseout(function() {$(".cmt_07").hide();});
	$(".iconlist_08").mouseout(function() {$(".cmt_08").hide();});
	$(".iconlist_09").mouseout(function() {$(".cmt_09").hide();});
	$(".iconlist_10").mouseout(function() {$(".cmt_10").hide();});
	$(".iconlist_11").mouseout(function() {$(".cmt_11").hide();});
});



function popupWinWithNoScroll(sUrl, nWidth, nHeight) {
    nLeft = (window.screen.width - nWidth ) / 2;
    nTop  = (window.screen.height- nHeight) / 3.5;
    sF  = "";
    sF += "toolbar=no,location=no,menubar=no,status=no,directories=no,resizable=no,scrollbars=no";
    sF += ",left=" + nLeft;
    sF += ",top=" + nTop;
    sF += ",width=" +  nWidth;
    sF += ",height=" + nHeight;
    window.open(sUrl, "", sF);
}

