<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<script>
<!-- 
var menuTxt = "";
var clickGroupNo = "-1";
var clickUpperNo = "";
var clickMenuNo = "";
var groupTopNo = "";

function isExistData(){
	if(menuTxt == ""){
		return false;
	} else {
		return true;
	}
}

function gFncSetGNB(){
	<c:forEach var="result" items="${list_headmenu}" varStatus="status" >
		if( 2 == "${result.level}" ) {
			groupTopNo = "${result.menuNo}";
			if( clickGroupNo == "" ) {
				clickGroupNo = "${result.menuNo}";	
			}
		}
		menuTxt += "ㆅ${result.level}ㆂ${result.nextLevel}ㆂ${result.urlPath}ㆂ${result.menuName}ㆂ${result.menuNo}ㆂ${result.upperMenuNo}ㆂ"+groupTopNo;
	</c:forEach>
	gFncGetGNB();
}

if(menuTxt == ""){
	gFncSetGNB();
}

function gFncGetGNB(){
	gFncDrawGNB(menuTxt);
}

function gFncSetTopNo(pClickGroupNo, pClickUpperNo, pClickMenuNo){
	clickGroupNo=pClickGroupNo;
	clickUpperNo=pClickUpperNo;
	clickMenuNo=pClickMenuNo;
}

function gFncGetGroupNo(){
	return clickGroupNo;
}

function gFncGetUpperNo(){
	return clickUpperNo;
}

function gFncGetMenuNo(){
	return clickMenuNo;
}

function gFncGetLnbData(){
	var menuList = menuTxt.split("ㆅ");
	var lnbMenuTxt = "";
	for(var i=0;i<menuList.length;i++){
		if(menuList[i] == "" ) {
			
		} else {
			if( menuList[i].indexOf("ㆂ"+clickGroupNo) > -1 && (" "+menuList[i]).indexOf(" 2ㆂ") < 0 ){
				lnbMenuTxt += "ㆅ"+menuList[i];
			}
		}
	}
	gFncDrawLNB(lnbMenuTxt);
}

function gFncDrawLNB(pOrgMenuList){
	var menuList = pOrgMenuList.split("ㆅ");
	var menuItem = "";
	var prevLevel = 0;
	var strMenuTxt = "";
	var contextPath = '${pageContext.request.contextPath}';
	
	for(var i=0;i<menuList.length;i++){
		if(menuList[i] == "" ) {
			
		} else {
			menuItem = menuList[i].split("ㆂ");
			
			//0:level, 1:nextLevel, 2:urlPath, 3:menuName, 4:menuNo, 5:upperMenuNo, 6:groupTopNo
			if( menuItem[0] == 3) {
				if( prevLevel > menuItem[0]*1 ){
					strMenuTxt += "</ul></li>";
				}
				if( menuItem[1] <= 3 ) {
					if( top.topFrame.gFncGetMenuNo() == menuItem[4] ) {
						className = " class='nav-active'";
					} else {
						className = "";
					}
					
					strMenuTxt += "<li"+className+"><a href='#' onclick=\"location.replace('"+contextPath+""+menuItem[2]+"');top.topFrame.gFncSetTopNo('"+menuItem[6]+"','"+menuItem[5]+"','"+menuItem[4]+"');\">"+menuItem[3]+"</a></li>";
				} else {
					if( top.topFrame.gFncGetUpperNo() == menuItem[4] ) {
						className = " nav-expanded";
					} else {
						className = "";	
					}
					
					strMenuTxt += "<li class='nav-parent"+className+"'>";
					strMenuTxt += "<a href='#'>"+menuItem[3]+"</a>";
					strMenuTxt += "<ul class='nav nav-children'>";
				}
			} else if( menuItem[0] == 4) {
				
				if( top.topFrame.gFncGetMenuNo() == menuItem[4] ) {
					className = " class='nav-active'";
				} else {
					className = "";
				}
				
				strMenuTxt += "<li"+className+"><a href='#' onclick=\"location.replace('"+contextPath+""+menuItem[2]+"');top.topFrame.gFncSetTopNo('"+menuItem[6]+"','"+menuItem[5]+"','"+menuItem[4]+"');\">"+menuItem[3]+"</a></li>";
				if( menuItem[0]*1 < menuItem[1]*1 ){
					strMenuTxt += "</ul>";
				}
			}
			prevLevel = menuItem[0]*1;
		}
	}
	if( prevLevel == 4 ){
		strMenuTxt += "</ul></li>";
	} else if( prevLevel == 3 ){
		strMenuTxt += "</li>";
	} else {
		strMenuTxt += "";
	}
	$("#lnbArea").html(strMenuTxt);	
	
	(function( $ ) {
		'use strict';
		var $items = $( '.nav-main li.nav-parent' );
		function expand( li ) {
			li.children( 'ul.nav-children' ).slideDown( 'fast', function() {
				li.addClass( 'nav-expanded' );
				$(this).css( 'display', '' );
				ensureVisible( li );
			});
		}

		function collapse( li ) {
			li.children('ul.nav-children' ).slideUp( 'fast', function() {
				$(this).css( 'display', '' );
				li.removeClass( 'nav-expanded' );
			});
		}

		function ensureVisible( li ) {
			var scroller = li.offsetParent();
			if ( !scroller.get(0) ) {
				return false;
			}

			var top = li.position().top;
			if ( top < 0 ) {
				scroller.animate({
					scrollTop: scroller.scrollTop() + top
				}, 'fast');
			}
		}

		$items.find('> a').on('click', function() {
			var prev = $( this ).closest('ul.nav').find('> li.nav-expanded' ),
				next = $( this ).closest('li');

			if ( prev.get( 0 ) !== next.get( 0 ) ) {
				collapse( prev );
				expand( next );
			} else {
				collapse( prev );
			}
		});
	}).apply( this, [ jQuery ]);
}
// -->
</script>
</head>
</html>