// Top Menu
var nowseq;

function initNavigation(seq) {
	nav = document.getElementById("topmenu");
	nav.menu = new Array();
	nav.current = null;
	nav.menuseq = 0;
	navLen = nav.childNodes.length;

	allA = nav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			nav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			nav.isOver = false;
			setTimeout(function () {
				if (nav.isOver == false) {
					if (nav.menu[seq])
						nav.menu[seq].onmouseover();
					else if(nav.current) {
						menuImg = nav.current.childNodes.item(0);
						menuImg.src = menuImg.src.replace("_on.gif", ".gif");
						if (nav.current.submenu)
							nav.current.submenu.style.display = "none";
						nav.current = null;
					}
				}
			}, 500);
		}
	}

	for (i = 0; i < navLen; i++) {
		navItem = nav.childNodes.item(i);
		if (navItem.tagName != "LI")
			continue;

		navAnchor = navItem.getElementsByTagName("a").item(0);
		navAnchor.submenu = navItem.getElementsByTagName("ul").item(0);

		navAnchor.onmouseover = navAnchor.onfocus = function () {
			if (nav.current) {
				menuImg = nav.current.childNodes.item(0);
				menuImg.src = menuImg.src.replace("_on.gif", ".gif");
				if (nav.current.submenu)
					nav.current.submenu.style.display = "none";
				nav.current = null;
			}
			if (nav.current != this) {
				menuImg = this.childNodes.item(0);
				menuImg.src = menuImg.src.replace(".gif", "_on.gif");
				if (this.submenu)
					this.submenu.style.display = "block";
				nav.current = this;
			}
			nav.isOver = true;
		}
		nav.menuseq++;
		nav.menu[nav.menuseq] = navAnchor;
	}
	if(seq)
		nowseq = seq;

	if (nav.menu[seq])
		nav.menu[seq].onmouseover();
}

function iniflashNavigationOff(seq) {
	nav = document.getElementById("topmenu");
	nav.menu = new Array();
	nav.current = null;
	nav.menuseq = 0;
	navLen = nav.childNodes.length;
	//alert(navLen);

	allA = nav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			nav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			nav.isOver = false;
			setTimeout(function () {
				if (nav.isOver == false) {
					if (nav.menu[seq])
						nav.menu[seq].onmouseover();
					else if(nav.current) {
						menuImg = nav.current.childNodes.item(0);
						if (nav.current.submenu)
							nav.current.submenu.style.display = "none";
						nav.current = null;
					}
				}
			}, 500);
		}
	}

	for (i = 0; i < navLen; i++) {
		navItem = nav.childNodes.item(i);
		if (navItem.tagName != "LI")
			continue;

		navAnchor = navItem.getElementsByTagName("a").item(0);
        navAnchor.submenu = navItem.getElementsByTagName("ul").item(0);

		navAnchor.onmouseover = navAnchor.onfocus = function () {
			if (nav.current) {
				menuImg = nav.current.childNodes.item(0);
				if (nav.current.submenu)
					nav.current.submenu.style.display = "none";
				nav.current = null;
			}
			//alert(nav.current);
			if (nav.current != this) {
				menuImg = this.childNodes.item(0);

				if (this.submenu)
						//alert(this.submenu);
					this.submenu.style.display = "none";
					//newseq = nav.menuseq;
				nav.current = this;
			}
			nav.isOver = true;
		}
		nav.menuseq++;
		nav.menu[nav.menuseq] = navAnchor;
	}
	if(seq)
		nowseq = seq;

	if (nav.menu[seq])
		nav.menu[seq].onmouseover();
}

function iniflashNavigationOn(seq) {
	nav = document.getElementById("topmenu");
	nav.menu = new Array();
	nav.current = null;
	nav.menuseq = 0;
	navLen = nav.childNodes.length;
	//alert(navLen);

	allA = nav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			nav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			nav.isOver = false;
			setTimeout(function () {
				if (nav.isOver == false) {
					if (nav.menu[seq])
						nav.menu[seq].onmouseover();
					else if(nav.current) {
						menuImg = nav.current.childNodes.item(0);
						if (nav.current.submenu)
							nav.current.submenu.style.display = "none";
						nav.current = null;
					}
				}
			}, 500);
		}
	}

	for (i = 0; i < navLen; i++) {
		navItem = nav.childNodes.item(i);
		if (navItem.tagName != "LI")
			continue;

		navAnchor = navItem.getElementsByTagName("a").item(0);
        navAnchor.submenu = navItem.getElementsByTagName("ul").item(0);

		navAnchor.onmouseover = navAnchor.onfocus = function () {
			if (nav.current) {
				menuImg = nav.current.childNodes.item(0);
				if (nav.current.submenu)
					nav.current.submenu.style.display = "none";
				nav.current = null;
			}
			//alert(nav.current);
			if (nav.current != this) {
				menuImg = this.childNodes.item(0);

				if (this.submenu)
						//alert(this.submenu);
					this.submenu.style.display = "block";
					//newseq = nav.menuseq;
				nav.current = this;
			}
			nav.isOver = true;
		}
		nav.menuseq++;
		nav.menu[nav.menuseq] = navAnchor;
	}
	if(seq)
		nowseq = seq;

	if (nav.menu[seq])
		nav.menu[seq].onmouseover();
}

// Adjust Layout
window.onload = function() {
	window.setInterval(function() {
		bodyEl = document.getElementById("body");
		subEl = document.getElementById("sub");
		if (!bodyEl || !subEl)
			return;
		if (bodyEl.offsetHeight < subEl.offsetHeight +  25) {
			bodyEl.style.height = subEl.offsetHeight + "px";
		}
	}, 200);
}

function initBoardList() {
	boardPager = document.getElementById("board-pager");
	if (boardPager)
		boardPager.getElementsByTagName("li").item(2).style.borderStyle = "none";
}
function initBoardViewPhoto() {
	imageContainer = document.getElementById("attach-photo");
	if (imageContainer) {
		imgEl = imageContainer.getElementsByTagName("img");
		for (i = 0; i < imgEl.length; i++) {
			if (imageContainer.offsetWidth < imgEl.item(i).offsetWidth) {
				imgEl.item(i).style.width = imageContainer.offsetWidth;
			}
		}
	}
}


	/* 퀵 메뉴 */
	// 메뉴가 증가할 높이
    var menu_height = 0;
    // 메뉴 높이
	var top_height=420;
	// 예전 높이;
	var old_height = 110;
	// 새높이;
	var new_height = 110;
	// 딜레이
	var scroll_delay = 20;
    // 스타트 체크
    var scroll_start = 0;
	function sub_scroll_menu(){
        if( scroll_start == 0 ) {
            scroll_start = 1
            document.getElementById('top_btn').style.top = '420px';
        }
        if(document.documentElement.scrollTop < top_height){
			new_height = top_height;
		}else{
			new_height = document.documentElement.scrollTop + 10;
		}
		var height_increment = (new_height - old_height)/10;

		if( parseInt(new_height/10) != old_height/10){
			if(new_height > old_height){
				if(height_increment < 1){
					height_increment = 1;
				}
				var re = /px/g;
				old_height = (document.getElementById('top_btn').style.top).replace(re,"");
				old_height = parseInt(old_height) + height_increment;
				if(new_height < old_height){
					old_height = new_height;
				}
				document.getElementById('top_btn').style.top = old_height + 'px';

			}else{
				if(height_increment > -1){
					height_increment = -1;
				}
				var re = /px/g;
				old_height = (document.getElementById('top_btn').style.top).replace(re,"");
				old_height = parseInt(old_height) + height_increment;
				if(new_height > old_height){
					old_height = new_height;
				}
				document.getElementById('top_btn').style.top = old_height + 'px';
			}
		}
		setTimeout ("sub_scroll_menu()", scroll_delay);

		//document.getElementById('quick_menu').style.top = document.documentElement.scrollTop + top_height + 'px';
	}