/*--------------------------------------------------------------------------*/
/*  $id Selector
/*--------------------------------------------------------------------------*/
/* getElementById : $id("id") */
function $id()	{
	var elements = new Array();

	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
		element = document.getElementById(element);

		if (arguments.length == 1)
		return element;

		elements.push(element);
	}

	return elements;
}



/*--------------------------------------------------------------------------*/
/*  getElementsByClassName Selector
/*--------------------------------------------------------------------------*/
/* getElementsByClassName : getElementsByClassName("className","parentId","elementName")*/
document.getElementsByClassName = function(_class, el_id, elTag) {
	if (elTag == false || elTag == null) {
		elTag = '*';
	}
	var parent, els, returnArr = new Array(), i = 0;
	parent = (el_id) ? document.getElementById(el_id) : document;
	els = parent.getElementsByTagName(elTag) || parent.all;
	for (i; i < els.length; i++)
		if (els[i].className == _class) 
			returnArr[returnArr.length] = els[i];
	return returnArr;
}



/*--------------------------------------------------------------------------*/
/*  image on off
/*--------------------------------------------------------------------------*/
function imgOn(imgElement)
{
	imgElement.src = imgElement.src.replace("_off.gif", "_on.gif");
}

function imgOff(imgElement)
{
	imgElement.src = imgElement.src.replace("_on.gif", "_off.gif");
}



/*--------------------------------------------------------------------------*/
/*  popup
/*--------------------------------------------------------------------------*/
function windowPopup(url, w, h, s, name){
	if (w==null) w = '100%';
	if (h==null) h = '100%';
	var l,t = '0';
	if (screen.width && screen.height)	{
		l = (screen.width-w)/2;
		t = (screen.height-h)/2;
	}
	if (s==null) s = '0';
	if (name==null) name = '';
	window.open(url, name, 'width='+w+',height='+h+',left='+l+',top='+t+',resizable=0,menubar=0,toolbar=0,scrollbars='+s+',status=0');
}



/*--------------------------------------------------------------------------*/
/*  embed object
/*--------------------------------------------------------------------------*/
var embedSWF = function(url, replaceEl, width, height, wmode, objId)	{
	try	{
		if (document.write && document.getElementById)
		{
			if (wmode == false) wmode = "window";
			if (objId == false) objId = "flashObject";

			var replaceEl = document.getElementById(replaceEl);
			var replaceElContent = replaceEl.innerHTML;

			var objectStr = ''+
			'<!--[if IE]>' +
			'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+objId+'">' +
			'<![endif] -->' +
			'<!--[if !IE]> <-->' +
			'<object type="application/x-shockwave-flash" data="'+url+'" width="'+width+'" height="'+height+'" id="'+objId+'">' +
			'<!--><![endif]-->' +
			'<param name="movie" value="'+url+'" />' +
			'<param name="wmode" value="'+wmode+'" />' +
			replaceElContent +
			'</object>';

			replaceEl.innerHTML = objectStr;
		}
	}
	catch (e)	{return false;}
}



/*--------------------------------------------------------------------------*/
/*  IE Image Label check
/*--------------------------------------------------------------------------*/
function	ieLabel(el)	{
	if(navigator.appVersion.indexOf('MSIE') != -1)	{
		var labelFor = el.getAttribute("for")? el.getAttribute("for") : el.getAttribute("htmlFor")
		$id(labelFor).focus();
		$id(labelFor).click();
	}
}



/*--------------------------------------------------------------------------*/
/*  tabContents
/*--------------------------------------------------------------------------*/
function	tabContents(tabId,tabMenuId)
{
	var moreBtn = document.getElementsByClassName("more",tabMenuId);
	var tabDivId = document.getElementById(tabId);
	var tabMenuId = document.getElementById(tabMenuId);

	var tabMenuAnchor = tabMenuId.getElementsByTagName("ul")[0].getElementsByTagName("a");

	var first=0;
	var temp = tabMenuAnchor[0].href.split("#")[1];

	for (i=0; i<tabMenuAnchor.length; i++)
	{
		var divName	= tabMenuAnchor[i].href.split("#")[1];
		document.getElementById(divName).style.display = "none";
		if ((moreBtn.length > 0) && (moreBtn[i] != null)) moreBtn[i].style.display = "none";

		if (first==0)
		{	
			document.getElementById(tabMenuAnchor[0].href.split("#")[1]).style.display = "block";
			if (moreBtn.length > 0) moreBtn[0].style.display = "block";
			if	(tabMenuId.getElementsByTagName("img")[0] !=null) {
				tabMenuId.getElementsByTagName("img")[0].src=
				tabMenuId.getElementsByTagName("img")[0].src.replace("_off","_on");
			}
			else	{
				tabMenuId.getElementsByTagName("li")[0].className="onTab";
			}
			first=1;
		}
		tabMenuAnchor[i].onclick = function()	{

			for	(j=0; j<tabMenuAnchor.length; j++)
			{
				if (tabMenuAnchor[j].getElementsByTagName("img")[0] != null)	{
					tabMenuAnchor[j].getElementsByTagName("img")[0].src = tabMenuAnchor[j].getElementsByTagName("img")[0].src.replace("_on","_off");
					this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].src.replace("_off","_on");
				}
				else	{
					tabMenuAnchor[j].parentNode.className="";
					this.parentNode.className="onTab";
				}
			}

			document.getElementById(temp).style.display = "none";
			divName	= this.href.split("#")[1];
			temp=divName;
			document.getElementById(divName).style.display = "block";

			if (moreBtn.length > 0)	{
				for	(k=0;k<tabMenuAnchor.length;k++)	{
					if (moreBtn[k] != null)	moreBtn[k].style.display = "none";
				}
				for	(l=0;l<tabMenuAnchor.length;l++)	{
					if (tabMenuAnchor.length == moreBtn.length && this==tabMenuAnchor[l])	moreBtn[l].style.display = "block";
					if (tabMenuAnchor.length != moreBtn.length) moreBtn[0].style.display = "block";
				}
			}

			return false;
		}
	}
}



/*--------------------------------------------------------------------------*/
/*  anchorList
/*--------------------------------------------------------------------------*/
function	anchorList(el)	{
	var el = $id(el);
	var dtTag = el.getElementsByTagName("dt")[0];
	var dtAnchorTag = dtTag.getElementsByTagName("a")[0];
	var ddTag = el.getElementsByTagName("dd")[0];
	var ddOlTag = ddTag.getElementsByTagName("ol")[0];
	var ddOlAnchorTag = ddOlTag.getElementsByTagName("a");

	ddTag.style.display = "none";

	var viewState = 0;
	dtAnchorTag.onmousedown = function()	{
		if (ddTag.style.display == "block")	{
			ddTag.style.display = "none";
		}
		else if (ddTag.style.display == "none")	{
			ddTag.style.display = "block";
		}
		viewState = 1;
	}
	dtAnchorTag.onclick = function()	{
		return false;
	}
	dtAnchorTag.onfocus = function()	{
		if (viewState != 1)
		{
			ddTag.style.display = "block";
			return false;
		}
		else {viewState = 0;}
	}
	ddOlAnchorTag[ddOlAnchorTag.length-1].onkeydown = function(e)	{
		var e = window.event || e
		var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
		if (keyCode == 9)	{
			function hideList()	{
				ddTag.style.display = "none";
				window.clearInterval(hideListInterval)
			}
			var hideListInterval = window.setInterval(hideList,50);
		}
	}
}



/*--------------------------------------------------------------------------*/
/*  navigation
/*--------------------------------------------------------------------------*/
function	globalNavigation(param,gnbOn,snbOn)	{
	// start main page
	if (param=="mainPage")
	{
		$("#subGnb").css("borderWidth","0");
		$("#subGnb div.subGnbDivision").css("position","absolute");
		$("#subGnb div.subGnbDivision").css("top","-9999px");
		$("#gnb ol li a").hover(
			function()	{
				$("#subGnb").css("borderWidth","1px");
				$("#subGnb div.subGnbDivision").css("position","absolute");
				$("#" + $(this).parent().attr("id").replace("main","sub")).css("position","static");
				$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_off","_on"));
			},
			function()	{
				//$("#subGnb").css("borderWidth","0");
				//$("#" + $(this).parent().attr("id").replace("main","sub")).css("position","absolute");
				$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_on","_off"));
			}
		);
		$("#gnb ol li a").focus(function()	{
			$("#subGnb").css("borderWidth","1px");
			$("#" + $(this).parent().attr("id").replace("main","sub")).css("position","static");
			$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_off","_on"));
		});
		$("#gnb ol li a").blur(function()	{
			$("#subGnb").css("borderWidth","0");
			$("#" + $(this).parent().attr("id").replace("main","sub")).css("position","absolute");
			$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_on","_off"));
		});
		$("#subGnb div.subGnbDivision").mouseover(function()	{
			$("#subGnb").css("borderWidth","1px");
			$(this).css("position","static");
		});
		$("#subGnb div.subGnbDivision").mouseout(function()	{
			$("#subGnb").css("borderWidth","0px");
			$(this).css("position","absolute");
		});
	}
	// end main page
	else if (param=="subPage")
	{
		$("#subGnb div.subGnbDivision").css("position","absolute");
		$("#subGnb div.subGnbDivision").css("top","-9999px");
		$("#subGnb").css("position","absolute");
		$("#subGnb").css("top","-9999px");
		if (gnbOn <= 4)	{
			$("#mainNavi" + gnbOn + " img").attr("src",$("#mainNavi" + gnbOn + " img").attr("src").replace("_off","_on"));
			if (snbOn != '')	{
				$("#subGnb").css("position","static");
				$("#subNavi" + gnbOn).css("position","static");
				$("#subNavi" + gnbOn + " li:nth-child(" + snbOn + ")").attr("class","on");
			}
		}
		$("#gnb ol li a").hover(
			function()	{
				$("#subGnb").css("position","static");
				$("#subGnb div.subGnbDivision").css("position","absolute");
				$("#" + $(this).parent().attr("id").replace("main","sub")).css("position","static");
				$("#mainNavi1 a img").attr("src",$("#mainNavi1 a img").attr("src").replace("_on","_off"));
				$("#mainNavi2 a img").attr("src",$("#mainNavi2 a img").attr("src").replace("_on","_off"));
				$("#mainNavi3 a img").attr("src",$("#mainNavi3 a img").attr("src").replace("_on","_off"));
				$("#mainNavi4 a img").attr("src",$("#mainNavi4 a img").attr("src").replace("_on","_off"));
				$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_off","_on"));
			},
			function()	{
				//$("#gnb ol li a").children("img").attr("src",$("#gnb ol li a").children("img").attr("src").replace("_on","_off"));
				//$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_on","_off"));
				$("#mainNavi1 a img").attr("src",$("#mainNavi1 a img").attr("src").replace("_on","_off"));
				$("#mainNavi2 a img").attr("src",$("#mainNavi2 a img").attr("src").replace("_on","_off"));
				$("#mainNavi3 a img").attr("src",$("#mainNavi3 a img").attr("src").replace("_on","_off"));
				$("#mainNavi4 a img").attr("src",$("#mainNavi4 a img").attr("src").replace("_on","_off"));
			}
		);
		$("#gnb ol li a").focus(function()	{
			$("#subGnb").css("position","static");
			$("#subGnb div.subGnbDivision").css("position","absolute");
			$("#" + $(this).parent().attr("id").replace("main","sub")).css("position","static");
			$("#mainNavi1 a img").attr("src",$("#mainNavi1 a img").attr("src").replace("_on","_off"));
			$("#mainNavi2 a img").attr("src",$("#mainNavi2 a img").attr("src").replace("_on","_off"));
			$("#mainNavi3 a img").attr("src",$("#mainNavi3 a img").attr("src").replace("_on","_off"));
			$("#mainNavi4 a img").attr("src",$("#mainNavi4 a img").attr("src").replace("_on","_off"));
			$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_off","_on"));
		});
		$("#gnb ol li a").blur(function()	{
			$("#mainNavi1 a img").attr("src",$("#mainNavi1 a img").attr("src").replace("_on","_off"));
			$("#mainNavi2 a img").attr("src",$("#mainNavi2 a img").attr("src").replace("_on","_off"));
			$("#mainNavi3 a img").attr("src",$("#mainNavi3 a img").attr("src").replace("_on","_off"));
			$("#mainNavi4 a img").attr("src",$("#mainNavi4 a img").attr("src").replace("_on","_off"));
		});
		$("#subGnb div.subGnbDivision").mouseover(function()	{
			$("#subGnb").css("position","static");
			$("#subGnb div.subGnbDivision").css("position","absolute");
			$(this).css("position","static");
		});
	}
}
