
/* roll over-out image */
function menuOver() {
	this.src = this.src.replace(".gif", "_on.gif");
}
function menuOut() {
	this.src = this.src.replace("_on.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;
	}
}

/* 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("li");


	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", "_on.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)
}
function lecOpen() {
	window.open('/utility/lecture.jsp', 'lecture', 'width=718, height=650, scrollbars=yes');
}
function dicOpen() {
	window.open('/utility/dictionary.jsp', 'dictionary', 'width=718, height=650, scrollbars=yes');
}


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;
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//select_go
function openWindow(http) {
		window.open(http,"sub_win")
	}

function sub_openWindow(http,open_name) {
	var http1,open_name1
		http1 = http;
		open_name1 = open_name;	
		window.open(http1,open_name1)
	}

	function selectLinks(form) {
		var http
			for(i=0;i<form.links.length;i++) {
				if(form.links.options[i].selected == true) {
					http = form.links.options[i].value					
				}
			}

		openWindow(http)
	}
	function selectLinks2(form) {
		var http
			for(i=0;i<form.links2.length;i++) {
				if(form.links2.options[i].selected == true) {
					http = form.links2.options[i].value
				}
			}
		openWindow(http)
	}
	function selectLinks3(form) {
		var http
			for(i=0;i<form.links3.length;i++) {
				if(form.links3.options[i].selected == true) {
					http = form.links3.options[i].value
				}
			}
		openWindow(http)
	}
	function selectLinks4(form) {
		var http
			for(i=0;i<form.links4.length;i++) {
				if(form.links4.options[i].selected == true) {
					http = form.links4.options[i].value
				}
			}
		openWindow(http)
	}



function vodWrite(url,w,h){



		var flashStr=
		"<object classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' name=MSMPlayer id=MSMPlayer width='"+w+"' height='"+h+"' style='LEFT: 0px; TOP: 0px'>"+		
		"<param name='Filename' value='"+url+"'>"+
		"<param name='enabletracker' value='1'>"+
		"<param name='ShowControls' value='1'>"+
		"<param name='ShowStatusBar' value='1'>"+
		"<param name='ShowDisplay' value='0'>"+
		"<param name='DefaultFrame' value='Slide'>"+
		"<param name='Autostart' value='1'>"+
		"<param name='EnableContextMenu' value='0'>"+
		"<embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/' id='MediaPlay' name='MSMPlayer' displaysize='5' autosize='1'  bgcolor='darkblue' showcontrols='1' showtracker='1' showdisplay='0' showstatusbar='1' videobordercolor='#8296b9' videoborderwidth='0' videoborder3d='0'   width='"+w+"' height='"+h+" src='"+url+"' autostart='1' autorewind='1' filename='"+url+"' enabletracker='1' defaultframe='Slide' enablecontextmenu='0'>"+
		"</embed>"+
		"</object>";

		document.write(flashStr);


}

//flash
function flashWrite(url,w,h,id,bg,vars,win){
		
		var src_arr = url.split("/");
		var src_file = src_arr[src_arr.length -1]
		var src_id = src_file.substr(0,src_file.length-4);	
        var flashStr=
//        "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' title='¸¶¿ì½º¸¦ ÁÂ¿ì·Î ¿òÁ÷¿©º¸¼¼¿ä.' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+        
		
		"<object type='application/x-shockwave-flash' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' id='"+src_id+"' width='"+w+"' height='"+h+"'>"+
        "<param name='allowScriptAccess' value='always' />"+
        "<param name='movie' value='"+url+"' />"+
        "<param name='FlashVars' value='"+vars+"' />"+
        "<param name='wmode' value='"+win+"' />"+
        "<param name='menu' value='false' />"+
        "<param name='quality' value='high' />"+
        "<param name='bgcolor' value='"+bg+"' />"+
//        "<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
		"<embed src='"+url+"' wmode='"+win+"'  quality='high' bgcolor='#ffffff' width='"+w+"' height='"+h+"' swliveconnect='true' id='"+src_id+"' name='"+src_id+"' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'>"+	
        "</object>";
        document.write(flashStr);
}


function swf(src, w, h) {
	var src_arr = src.split("/");
	var src_file = src_arr[src_arr.length -1]
	var src_id = src_file.substr(0,src_file.length-4);
	//alert(src_id);

	html = '';
	html += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="'+src_id+'" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="swliveconnect" value="true">';	
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="'+src_id+'" name="'+src_id+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}
