var Navigation = function(){
	this.checkIE = ""; //Check IE 5.5 & 6
	this.header = parent.frames['header']; //Header Frame
	this.currentID = "navi1"; //currentID
	this.lv1ID = ""; //Navigation level1 id name
	this.lv2ID = ""; //Navigation level2 id name
	this.wrapCnt = {} //Wrap In List Count
}

Navigation.prototype.navigationOut = function() {
	document.getElementById("navigationLayer").style.visibility = "hidden";
	document.getElementById("naviOut").style.visibility = "hidden";
	if (document.getElementById(this.lv2ID + "_Wrap")) document.getElementById(this.lv2ID + "_Wrap").style.visibility = "hidden";
	if (document.getElementById(this.lv1ID + "_Wrap")) document.getElementById(this.lv1ID + "_Wrap").style.visibility = "hidden";
	this.lineOut();
	this.lv1ID = "";
	this.lv2ID = "";
};

Navigation.prototype.out = function() {
	this.header.Navi.navigationOut();
	this.navigationOut();
};

Navigation.prototype.lineOut = function() {
	for (var i=1;i<=this.wrapCnt[this.lv1ID];i++) {
		var id = "line"+this.lv1ID+"_"+i;
		document.getElementById(id).style.borderLeft = "solid 1px #bbbbbb";
		document.getElementById(id).childNodes[0].style.visibility = "hidden";
		document.getElementById(id).childNodes[0].style.width = "auto";
	}
	for (var i=1;i<this.wrapCnt[this.lv1ID];i++) {
		var id = this.lv1ID+"_"+i;
		document.getElementById(id).style.borderRight = "solid 1px #bbbbbb";
		document.getElementById(id).style.borderLeft = "solid 1px #bbbbbb";
		document.getElementById(id).style.paddingLeft = "13px";
	}
};

Navigation.prototype.over = function(self) {
	//Scroll Contents Window
	//window.scroll(0,0);
	//Navigation ID
	var ids = self.getAttribute("id");
	if (ids.indexOf("line") > -1) ids = ids.slice(4);
	var p = ids.split("_");
	//Navigation line
	this.lineOut();
	document.getElementById("line"+ids).childNodes[0].style.visibility = "visible";
	var nline = Number(p[1]) + 1;
	if (document.getElementById("line" + p[0] + "_" + nline)) document.getElementById("line" + p[0] + "_" + nline).childNodes[0].style.visibility = "visible";
	//navigation level2
	if (nTree[this.lv1ID].lv3P == "left" && document.getElementById(ids+"_Wrap")) {
		document.getElementById(ids).style.borderLeft = "none";
		document.getElementById("line" + ids).style.borderLeft = "none";
		document.getElementById(ids).style.paddingLeft = "14px";
		document.getElementById("line" + ids).childNodes[0].style.width = "100%";
	} else if (document.getElementById(ids+"_Wrap")) {
		document.getElementById(ids).style.borderRight = "none";
		document.getElementById("line" + ids).style.Right = "none";
	}
	//navigation level3
	if (this.lv2ID) document.getElementById(this.lv2ID + "_Wrap").style.visibility = "hidden";
	if (document.getElementById(ids+"_Wrap")) {
		document.getElementById(ids+"_Wrap").style.visibility = "visible";
		if (nTree[this.lv1ID].lv3P == "right") {
			var posX = document.getElementById(this.lv1ID+"_Wrap").offsetWidth + document.getElementById(this.lv1ID+"_Wrap").offsetLeft;
			document.getElementById(ids+"_Wrap").style.left = posX - (6+1) + "px";
		} else {
			var posX = document.getElementById(this.lv1ID+"_Wrap").offsetLeft - document.getElementById(ids+"_Wrap").offsetWidth + 12;
			document.getElementById(ids+"_Wrap").style.left = posX - (6-1) + "px";
			document.getElementById(this.lv1ID+"_Wrap").style.zIndex = 100;
		}
		posY = document.body.scrollTop || document.documentElement.scrollTop;
		document.getElementById(ids+"_Wrap").style.top = document.getElementById("line"+ids).offsetTop + posY + "px";
		this.lv2ID = ids;
	} else {
		this.lv2ID = "";
	}
	//#naviOut Style
	document.getElementById("naviOut").style.visibility = "visible";
};

Navigation.prototype.fixPng = function(w,h,src,sizing) {
	return 'width:'+w+';height:'+h+';filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+src+'\', sizingMethod=\''+sizing+'\');';
}
Navigation.prototype.makeTagLine = function(tags,ids,lv,cnt,w) {
	return '<div class="lineT">&nbsp;</div><div class="lineC">&nbsp;</div><div class="lineB">&nbsp;</div>';
};
Navigation.prototype.makeTag = function(tags,ids,lv,cnt,w) {
	var str = '<table class="naviLv' + lv + '" id="' + ids + '_Wrap" cellspacing="0" cellpadding="0"><tr><th colspan="2">';
	str += '<table class="navi" style="width:' + w + 'px;" cellspacing="0" cellpadding="0">';
	if (lv == 2) str += '<tr><td class="naviT">&nbsp;</td></tr>';
	str += tags;
	if (lv == 2) str += '<tr><td style="padding:0;" id="line' + ids + "_" +cnt + '"><div class="line">'+this.makeTagLine()+'</div></td></tr>';
	str += '<tr><td class="naviB">&nbsp;</td></tr></table></th>';
	if (this.checkIE) {
		str += '<td id="' + ids + '_WrapSR"></td>';
		str += '</tr><tr>';
		str += '<td class="naviSLB"><div style="'+this.fixPng('6px','6px',root+'/common/images/shadow_lb.png','crop')+'">&nbsp;</div></td>';
		str += '<td class="naviSB"><div style="'+this.fixPng((w-6)+'px','30px',root+'/common/images/shadow_b.png','scale')+'">&nbsp;</div></td>';
		str += '<td class="naviSRB"><div style="'+this.fixPng('6px','6px',root+'/common/images/shadow_rb.png','crop')+'">&nbsp;</div></td>';
		str += '</tr></table>';
	} else {
		str += '<td class="naviSR" style="background: url('+root+'/common/images/shadow_r.png) repeat-y;">&nbsp;</td>';
		str += '</tr><tr>';
		str += '<td class="naviSLB" style="background: url('+root+'/common/images/shadow_lb.png) no-repeat;">&nbsp;</td>';
		str += '<td class="naviSB" style="background: url('+root+'/common/images/shadow_b.png) repeat-x;"><div style="width:'+ (w-6) +'px;">&nbsp;</div></td>';
		str += '<td class="naviSRB" style="background: url('+root+'/common/images/shadow_rb.png) no-repeat;">&nbsp;</td>';
		str += '</tr></table>';
	}
	return str;
};

Navigation.prototype.set = function() {
	if (!top.ParentFrame && location.pathname) {
		var p = location.pathname.split("_c.");
		var url = p[0]+"."+p[1];
		location.href = url;
	}
	this.checkIE = checkIE();
	//Get nTree
	var str = '<div id="naviOut" onmouseover="Navi.out()"><img src="'+root+'/common/images/spacer.gif" width="100%" height="100%"></div>';
	for(var i in nTree){
		var tags = {};
		for(var j in nTree[i].list){
			var cntLv3 = 1;
			var p = nTree[i].list[j].split("<>");
			if (Number(p[0]) == 2) {
				//Navigation Level 2
				if (!tags[i]) tags[i] = "";
				if (!this.wrapCnt[i]) this.wrapCnt[i] = 0;
				this.wrapCnt[i]++;
				var ids = i + "_" + this.wrapCnt[i];
				tags[i] += '<tr><td style="padding:0;" id="line' + ids + '" onmouseover="Navi.over(this)"><div class="line">'+this.makeTagLine()+'</div></td></tr>';
				tags[i] += '<tr><td id="' + ids + '" onmouseover="Navi.over(this)">';
				tags[i] += '<a href="' + root + p[2] + '" target="_top">' + p[1] + '</a></td></tr>';
			} else if (Number(p[0]) == 3) {
				//Navigation Level 3
				if (!tags[ids]) tags[ids] = "";
				if (!this.wrapCnt[ids]) this.wrapCnt[ids] = 0;
				this.wrapCnt[ids]++;
				if (this.wrapCnt[ids] == 1) {
					if (nTree[i].lv3P == "right") {
						tags[ids] += '<tr><td style="padding:0; border-left:0;"><div class="line">'+this.makeTagLine()+'</div></td></tr><tr><td style="border-left:none;padding-left:14px;">';
					} else {
						tags[ids] += '<tr><td style="padding:0;"><div class="line">'+this.makeTagLine()+'</div></td></tr><tr><td style="border-right:none;">';
					}
				} else {
					tags[ids] += '<tr><td class="noline">&nbsp;</td></tr><tr><td>';
				}
				tags[ids] += '<a href="' + root + p[2] + '" target="_top">' + p[1] + '</a></td></tr>';
			}
		}
		for(var j in tags) {
			this.wrapCnt[j]++;
			var d = j.split("_");
			var w = ((d.length + 1) == 2)? nTree[i].lv2W : nTree[i].lv3W;
			str += this.makeTag(tags[j],j,d.length + 1,this.wrapCnt[j],w);
		}
	}
	//Append Html
	var layer = document.createElement("div");
	layer.setAttribute("id","navigationLayer");
	layer.innerHTML = str;
	document.body.appendChild(layer);
	//IE png
	if (this.checkIE) {
		for(var i in this.wrapCnt) {
			var h = document.getElementById(i+"_Wrap").offsetHeight;
			var str = '<div style="'+this.fixPng('6px',(h-30)+'px',root+'/common/images/shadow_r.png','scale')+'"></div>';
			document.getElementById(i+"_WrapSR").innerHTML = str;
		}
	}
	//Navigation Contents Load Check
	top.LodeContents = true;
};

Navigation.prototype.scroll = function() {
	if (this.lv1ID) {
		this.header.Navi.navigationOut();
		this.navigationOut();
	}
};

function loadContents() {
	Navi.set();
	resizeWindow();
}
function resizeWindow(){
	if (document.getElementById("wrapperColumn") && document.getElementById("unitNavigation")) {
		var contentsH = document.getElementById("wrapperColumn").offsetHeight;
		var windowH = document.documentElement.clientHeight || document.body.clientHeight;
		var h = (contentsH < windowH)? windowH : contentsH + 32;
		document.getElementById("unitNavigation").style.height = h - 32 + "px";
	}
	
}
function scrollWindow(){
	Navi.scroll();
}
function unloadContents(){
	top.LodeContents = false;
	if (parent.frames['header']) parent.frames['header'].Navi.navigationOut();
}
var Navi = new Navigation();
eventObserve(window, 'load', loadContents, false);
eventObserve(window, 'unload', unloadContents, false);
eventObserve(window, 'resize', resizeWindow, false);
eventObserve(window, 'scroll', scrollWindow, false);


function setElementClassById(elem, value) {
	if(document.getElementById) {
		var obj = document.getElementById(elem);
		if(obj) {
			obj.className = value;
		}
	}
}