// JavaScript Document 
function addLoadEvent(func) {
	var oldonLoad = window.onload;
	if (typeof window.onload != 'function') {
			window.onload = func;
	}else {
		window.onload = function(){
			oldonLoad();
			func();
		}
	}
}
function addResizeEvent(func){
	var oldonResize = window.onresize;
	if (typeof window.onresize !='function'){
		window.onresize = func;
	}else {
		window.onload = function(){
			oldonResize();
			func();
		}
	}
}

function getElementsByClassName2(clsName,parentNode) {
 var arr = new Array();
 if (parentNode == null) {
  var elems = document.getElementsByTagName("*");
 } else {
  var elems = parentNode.getElementsByTagName("*");
 }
 for ( var cls, i = 0; ( elem = elems[i] ); i++ ) {
  if ( elem.className == clsName ) {
   arr[arr.length] = elem;
  }
 }
 return arr;
}
function newAlert(text,node,xx,yy){
	if(!xx)xx=document.body.mouseX;
	if(!yy)yy=document.body.mouseY+document.body.scrolltop-50;
	if(!node)node=document.body;
	if(node.newAlert)animateElementRemove(node.newAlert,100,0,"opacity");
	node.newAlert = document.createElement("div");
	node.newAlert.className = "newAlert";
	/*
	for (i=0;i<10;i++){
        var temp = document.createElement("p");
        temp.className = "deco deco"+i;
        node.newAlert.appendChild(temp);
    }*/
	insertTag(node.newAlert,"text",text);
	node.newAlert.style.top = yy+"px";
	node.newAlert.style.left = xx+"px";
	document.body.appendChild(node.newAlert);
	animateElement(node.newAlert,0,100,"opacity");
	node.newAlert.onclick = function(){
		if(this.timeout)clearTimeout(this.timeout["opacity"]);
		animateElementRemove(this,100,0,"opacity");
	}
	if (node!=document.body){
		node.onmouseout = function(){
			if(this.newAlert.timeout)clearTimeout(this.newAlert.timeout["opacity"]);
			animateElementRemove(this.newAlert,100,0,"opacity");
		}
	}
}

addLoadEvent(blockquote_cite_showup);
function blockquote_cite_showup() {
	if (!document.getElementsByTagName("blockquote"))return false;
	var blockquote_el = document.getElementsByTagName("blockquote");
	for (i=0;i<blockquote_el.length;i++) {
		var from = document.createTextNode("from : ");
		if (!blockquote_el[i].getAttribute("cite")) return false;
		var cite = blockquote_el[i].getAttribute("cite");
		var text = document.createTextNode(cite);
		if (cite.substring(0,4) =="http" || cite.substring(0,6) =="mailto"){
			var a_el = document.createElement("a");
			a_el.href = cite;
			a_el.appendChild(text);
		} 
		var p_el = document.createElement("p");
		p_el.className = "cite";
		var cite_el = document.createElement("cite");
		cite_el.appendChild(from);
		p_el.appendChild(cite_el);
		if (a_el) {cite_el.appendChild(a_el);}
		else {cite_el.appendChild(text);}
		blockquote_el[i].appendChild (p_el);
	}
}


addLoadEvent(abbr_title_list);
function abbr_title_list() {
	if (!document.getElementsByTagName("abbr"))return false;
	var abbr_el = document.getElementsByTagName("abbr");
	var abbrList_el = new Array();
	var cnt=0;
	for (i=0;i<abbr_el.length;i++){
		if (abbr_el[i].title){
			abbrList_el[cnt] = abbr_el[i].cloneNode(true);
			abbrList_el[cnt].id = "abbrTitleLink"+(cnt+1);
			a_el = document.createElement("a");
			a_el.href = "#"+abbrList_el[cnt].id ;
			a_el.id ="top"+abbrList_el[cnt].id
			abbrList_el[cnt]._id = a_el.id;
			cnt++;
			text = document.createTextNode("(" + cnt + ")");
			a_el.appendChild(text);
			a_el.className = "abbrTitleList";
			abbr_el[i].parentNode.insertBefore(a_el,abbr_el[i]);	
		}
	}
	if (cnt==0) return false;
	var abbrDIV = document.createElement("div");
	abbrDIV.className = "abbrTitleList";
	var h2 = document.createElement("h2");
	var text = document.createTextNode("용어풀이");
	h2.appendChild(text);
	h2.id = "abbreviation";
	abbrDIV.appendChild(h2);
	var abbrOL = document.createElement("ol");
	for (i=0; i<abbrList_el.length;i++) {
		var abbrLI = document.createElement("li");
		var a_el = document.createElement("a");
		a_el.href = "#"+abbrList_el[i]._id;
		var text = document.createTextNode("▲");
		a_el.appendChild(text);
		abbrLI.appendChild(a_el);
		abbrLI.appendChild(abbrList_el[i]);
		var text = document.createTextNode(": "+abbrList_el[i].title);
		abbrLI.appendChild(text);
		abbrOL.appendChild(abbrLI);
		abbrLI.onmouseover = function () {
			if(!document.getElementById(this.childNodes[1]._id))return false;
			var abbrEL=document.getElementById(this.childNodes[1]._id);
			abbrEL.style.background = "#ff0";
		}
		abbrLI.onmouseout = function() {
			if(!document.getElementById(this.childNodes[1]._id))return false;
			var abbrEL=document.getElementById(this.childNodes[1]._id);
			abbrEL.style.background = "none";			
		}
		
	}
	if (!document.getElementById("content_supp")){
		var content_el=document.createElement("div");
		content_el.id="content_supp";
		document.getElementById("content").appendChild(content_el);
	}
	else {var content_el = document.getElementById("content_supp");}
	abbrDIV.appendChild(abbrOL);
	content_el.appendChild(abbrDIV);
}

addLoadEvent(linkImageShowup);
function linkImageShowup(){
	if(!document.getElementsByTagName)return false;
    if(!document.getElementsByTagName("a"))return false;
	var a_el = document.getElementsByTagName("a");
	for (i=0;i<a_el.length;i++){
		if (a_el[i].childNodes[0]){
			if (a_el[i].childNodes[0].nodeName!="IMG"){
				if(!a_el[i].onclick){
				a_el[i].onclick = function(){
					var str=this.href.substring(this.href.length-3,this.href.length);
					if (str=="jpg" || str=="png" || str=="gif"){
                    	popupImage(this,this.href);
                    	return false;
                	}
				}}
			}
		}
	}

}
addLoadEvent(imgShowup);
function imgShowup(){
	if (!document.getElementsByTagName)return false;
	if (!document.getElementsByTagName("img"))return false;
	var body_el = document.getElementsByTagName("body")[0];
	var img_el = document.getElementsByTagName("img");
	for (i=0;i<img_el.length;i++){
		if(img_el[i].parentNode.nodeName == "A"){
			img_el[i].parentNode.onclick = function(){
           		var str=this.href.substring(this.href.length-3,this.href.length);
				if (str=="jpg" || str=="png" || str=="gif"){
					popupImage(this,this.href);
					return false;
				}
			} 
			//---------------------수정필요
		}else {
			img_el[i].a_el = document.createElement("a");
            img_el[i].a_el.setAttribute("href",img_el[i].src);
			img_el[i].a_el.setAttribute("onkeydown","mouseXYinput(event,'keybord')");
			img_el[i].a_el.setAttribute("onmousedown","mouseXYinput(event,'mouse')");

            img_el[i].a_el.onclick = function(){
				popupImage(this);
				return false;
			}
			img_el[i].parentNode.insertBefore(img_el[i].a_el,img_el[i]);
			img_el[i].a_el.appendChild(img_el[i]);
		}
	}
	
}
function popupImage(node,src){
				var body_el=document.body;
                var xx = body_el.mouseX;
                var yy = body_el.mouseY;
                if(node.box_el){
                    xx=parseInt(node.box_el.style.left);
                    yy=parseInt(node.box_el.style.top);
                    if(node.box_el.timeout)clearTimeout(node.box_el.timeout);
                    animateElementRemove(node.box_el,100,0,"opacity",4,30);
                }
                body_el.scrolltop = document.body.scrollTop;
                if (body_el.scrolltop==0)body_el.scrolltop = document.documentElement.scrollTop;
                body_el.mouseY = body_el.mouseY + body_el.scrolltop;
				node.box_el = node.cloneNode(true);
				if(node.box_el.childNodes[0].nodeName!="IMG"){
					node.box_el.removeChild(node.box_el.childNodes[0]);
					insertTag(node.box_el,"img",src);
				} else {
					if (src){
						var alt= node.box_el.childNodes[0].getAttribute("alt");
						var img = document.createElement("img");
						img.setAttribute("src",src);
						img.setAttribute("alt",alt); 
						node.box_el.removeChild(node.box_el.childNodes[0]);
						node.box_el.appendChild(img);
					}
				}
				if(src)node.box_el.childNodes[0].src=src;
                node.box_el.onclick = function(){
                    animateElementRemove(this,100,0,"opacity",2,30);
                    return false;
                }
                node.box_el.className = "imageBox";
                body_el.appendChild(node.box_el);

                var boxWidth = node.box_el.offsetWidth;
                                var boxHeight = node.box_el.offsetHeight;
                                var bodyWidth = body_el.clientWidth;
                var x2 = Math.floor(Math.random(1)*(bodyWidth-(boxWidth+2)));
                                var y2 = Math.floor(Math.random(2)*400);
                //alert (xx+"-"+yy+":"+body_el.scrolltop);
                animateElement(node.box_el,xx,x2,"left",2,30);
                animateElement(node.box_el,yy,body_el.scrolltop+y2,"top",2,30);
                animateElement(node.box_el,0,100,"opacity",2,30);
                animateElement(node.box_el.childNodes[0],0,node.box_el.childNodes[0].offsetWidth,"width",2,30);
                var aa = Math.ceil(Math.random(2)*9000)+5000;
                return false;
}

addLoadEvent(body_onmousemove);
function body_onmousemove(){
	document.body.setAttribute("onmousemove","mouseXYinput(event,'mouse')");
}

function mouseXYinput(evt,type){ // 마우스의 좌표값을 구하여 body 엘리멘트에 저장합니다.
	var body_el = document.getElementsByTagName("body")[0];
	if (type =="mouse"){
		body_el.mouseX = evt.clientX;
		body_el.mouseY = evt.clientY;
	}else {
		body_el.mouseX = 0;
		body_el.mouseY = 0;
	}
  	body_el.scrolltop = document.body.scrollTop;
    if (body_el.scrolltop==0)body_el.scrolltop = document.documentElement.scrollTop;

}

addLoadEvent(me2dayAction);
function me2dayAction() {
	if (!document.getElementById("content"))return false;
	var content_el = document.getElementById("content");
	if (!getElementsByClassName2("me2day_daily_digest",content_el))return false;
	var me2day_el = getElementsByClassName2("me2day_daily_digest",content_el) ;
	var a_el = new Array();
	for (i=0;i<me2day_el.length;i++) {
		a_el[i] = me2day_el[i].getElementsByTagName("a");
		for (j=0;j<a_el[i].length;j++){
			a_el[i][j].className = "phxys_"+i+j;
			a_el[i][j].onclick = function(){
				if (document.getElementById(this.className)) {
					var item_el = document.getElementById(this.className);
					animateElement(item_el,100,0,"opacity");
					animateElementRemove(item_el,item_el.offsetHeight,0,"height",2,30);
					return false;
				}
				var string = this.href.substring(this.href.length-3,this.href.length);
				if (string=="jpg"||string=="JPG"||string=="png"||string=="PNG"||string=="gif"||string=="GIF") {
					var temp_el = document.createElement("img");
					temp_el.onclick = function(){
						animateElement(this,100,0,"opacity");
						animateElementRemove(this,this.offsetHeight,0,"height",2,30);
					}
					temp_el.src = this.href;
					temp_el.alt = "미투데이 링크된 그림";
					temp_el.className = "button";
					animateElement(temp_el,0,100,"opacity");
					animateElement(temp_el,0,600,"width");

				}
				else {
					var temp_el = document.createElement("div");
					temp_el.className = "Box";
					var a_el = document.createElement("a");
					a_el.href = "#";
					a_el.onclick = function () {
						this.setAttribute("style","overflow:hidden");
						animateElement(this.parentNode,100,0,"opacity");
						animateElementRemove(this.parentNode,this.offsetHeight,0,"height",2,30);
						return false;
						}
					a_el.className = "close";
					var text = document.createTextNode("프레임 닫기");
					a_el.appendChild(text);					
					var iframe_el = document.createElement("iframe");
					iframe_el.src = this.href;
					temp_el.appendChild(iframe_el);
					temp_el.appendChild(a_el);
					animateElement(iframe_el,0,300,"height",3,30);
					animateElement(iframe_el,0,100,"opacity",3,30);

				}
				temp_el.id = this.className;
				this.parentNode.appendChild(temp_el);
				return false;
			}
		}
		var div_el = document.createElement("div");
		}

}

	
//addLoadEvent(StyleChange);
function StyleChange(){	
	if (!document.getElementsByTagName("link") || !document.getElementById("nav_main"))return false;
	var navMain_el = document.getElementById("nav_main");
	var head_el = document.getElementsByTagName("head")[0];
	var link_el = head_el.getElementsByTagName("link");	
	var div_el = document.createElement("div");
	var h2_el = document.createElement("h2");
	var text = document.createTextNode("Color Theme");
	h2_el.appendChild(text);
	h2_el.id = "colorTheme";
	div_el.appendChild(h2_el);
	div_el.id = "StyleChange";
	var ul_el = document.createElement("ul");
	for (i=0;i<link_el.length;i++){
		if (link_el[i].rel=="stylesheet" && link_el[i].title) {
				var li_el = document.createElement("li");
				var a_el = document.createElement("a");	
				if (link_el[i].title) {var texts = link_el[i].title;}
				else {var texts ="style"+i;}
				var text = document.createTextNode(texts);
				a_el.appendChild(text);
				a_el.href = link_el[i].href;
				//a_el.className = texts;
				a_el.title = link_el[i].title + "(으)로 Color Theme 를 변경합니다" ;
				a_el.onclick = function(){
						newAlert(this.title,this,30,30);
						remove_AddCSS();
						addStyleLink(this.href);
						setCookie("siteStyle",this.href);
						SelectedChangeCssButton(this.href);
						return false;
				}
				li_el.className = texts;
				li_el.appendChild(a_el);
				ul_el.appendChild(li_el);
		}
	}
	var a_el = document.createElement("a");
	var text = document.createTextNode("Random");
	a_el.appendChild(text);
	a_el.href="#;";
	a_el.title = "무작위로 Color Theme를 선택합니다";
	a_el.onclick = function() {
		newAlert("Color Theme 옵션을 를 무작위 변경 으로 설정했습니다.",this,30,30);
		remove_AddCSS();
		var randomStyleNo = Math.floor(Math.random(1)*(this.parentNode.parentNode.childNodes.length-1));
		var _href = this.parentNode.parentNode.childNodes[randomStyleNo].childNodes[0].href;
		addStyleLink(_href);
		setCookie("siteStyle","random");
		SelectedChangeCssButton("random");
		return false;
		}
	var li_el = document.createElement("li");
	li_el.className = "Random";
	li_el.appendChild(a_el);
	ul_el.appendChild(li_el);
	div_el.appendChild(ul_el);
	div_el.style.opacity=0;	
	navMain_el.appendChild(div_el); 
	animateElement(div_el,0,100,"opacity",10,50);
	if (getCookie("siteStyle")){
		var str = getCookie("siteStyle");
		SelectedChangeCssButton(str);	
	}
}
if (getCookie("siteStyle")){
	var head_el = document.getElementsByTagName("head")[0];
	var link_el = head_el.getElementsByTagName("link");	
	if (getCookie("siteStyle")=="random") {
		var _href = link_el[Math.floor(Math.random(1)*link_el.length)].href;
	}
	else {
		var _href = getCookie("siteStyle")
	}
	addStyleLink(_href);
}
function addStyleLink(href){
	var head_el = document.getElementsByTagName("head")[0];
	var style_el = document.createElement("link");
	style_el.type = "text/css";
	style_el.href = href;
	style_el.media = "all";
	style_el.rel = "stylesheet";
	style_el.id="styleChange";
	head_el.appendChild(style_el);	
}
function remove_AddCSS() {
if(document.getElementById("styleChange")) {
	var el = document.getElementById("styleChange");
	el.parentNode.removeChild(el);
	}
}
function SelectedChangeCssButton(str) {
	if (!document.getElementById("nav_main"))return false;
	var nav_main_el = document.getElementById("nav_main");
	nav_main_el.className = str.substring(str.length-8,str.length-4);
}

function setCookie(name, value){
	var today = new Date();
    var expire = new Date();
    expire.setTime(today.getTime() + 1000*60*60*365);
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expire );
	document.cookie = name + "=" + escape( value ) + "; path=/;expires=" + todayDate.toGMTString()+ "domain=" + "www.kongbaguni.com;" ;
	} 

function getCookie(Name){
	var search = Name + "=";
    if(document.cookie.length >0){
     offset = document.cookie.indexOf(search);
		if(offset != -1){
			 offset +=search.length;
			 end = document.cookie.indexOf(";",offset);
			 if(end==-1)end = document.cookie.length;
			 return unescape(document.cookie.substring(offset, end));     
		}
    }
}
addLoadEvent(titleAlert);

function titleAlert(){
	var all_el = document.getElementsByTagName("*");
	
	for (i=0;i<all_el.length;i++){
		if(all_el[i].title && 
				  all_el[i].parentNode.parentNode.nodeName!="TABLE" &&
				  all_el[i].nodeName!="TD" &&
				  all_el[i].nodeName!="TH" &&
				  all_el[i].parentNode.nodeName!="TD" &&
				  all_el[i].parentNode.nodeName!="TH" &&
				  all_el[i].nodeName!="H1" && 
				  all_el[i].nodeName!="H2" && 
				  all_el[i].nodeName!="H3" && 
				  all_el[i].nodeName!="H4" && 
				  all_el[i].nodeName!="H5" && 
				  all_el[i].nodeName!="H6" &&
				  all_el[i].rel != "bookmark" &&
				  all_el[i].nodeName!="IMG" &&
				  all_el[i].nodeName!="FORM"){
			/*
			all_el[i].onmouseover = function() {
				newAlert(this.title,"설명",this,false,60,.95);
				this.temp = this.title ;
				this.title = null;
				
			}
			all_el[i].onmouseout = function(){
				this.title = this.temp;
				opacityRemoveElement("newAlert");	
			}
			*/
		}
		
		/*if(all_el[i].cite) {
			all_el[i].onmouseover = function() {
				newAlert(this.cite,"출처",this,false,-70,95);
			}
			all_el[i].onmouseout = function() {
				removeNewAlert();				
			}
		}*/
		if(all_el[i].title && all_el[i].nodeName=="IMG" ){
		/*
			all_el[i].onmouseover = function() {
				newAlert(this.title,"img",this,false,-150,.95);
				this.temp = this.title ;
				this.title = null;
			}
			all_el[i].onmouseout = function(){
				this.title = this.temp;
				opacityRemoveElement("newAlert");
			}
		*/
		}
		if(all_el[i].alt && !all_el[i].title) {
			all_el[i].onmouseover = function() {
				newAlert(this.alt,this);
			}
			all_el[i].onmouseout = function(){
			}
			
		}
	}
}
var content_sub_el;
var navi_switch = true;
var body_el;
addLoadEvent(content_sub_switch_button);
function content_sub_switch_button(){
if (navigator.appName == "Microsoft Internet Explorer") return false;

	body_el = document.getElementsByTagName("body")[0];
	body_el.className = "on";
	if (!document.getElementById("content_sub")){
		body_el.className="off";
		return false;
	}
	content_sub_el = document.getElementById("content_sub");
	var a_el = document.createElement("a");
	var text = document.createTextNode("sub content switch");
	a_el.className = "switch";
	a_el.href = "#;";
	a_el.title = "sub content switch";
	a_el.appendChild(text);
	content_sub_el.className ="content_sub_on";
	a_el.onclick = function() {
		autoindex_el = document.getElementById("kongbaguni_AutoIndex");
		if (navi_switch==true) {
			body_el.className = "off"
			navi_switch = false;
			this.className = "switch off";
			setCookie("content_sub_switch","off");
			content_sub_el.className = "content_sub_off";
			animationLoad();
			return false
		}
		if (navi_switch == false){
			navi_switch = true;
			body_el.className = "on";
			this.className = "switch on";
			content_sub_el.className ="content_sub_on";
			setCookie("content_sub_switch","on");
			animationLoad();
			return false;
		}
	}
	document.body.appendChild(a_el);
	//content_sub_el.insertBefore(a_el,content_sub_el.childNodes[0]);
	
	if (getCookie("content_sub_switch")) {
		if(getCookie("content_sub_switch")=="off") {
			body_el.className = "off";
			navi_switch = false;
			a_el.className = "switch off";
			content_sub_el.className = "content_sub_off";
			return false;
		}else if (getCookie("content_sub_switch")=="on"){
			body_el.className = "on";
			navi_switch = true;
			a_el.className = "switch on";
			content_sub_el.className = "content_sub_on";
			return false;
		}
	}
}


var ed_el;
var ed_switch = true;
var content_el

function insertTag(node,tagName,text,url){
/* 
Element를 쉽게 집어넣자.
사용예 : 
	insertTag(node,"text","글자"); TextNode를 생성하여 node에 집어넣는다.
	insertTag(node,"strong","강조할 글자");p,strong, em, span,ins 같은 태그안에 Textnode를 생성하여 node안에 삽입한다.
	insertTag(node,"br");  br, hr 같은 태그를 집어넣을때.
	insertTag(node,"img","대치문자","그림주소") img 태그를 사용 그림을 넣는다.
	insertTag(node,"a","하이퍼링크 이름","하이퍼링크 주소 URL") 하이퍼링크 를 생성한다.

*/

	if (tagName!="text") var el = document.createElement(tagName);
	if (tagName=="img") {
			el.setAttribute("alt",text);
			el.setAttribute("src",url);
	}
    if (text) {
		var txt = document.createTextNode(text);
		if (tagName!="text") el.appendChild(txt);
	}
    if (tagName!="text") node.appendChild(el);
	if (tagName=="text") node.appendChild(txt);
	if (tagName=="a" && url) el.setAttribute("href",url);
}

function insertInput(node,value,type,name){
	var p_el = document.createElement("p");
	p_el.className = name;
	var input_el = document.createElement("input");
	if(!type)type="submit";
	input_el.setAttribute("type",type);
	if (name) input_el.setAttribute("name",name);
	if (value) input_el.setAttribute("value",value);
	p_el.appendChild(input_el);
	node.appendChild(p_el);
}

function makeInput(value,type,name,title){
    var p_el = document.createElement("p");
	if (title){
		var text = document.createTextNode(title + " : ");
		p_el.appendChild(text);
	}
    p_el.className = name;
    var input_el = document.createElement("input");
    if(!type) type="submit";
    input_el.setAttribute("type",type);
    if (name) input_el.setAttribute("name",name);
    if (value) input_el.setAttribute("value",value);
    p_el.appendChild(input_el);
    return p_el;
}

function animateElement(node,oldValue,newValue,type,smooth,speed) {
/*
node = 움직일 노드 입력  노드로 입력.
oldValue = 크기를 변경하기 전으 수치.애니메이션의 시작 값, 숫자로 입력.
newValue = 애니메이션의 목표값. 숫자로 입력.
type = 변경할 속성의 타입을 정의. 문자로 입력.
    -> "width" ->Element 의 너비를 변경.
    -> "height" ->Element 의 높이를 변경..
    -> "top","left","right","bottom" -> Element 의 위치를 변경.
smooth = 움직임을 제어하는 수치. 많을수록 부드럽게 움직인다. 숫자로 입력.
speed = 애니메이션으 속도 제어. 숫자로 입력.
*/ 
	if (!node.style) return false;
	node.style.display = "block";
    if (!smooth) smooth = 10;
    if (!speed) speed = 30;
    if (!node._value) node._value = new Array();
    if (!node._value[type]) node._value[type] = oldValue;
	
    node._value[type] = node._value[type] + ((newValue-node._value[type])/smooth);
	var AAA = Math.floor(node._value[type]);
    if (type=="width"){ node.style.width = AAA + "px";}
    else if (type == "height"){ node.style.height = AAA + "px";}
    else if (type == "top"){ node.style.top = AAA + "px";}
    else if (type == "left"){ node.style.left = AAA + "px";}
    else if (type == "right"){ node.style.right = AAA + "px";}
    else if (type == "bottom"){ node.style.bottom = AAA + "px";}
	else if (type == "opacity"){ node.style.opacity = AAA / 100 ;}
	if (navigator.appName == "Microsoft Internet Explorer" & type == "opacity") {
		node.style.filter = "alpha(opacity="+AAA+");";
	}
	if(node._value["opacity"]<1) node.style.display = "none";
    if (oldValue < newValue && node._value[type] <= newValue-1) {
        var Action = true;
    } else if (oldValue > newValue && node._value[type] > newValue+1) {
        var Action = true;
    } else {
        var Action = false;
		//if (node.timeout)clearTimeout(node.timeout[type]);
    }
    if (Action == true) {
        if (!node.timeout) node.timeout = new Array();
        node.timeout[type] = setTimeout (function () { animateElement(node,oldValue,newValue,type,smooth,speed) }, speed);
    }

}

function animateElementRemove(node,oldValue,newValue,type,smooth,speed) {
		if(!type)type = "opacity";
		if(!oldValue) oldValue = 100;
		if(!newValue) newValue = 0;
		if(!smooth) smooth = 2;
		if(!speed) speed = 30;
		animateElement(node,oldValue,newValue,type,smooth,speed);
		node.timeout = setTimeout(function(){if(node.parentNode)node.parentNode.removeChild(node);},speed*30);
		return false;
}
addLoadEvent(nav_subAnimate);
function nav_subAnimate(){
	if(!document.getElementById("nav_sub"))return false;
	var top_el=document.getElementById("nav_sub");
	var ul_el = top_el.getElementsByTagName("ul")[0];
	var li_el = ul_el.getElementsByTagName("li");
	for (var i=0;i<li_el.length;i++){
		if(li_el[i].getElementsByTagName("ul")){
			li_el[i].onmouseover = function(){
				if(!this.getElementsByTagName("ul")[0])return false;
				var child = this.getElementsByTagName("ul")[0];
				var li_el = child.getElementsByTagName("li");
				var height = li_el[0].offsetHeight*li_el.length+10;

				if(child.timeout){
					clearTimeout(child.timeout["height"]);
					clearTimeout(child.timeout["opacity"]);
				}
				child.style.display="block";
				animateElement(child,0,height,"height",5,30);
				animateElement(child,0,100,"opacity",5,30);
			}
            li_el[i].onmouseout = function(){
				if(!this.getElementsByTagName("ul")[0])return false;
                var child = this.getElementsByTagName("ul")[0];
                if(child.timeout){
					clearTimeout(child.timeout["height"]);
					clearTimeout(child.timeout["opacity"]);
				}
                child.style.display="none";
                animateElement(child,200,0,"height",20,30);
				animateElement(child,100,0,"opacity",20,30);
            }

		}
	}
}
