/* roll over-out image */
function menuOver() {
	this.src = this.src.replace(".gif", "_ov.gif");
}
function menuOut() {
	this.src = this.src.replace("_ov.gif", ".gif");
}

function initImgEffect(ImgEls,SelImg) {
	
	MenuImg = document.getElementById(ImgEls).getElementsByTagName("img");
	MenuImgLen = MenuImg.length;

	for (i=0; i<MenuImgLen; i++) {
		MenuImg.item(i).onmouseover = menuOver;
		MenuImg.item(i).onmouseout = menuOut;
		if (i == SelImg) {
			MenuImg.item(i).onmouseover();
			MenuImg.item(i).onmouseover = null;
			MenuImg.item(i).onmouseout = null;
		}
	}
}

/* IE HTML rewrite */
function IE_HtmlRewrite(objParent) {
	if (window.ActiveXObject && objParent) {
		objParent.innerHTML = objParent.innerHTML;
	}
}


/* list toggle */
function initToggleList(ulEl, que, ans) {
	currentListNum = false;
	queEl = ulEl.getElementsByTagName(que);
	ansEl = ulEl.getElementsByTagName(ans);
	
	for (i=0;i<queEl.length;i++) {
		ansEl.item(i).listNum = i;
		queEl.item(i).listNum = i;
		ansEl.item(i).className = "off";
		queEl.item(i).onclick = toggleList;
	}
}
function toggleList () {
	if (currentListNum && currentListNum != this.listNum + 1) {
		queEl.item(currentListNum-1).className = null;
		ansEl.item(currentListNum-1).className = "off";
	}
	if (ansEl.item(this.listNum).className == "on") {
		queEl.item(this.listNum).className = null;
		ansEl.item(this.listNum).className = "off";
	} else {
		queEl.item(this.listNum).className ="on";
		ansEl.item(this.listNum).className ="on";
	}
	currentListNum = this.listNum + 1;
}


// top menu action
var currentMenu;	// current shown menu (mouse over)
var focusMenu;	// current page menu
var menu = new Array();	// each menu array

/**
 * Ace Golf top menu
 */
function initNavigation(seq) {
	var menuseq = 0;
	nav = document.getElementById("topmenu");
	menuEl = nav.getElementsByTagName("dl");

	for(i = 0; i < menuEl.length; i++) {
		if (menuEl.item(i).className.length == 8) {
			menu[i] = menuEl.item(i);
			menu[i].onmouseover = function navigationOver() {
				hideSubmenu();
				currentMenu = this;
				showSubmenu();
			}
			menu[i].onmouseout = function navigationOut() {
				this.isMenuOver = false;
				setTimeout("hideSubmenu()", 500);
			}
	
			menu[i].submenu = menu[i].getElementsByTagName("ul").item(0);
			if (menu[i].submenu) {
				menu[i].submenu.menu = menu[i];
				menu[i].submenu.onmouseover = subOver;
				menu[i].submenu.getElementsByTagName("dl").item(0).className = "first";
			}
			
			menu[i].menuimg = menu[i].getElementsByTagName("img").item(0);
			menu[i].menuimg.style.position = "relative";
			menu[i].menuimg.style.zIndex = menuEl.length - i;
			menu[i].menuimg.menunum = menuEl.length;

			menuseq++;
			if (menuseq == seq) {
				focusMenu = menu[i]
			}
		}
	}
	initFocus();
}
function initFocus() {		// current page menu focusing
	if (focusMenu) {
		currentMenu = focusMenu;
	} else {
		currentMenu = null;
	}
	showSubmenu();
}
function showSubmenu() {
	if (currentMenu && !currentMenu.isMenuOver) {
		menuimg = currentMenu.getElementsByTagName("img").item(0);
		menuimg.style.zIndex = parseInt(menuimg.style.zIndex) + menuimg.menunum;
		menuimg.src = menuimg.src.replace(".gif", "_ov.gif");

		if (currentMenu.submenu) {
			currentMenu.submenu.style.display = "block";
		}
		currentMenu.isMenuOver = true;

		if (focusMenu && currentMenu != focusMenu) {
			focusMenu.submenu.style.display = "none";
		}
	}
}
function hideSubmenu() {
	if (currentMenu && !currentMenu.isMenuOver) {
		menuimg = currentMenu.getElementsByTagName("img").item(0);
		menuimg.style.zIndex = parseInt(menuimg.style.zIndex) - menuimg.menunum;
		menuimg.src = menuimg.src.replace("_ov.gif", ".gif");

		if (currentMenu.submenu) {
			currentMenu.submenu.style.display = "none";
		}
		currentMenu.isMenuOver = false;

		if (focusMenu && currentMenu != focusMenu) {
			focusMenu.submenu.style.display = "block";
		}
		initFocus();
	}
}
function subOver() {
	this.menu.isMenuOver = true;
}

/**
 * Tab Content
 */
function initTabMenu(menuContainerID) {
	
	var tabAnchor = document.getElementById(menuContainerID).getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;
		thismenu.menuContainer = document.getElementById(menuContainerID);
		thismenu.targetEl = document.getElementById(thismenu.href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		if (thismenu.getElementsByTagName("img").item(0)) {
			thismenu.getElementsByTagName("img").item(0).onmouseover = function () {
				this.src = this.src.replace(".gif", "_ov.gif");
			}
			thismenu.getElementsByTagName("img").item(0).onmouseout = function () {
				this.src = this.src.replace("_ov.gif", ".gif");
			}
		}

		thismenu.onclick = tabMenuClick;
		
		if (!thismenu.menuContainer.first) {
			thismenu.menuContainer.first = thismenu;
		}
	}
	document.getElementById(menuContainerID).first.onclick();
}
function tabMenuClick() {
	currentmenu = this.menuContainer.current;

	if (currentmenu != this) {
		if (currentmenu) {
			currentmenu.targetEl.style.display = "none";
			if (currentmenu.getElementsByTagName("img").item(0)) {
				currentmenu.getElementsByTagName("img").item(0).onmouseover = function () {
					this.src = this.src.replace(".gif", "_ov.gif");
				}
				currentmenu.getElementsByTagName("img").item(0).onmouseout = function () {
					this.src = this.src.replace("_ov.gif", ".gif");
				}
				currentmenu.getElementsByTagName("img").item(0).onmouseout();
			//} else {
			//	currentmenu.className = currentmenu.className.replace(" on", "");
			}
			currentmenu.className = currentmenu.className.replace(" on", "");
		}

		this.targetEl.style.display = "block";
		if (this.getElementsByTagName("img").item(0)) {
			this.getElementsByTagName("img").item(0).onmouseout();
			this.getElementsByTagName("img").item(0).onmouseover();
			this.getElementsByTagName("img").item(0).onmouseover = null;
			this.getElementsByTagName("img").item(0).onmouseout = null;
		//} else {
		//	this.className += " on";
		}
		if (this) {
			this.className += " on";
		}
		this.menuContainer.current = this;
	}
	return false;
}

/**
 * Tab Content
 */
function newsInitTabMenu(menuContainerID) {
	
	var tabAnchor = document.getElementById(menuContainerID).getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;
		thismenu.menuContainer = document.getElementById(menuContainerID);
		thismenu.targetEl = document.getElementById(thismenu.href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		if (thismenu.getElementsByTagName("img").item(0)) {
			thismenu.getElementsByTagName("img").item(0).onclick = function () {
				this.src = this.src.replace(".gif", "_ov.gif");
			}
		}

		thismenu.onclick =  newsTabMenuClick;
		
		if (!thismenu.menuContainer.first) {
			thismenu.menuContainer.first = thismenu;
		}
	}
	document.getElementById(menuContainerID).first.onclick();
}
function newsTabMenuClick() {
	currentmenu = this.menuContainer.current;
	
	if (currentmenu != this) {
		if (currentmenu) {
			currentmenu.targetEl.style.display = "none";
			if (currentmenu.getElementsByTagName("img").item(0)) {
				currentmenu.getElementsByTagName("img").item(0).src = currentmenu.getElementsByTagName("img").item(0).src.replace("_ov.gif", ".gif");
				currentmenu.getElementsByTagName("img").item(0).onclick = function () {
					this.src = this.src.replace(".gif", "_ov.gif");
				}
			}
			currentmenu.className = currentmenu.className.replace(" on", "");
		}

		this.targetEl.style.display = "block";
		if (this.getElementsByTagName("img").item(0)) {
			this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("_ov.gif", ".gif");
			this.getElementsByTagName("img").item(0).onclick();
			this.getElementsByTagName("img").item(0).onclick = null;
		}
		if (this) {
			this.className += " on";
		}
		this.menuContainer.current = this;
	}
	return false;
}

/**
 * www.rrl.go.kr submenu
 */
function initSubmenu(depth1, depth2, depth3) {
	selectDepth1 = "menu" + depth1 + "-" + depth2;
	selectDepth2 = "menu" + depth1 + "-" + depth2 + "-" + depth3;
	
	nav = document.getElementById("sub");
	menuEl = nav.getElementsByTagName("dl");
		

	for(i = 0; i < menuEl.length; i++) {
		if (menuEl.item(i).id == selectDepth1 || menuEl.item(i).id == selectDepth2  ) {
			menuEl.item(i).getElementsByTagName("img").item(0).src = menuEl.item(i).getElementsByTagName("img").item(0).src.replace(".gif", "_ov.gif");
		} else {
			menuEl.item(i).getElementsByTagName("img").item(0).onmouseover = menuOver;
			menuEl.item(i).getElementsByTagName("img").item(0).onmouseout = menuOut;
			if (menuEl.item(i).getElementsByTagName("ul").item(0)) {
				menuEl.item(i).getElementsByTagName("ul").item(0).style.display = "none";
			}
		}
	}
}
function applyScriptCss(linkCss) {
	document.write(linkCss);
}



function initMoving(target) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = 600;
	obj.initLeft = 900;
	obj.bottomLimit = document.documentElement.scrollHeight - 220;
	obj.topLimit = 550;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;
	obj.style.top = obj.top + "px";
	obj.style.left = obj.left + "px";

	obj.getTop = function() {
		if (document.documentElement.scrollTop) {
			return document.documentElement.scrollTop;
		} else if (window.pageYOffset) {
			return window.pageYOffset;
		} else {
			return 0;
		}
	}
	obj.getHeight = function() {
		if (self.innerHeight) {
			return self.innerHeight;
		} else if(document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		} else {
			return 500;
		}
	}
	obj.move = setInterval(function() {
		pos = obj.getTop() + obj.getHeight() / 2 - 15;

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit
		if (pos < obj.topLimit)
			pos = obj.topLimit

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 40)
}



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;
}











