/**
 * GS´ëÇ¥ µðÀÚÀÎ ½ºÅ©¸³Æ®
 */

/**
 * °ø½ÃÁ¤º¸ ÆË¾÷
 */
function openInvestPublic(url) {
	window.open(url, 'investPublic', 'width=800,height=559');
	return false;
}


/**
 * °øÅë ½ºÅ©¸³Æ® (»çÀÌÆ® Àü¹ÝÀûÀ¸·Î »ç¿ëµÇ´Â ½ºÅ©¸³Æ®)
 */

// image roll
function menuOver() {
	this.src = this.src.replace(".gif", "_on.gif");
}
function menuOut() {
	this.src = this.src.replace("_on.gif", ".gif");
}

function sltOn(slt) {
	if (document.getElementById(slt)) {
		document.getElementById(slt).src = document.getElementById(slt).src.replace(".gif", "_on.gif");
	}
}

function imageOver(imgEl) {
	document.getElementById(imgEl).src = document.getElementById(imgEl).src.replace(".gif", "_on.gif");
}
function imageOut(imgEl) {
	document.getElementById(imgEl).src = document.getElementById(imgEl).src.replace("_on.gif", ".gif");
}

// family site
function startFamilySiteScroll() {
	setTimeout("slideFamilySite()", 10);
}
function slideFamilySite() {
	el = document.getElementById("related-site-list");

	if (el.heightPos == null || (el.isDone && el.isOn == false)) {
		el.isDone = false;
		el.heightPos = 0;
		el.heightTo = 110;
	} else if (el.isDone && el.isOn){
		el.isDone = false;
		el.heightTo = 0;
	}
	if (Math.abs(el.heightTo - el.heightPos) > 1) {
		el.heightPos += (el.heightTo - el.heightPos) / 10;
		el.style.height = el.heightPos + "px";
		startFamilySiteScroll();
	} else {
		if (el.heightTo == 110) {
			el.isOn = true;
		} else {
			el.isOn = false;
		}
		el.heightPos = el.heightTo;
		el.style.height = el.heightPos + "px";
		el.isDone = true;
	}
}


// element toggle
function blockToggle(href) {
	targetElement = document.getElementById(href.split("#")[1]);

	if (targetElement && targetElement.style.display == "block") {
		targetElement.style.display = "none";
	} else {
		targetElement.style.display = "block";
	}
	return false;
}


// tabbed menu
function initTabMenu(menuElId) {
	var tabMenu = document.getElementsByName("tab");
	for(i=0; i<tabMenu.length; i++) {
		thismenu = tabMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		thismenu.targetEl = document.getElementById(tabMenu.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		/*
		if (thismenu.getElementsByTagName("img").item(0)) {
			thismenu.getElementsByTagName("img").item(0).onmouseover = menuOver;
			thismenu.getElementsByTagName("img").item(0).onmouseout = menuOut;
		}
		*/
		thismenu.onclick = tabMenuClick;
	}

	initmenu = tabMenu.item(0);
	initmenu.targetEl.style.display = "block";
	/*
	if (initmenu.getElementsByTagName("img").item(0)) {
		initmenu.getElementsByTagName("img").item(0).onmouseover();
		initmenu.getElementsByTagName("img").item(0).onmouseover = null;
		initmenu.getElementsByTagName("img").item(0).onmouseout = null;
	}
	*/
	initmenu.getElementsByTagName("img").item(0).src = initmenu.getElementsByTagName("img").item(0).src.replace(".gif", "_on.gif");
	initmenu.menuContainer.current = initmenu;
}
function tabMenuClick() {
	currentmenu = this.menuContainer.current;
	if (currentmenu != this) {
		currentmenu.targetEl.style.display = "none";
		/*
		if (currentmenu.getElementsByTagName("img").item(0)) {
			currentmenu.getElementsByTagName("img").item(0).onmouseover = menuOver;
			currentmenu.getElementsByTagName("img").item(0).onmouseout = menuOut;
			currentmenu.getElementsByTagName("img").item(0).onmouseout();
		}
		*/
		currentmenu.getElementsByTagName("img").item(0).src = currentmenu.getElementsByTagName("img").item(0).src.replace("_on.gif", ".gif")
	
		this.targetEl.style.display = "block";
		/*
		if (this.getElementsByTagName("img").item(0)) {
			this.getElementsByTagName("img").item(0).onmouseover = null;
			this.getElementsByTagName("img").item(0).onmouseout = null;
		}
		*/
		this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace(".gif", "_on.gif");
		this.menuContainer.current = this;
	}
	return false;
}

/**
 * ¸Þ´º, ÇöÀçÀ§Ä¡ ½ºÅ©¸³Æ®
 
// convert menu text to image
function initTopNavigation() {
	// change top menu text to image
	topMenuEl = document.getElementById("top-navigation").getElementsByTagName("li");
	for (i=0; i<topMenuEl.length; i++) {
		var menuAnchor = topMenuEl[i].getElementsByTagName("a")[0];
		menuAnchor.innerHTML = "<input type=\"image\" name=\"p_menucode\" src=\"/Images/skin01/color001/top/" + topMenuEl[i].className + ".gif\" id=\"" + topMenuEl[i].className + "\" alt=\"" + menuAnchor.innerHTML + "\" value=\"AA010" +topMenuEl[i].className.substr(5,1)+ "\" />";
		menuAnchor.getElementsByTagName("input").item(0).onmouseover = menuOver;
		menuAnchor.getElementsByTagName("input").item(0).onmouseout = menuOut;
	}

	// remove slashed background image of first menu item
	topMenuD2El = document.getElementsBySelector("#top-navigation ul.depth2");
	for (i=0; i<topMenuD2El.length; i++) {
		topMenuD2El[i].getElementsByTagName("li").item(0).style.background = "none";
	}
}
*/

// top menu action
var currentMenu;	// current shown menu (mouse over)
var focusMenu;	// current page menu
var menu = new Array();	// each menu array

function initNavigation(seq) {
	for(i=1; i<10; i++) {
		menu[i] = document.getElementsBySelector("#top-navigation li.menu-" + i)[0];
		menu[i].onmouseover = navigationOver;
		menu[i].onmouseout = navigationOut;

		menu[i].submenu = document.getElementsBySelector("#top-navigation li.menu-" + i +" ul.depth2")[0];
		menu[i].submenu.menu = menu[i];
		menu[i].submenu.onmouseover = subOver;

	}
}
function initFocus() {		// current page menu focusing
	if (focusMenu) {
		currentMenu = focusMenu;
	} else {
		currentMenu = null;
	}
	showSubmenu();
}
function navigationOver() {		// onmouseover
	hideSubmenu();
	if (focusMenu) {
		focusMenu.submenu.style.display = "none";
	}
	currentMenu = this;
	showSubmenu();
//	document.getElementById("body").innerHTML = document.getElementById("body").innerHTML + "nav over<br>"
}
function navigationOut() {		// onmouseout
	this.isMenuOver = false;
	setTimeout("hideSubmenu()", 500);
}
function showSubmenu() {
	if (currentMenu) {
		currentMenu.submenu.style.display = "block";
		currentMenu.isMenuOver = true;
	}
}
function hideSubmenu() {
	if (currentMenu && !currentMenu.isMenuOver) {
		currentMenu.submenu.style.display = "none";
		currentMenu.isMenuOver = false;
		initFocus();
	}
}
function subOver() {
	this.menu.isMenuOver = true;
}


/**
function initLocation() {
	initNavigation();

	if (document.getElementById("location")) {
		loc = document.getElementById("location").getElementsByTagName("a");
	
		if (document.getElementById("top-navigation") && document.getElementById("top-navigation").getElementsByTagName("li")) {
			topMenuLi = document.getElementById("top-navigation").getElementsByTagName("li");
			for(j=0; j<topMenuLi.length; j++) {
				topMenuText = topMenuLi[j].getElementsByTagName("img").item(0).alt;
				if (loc.item(1) && topMenuText == loc.item(1).innerHTML) {		// top menu depth1
					focusMenu = menu[topMenuLi[j].className.substr(topMenuLi[j].className.length-1, 1)];
					initFocus();
					if (currentMenu.getElementsByTagName("img").item(0).src.indexOf("_on.gif") == -1) {
						currentMenu.getElementsByTagName("img").item(0).onmouseover();
					}
					currentMenu.getElementsByTagName("img").item(0).onmouseover = null;
					currentMenu.getElementsByTagName("img").item(0).onmouseout = null;
				}
				if (loc.item(2) && topMenuText == loc.item(2).innerHTML) {		// top menu depth2
					topMenuLi[j].getElementsByTagName("img").item(0).onmouseover();
					topMenuLi[j].getElementsByTagName("img").item(0).onmouseover = null;
					topMenuLi[j].getElementsByTagName("img").item(0).onmouseout = null;
				}
			}
		}
	}
}
*/

/**
 * ¹Ù·Î°¡±â
 */
function viewExtLink() {
	target = this.href;
	linkEl = document.getElementById(target.split("#")[1]);
	if (linkEl.style.display == "block") {
		linkEl.style.display = "none";
	} else {
		linkEl.style.display = "block";
	}
	return false;
}
function initExtLink() {
	extLinkEl = document.getElementById("ext-link");
	extLinkElH2 = extLinkEl.getElementsByTagName("h2");
	for(i=0; i<extLinkElH2.length; i++) {
		extLinkElH2[i].getElementsByTagName("a")[0].onclick = viewExtLink;
	}
}

/**
 * µðÀÚÀÎ º¸Á¤¿ë ½ºÅ©¸³Æ® (CSS µðÀÚÀÎ Àç±¸¼º¿ë ½ºÅ©¸³Æ®)
 */

// layout adjust
window.onload = function adjustLayout() {
	if (document.getElementById("sub") && document.getElementById("body")) {
		if (document.getElementById("sub").offsetHeight > document.getElementById("body").offsetHeight) {
			document.getElementById("body").style.height = document.getElementById("sub").offsetHeight + "px";
		}
	}
	
	//set page print button
	if (document.getElementById("page-print")) {
		document.getElementById("page-print").onclick = function () {
			window.print();
			return false;
		}
	}
}

// board design adjust
function initBoardList() {
	cssFirstChild(document.getElementsBySelector("div.board-list table.list tbody tr"), "first-child");

	boardRowEl = document.getElementsBySelector("div.board-list table.list tbody tr");
	for(i=0; i<boardRowEl.length; i++) {
		boardRowEl[i].onmouseover = function boardListRowOver() {
			this.className = this.className + " over";
		}
		boardRowEl[i].onmouseout = function boardListRowOut() {
			this.className = this.className.replace("over", "");
		}
	}
}
function initBoardView() {
	cssFirstChild(document.getElementsBySelector("div.board-view table.list tbody tr"), "first-child");
}

// sitemap layout adjust
function initSitemap() {
	for(i=1; i<19; i++) {
		sitemapDepth1 = document.getElementsBySelector("#sitemap li.menu-" + i)[0];
		sitemapDepth1Anchor = sitemapDepth1.getElementsByTagName("a")[0];
		sitemapDepth1Anchor.innerHTML = "<img src=\"/images/guide/sitemap-" + sitemapDepth1.className + ".gif\" alt=\"" + sitemapDepth1Anchor.innerHTML + "\" />";
	}
	// IE Bug Fix
	document.getElementsBySelector("#sitemap li.menu-3")[0].style.height = document.getElementsBySelector("#sitemap li.menu-2")[0].offsetHeight + "px";
	document.getElementsBySelector("#sitemap li.menu-10")[0].style.height = document.getElementsBySelector("#sitemap li.menu-8")[0].offsetHeight + "px";
}
// css first-child
function cssFirstChild(el, clsname) {
	if (el[0]) {
		if (el[0].className) {
			el[0].className = el[0].className + " " + clsname;
		} else {
			el[0].className = clsname;
		}
	}
}

// tabbed menu
/**
function initTabMenu(menuElId) {
	var tabMenu = document.getElementsByName("tab");
	for(i=0; i<tabMenu.length; i++) {
		thismenu = tabMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		thismenu.targetEl = document.getElementById(tabMenu.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		if (thismenu.getElementsByTagName("img").item(0)) {
			thismenu.getElementsByTagName("img").item(0).onmouseover = menuOver;
			thismenu.getElementsByTagName("img").item(0).onmouseout = menuOut;
		}
		thismenu.onclick = tabMenuClick;
	}

	initmenu = tabMenu.item(0);
	initmenu.targetEl.style.display = "block";
	if (initmenu.getElementsByTagName("img").item(0)) {
		initmenu.getElementsByTagName("img").item(0).onmouseover();
		initmenu.getElementsByTagName("img").item(0).onmouseover = null;
		initmenu.getElementsByTagName("img").item(0).onmouseout = null;
	}
	initmenu.menuContainer.current = initmenu;
}
function tabMenuClick() {
	currentmenu = this.menuContainer.current;
	if (currentmenu != this) {
		currentmenu.targetEl.style.display = "none";
		if (currentmenu.getElementsByTagName("img").item(0)) {
			currentmenu.getElementsByTagName("img").item(0).onmouseover = menuOver;
			currentmenu.getElementsByTagName("img").item(0).onmouseout = menuOut;
			currentmenu.getElementsByTagName("img").item(0).onmouseout();
		}
	
		this.targetEl.style.display = "block";
		if (this.getElementsByTagName("img").item(0)) {
			this.getElementsByTagName("img").item(0).onmouseover = null;
			this.getElementsByTagName("img").item(0).onmouseout = null;
		}
		this.menuContainer.current = this;
	}
	return false;
}
*/

/* 
 * css3 background property implementation
 * Author : http://hyeonseok.com
 * version : alpha (20050227)
 * usage
	css3Background(document.getElementById("thisElement"), "background: url(topleft.gif) no-repeat 0 0, background: url(bottomright.gif) no-repeat 100% 100%");
 */
function css3Background(element, backgroundString) {
	if (!element) {
		return false;
	}
	// getStyle script form http://www.quirksmode.org/dom/getstyles.html
	if (window.getComputedStyle) {
		padding = window.getComputedStyle(element,null).getPropertyValue("padding-top");
		padding += " " + window.getComputedStyle(element,null).getPropertyValue("padding-right");
		padding += " " + window.getComputedStyle(element,null).getPropertyValue("padding-bottom");
		padding += " " + window.getComputedStyle(element,null).getPropertyValue("padding-left");
	} else if (element.currentStyle) {
		padding = eval('element.currentStyle.' + "paddingTop");
		padding += " " + eval('element.currentStyle.' + "paddingRight");
		padding += " " + eval('element.currentStyle.' + "paddingBottom");
		padding += " " + eval('element.currentStyle.' + "paddingLeft");
	}
	
	// save content
	originalHTML = element.innerHTML;
	element.innerHTML = "";

	// create div element and layering
	backgroundEach = backgroundString.split(",");
	for (i=0; i<backgroundEach.length; i++) {
		backgroundProperty = backgroundEach[i].replace("background:", "");
	
		el = document.createElement("div");
		if (i==0) {
			element.style.padding = "0";
		}
		el.style.background = backgroundProperty;
		element.appendChild(el);
		element = el;
	}

	element.style.padding = padding;
	element.innerHTML = originalHTML;
	return true;
}

/* document.getElementsBySelector(selector)
	 - returns an array of element objects from the current document
		 matching the CSS selector. Selectors can contain element names, 
		 class names and ids and can be nested. For example:
		 
			 elements = document.getElementsBySelect('div#main p a.external')
		 
		 Will return an array of all 'a' elements with 'external' in their 
		 class attribute that are contained inside 'p' elements that are 
		 contained inside the 'div' element which has id="main"

	 New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
	 See http://www.w3.org/TR/css3-selectors/#attribute-selectors

	 Version 0.4 - Simon Willison, March 25th 2003
	 -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
	 -- Opera 7 fails 
*/

function getAllChildren(e) {
	// Returns all children of element. Workaround required for IE5/Windows. Ugh.
	return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
	// Attempt to fail gracefully in lesser browsers
	if (!document.getElementsByTagName) {
		return new Array();
	}
	// Split selector in to tokens
	var tokens = selector.split(' ');
	var currentContext = new Array(document);
	for (var i = 0; i < tokens.length; i++) {
		token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
		if (token.indexOf('#') > -1) {
			// Token is an ID selector
			var bits = token.split('#');
			var tagName = bits[0];
			var id = bits[1];
			var element = document.getElementById(id);
			if (tagName && element.nodeName.toLowerCase() != tagName) {
				// tag with that ID not found, return false
				return new Array();
			}
			// Set currentContext to contain just this element
			currentContext = new Array(element);
			continue; // Skip to next token
		}
		if (token.indexOf('.') > -1) {
			// Token contains a class selector
			var bits = token.split('.');
			var tagName = bits[0];
			var className = bits[1];
			if (!tagName) {
				tagName = '*';
			}
			// Get elements matching tag, filter them for class selector
			var found = new Array;
			var foundCount = 0;
			for (var h = 0; h < currentContext.length; h++) {
				var elements;
				if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
				} else {
						elements = currentContext[h].getElementsByTagName(tagName);
				}
				for (var j = 0; j < elements.length; j++) {
					found[foundCount++] = elements[j];
				}
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			for (var k = 0; k < found.length; k++) {
				if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
					currentContext[currentContextIndex++] = found[k];
				}
			}
			continue; // Skip to next token
		}
		// Code to deal with attribute selectors
		if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
			var tagName = RegExp.$1;
			var attrName = RegExp.$2;
			var attrOperator = RegExp.$3;
			var attrValue = RegExp.$4;
			if (!tagName) {
				tagName = '*';
			}
			// Grab all of the tagName elements within current context
			var found = new Array;
			var foundCount = 0;
			for (var h = 0; h < currentContext.length; h++) {
				var elements;
				if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
				} else {
						elements = currentContext[h].getElementsByTagName(tagName);
				}
				for (var j = 0; j < elements.length; j++) {
					found[foundCount++] = elements[j];
				}
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			var checkFunction; // This function will be used to filter the elements
			switch (attrOperator) {
				case '=': // Equality
					checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
					break;
				case '~': // Match one of space seperated words 
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
					break;
				case '|': // Match start with value followed by optional hyphen
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
					break;
				case '^': // Match starts with value
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
					break;
				case '$': // Match ends with value - fails with "Warning" in Opera 7
					checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
					break;
				case '*': // Match ends with value
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
					break;
				default :
					// Just test for existence of attribute
					checkFunction = function(e) { return e.getAttribute(attrName); };
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			for (var k = 0; k < found.length; k++) {
				if (checkFunction(found[k])) {
					currentContext[currentContextIndex++] = found[k];
				}
			}
			// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
			continue; // Skip to next token
		}
		// If we get here, token is JUST an element (not a class or ID selector)
		tagName = token;
		var found = new Array;
		var foundCount = 0;
		for (var h = 0; h < currentContext.length; h++) {
			var elements = currentContext[h].getElementsByTagName(tagName);
			for (var j = 0; j < elements.length; j++) {
				found[foundCount++] = elements[j];
			}
		}
		currentContext = found;
	}
	return currentContext;
}



/* That revolting regular expression explained 
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
	\---/	\---/\-------------/		\-------/
		|			|				 |							 |
		|			|				 |					 The value
		|			|		~,|,^,$,* or =
		|	 Attribute 
	 Tag
*/


//ÇÃ·¡½¬ (ie¼³°èº¯°æ)
function MakeFlash(strFileUrl,strWidth,strHeight,strBgColor,strWMode,strBrowerType){
	var strProto = document.location.protocol + "//";
	
	if (strBgColor == "")
		strBgColor = "#ffffff";
	
	if (strWMode == "")
		strWMode = "window";
	
		
	if(strBrowerType == "IE"){	//ieÀÏ °æ¿ì
		document.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"" + strProto +"download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9.0.0.0\" width=\"" + strWidth + "\" height=\"" + strHeight + "\">");
		document.writeln("<param name=\"movie\" value=\"" + strFileUrl + "\" />");
		document.writeln("<param name=\"wmode\" value=\"" + strWMode + "\" />");	
		document.writeln("</object>");	
	}else{
		document.writeln("<object type=\"application/x-shockwave-flash\" data=\"" + strFileUrl + "\" width=\"" + strWidth + "\" height=\"" + strHeight + "\">");
		document.writeln("<param name=\"wmode\" value=\"" + strWMode + "\" />");	
		document.writeln("</object>");	
	}
}

function MakeMPlayer(strFileUrl,strWidth,strHeight,strBrowerType){
	if(strBrowerType == "IE"){	//ieÀÏ °æ¿ì
		document.writeln("<object id=\"WindowsMediaPlayer7\" width=\"" + strWidth + "\" height=\"" + strHeight + "\" classid=\"clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6\" type=\"application/x-oleobject\">");	
		document.writeln("<param name=\"url\" value=\"" + strFileUrl + "\" />");
		document.writeln("</object>");
	}else{
		document.writeln("<object type=\"video/x-ms-wmv\" data=\"" + strFileUrl + "\" width=\"" + strWidth + "\" height=\"" + strHeight + "\">");
		document.writeln("<p>no plug-ins</p>");
		document.writeln("</object>");
	}	
}