var category = new Array("HOME", "AIUEO", "TC", "LG", "FF", "CW", "NR", "SEARCH");

var categoryPath = new Array();
categoryPath["HOME"]   = "index.html";
categoryPath["AIUEO"]  = "a";
categoryPath["TC"]     = "tc-0105";
categoryPath["LG"]     = "lg-0105";
categoryPath["FF"]     = "ff-0105";
categoryPath["CW"]     = "cw-0105";
categoryPath["NR"]     = "nr-0105";
categoryPath["SEARCH"] = "search";

var volumePrefixes = new Array("tc", "lg", "ff", "cw", "nr");

var CHARACTER = 0;
var TOOL      = 1;
var LINK      = 2;
var PLACE     = 3;
var DATA      = 4;

var voiced = new Array(
	new Array('a','i','u','e','o','v'),
	new Array('k','g','c','q'),
	new Array('s','j','z'),
	new Array('t','d'),
	new Array('r','l'),
	new Array('h','f','b','p')
)

function getVoicelessChar(headChar) {
	ret = headChar.toLowerCase();

	for(i = 0; i < voiced.length; i++) {
		for(n = 0; n < voiced[i].length; n++) {
			if(voiced[i][n] == ret) {
				ret = voiced[i][0];
				break;
			}
		}
	}

	return ret;
}

function showDetail(detailName, detailKind) {
	var dir  = Dora.requiredFrameDirs[detailKind];
	var file = "";
	var hi  = 0;
	var low = 0;
	var n   = 0;
	var showLocation = null;

	if(detailName == '') {
		return;
	} else {
		for(i = 0; i < category.length; i++) {
			if(category[i] == detailName) {
				file = categoryPath[detailName];
				break;
			}
		}
	}

	if (self.name == "navi") {
		if (file == "search") {
			showLocation = parent.location;
		} else if (parent.desc == null) {
			showLocation = self.location;
		} else {
			showLocation = parent.desc.location;
		}
	} else {
		showLocation = self.location;
	}

	if (file == "search") {
		file = "../search/index.html"
		file += "?dataKind=" + Dora.requiredFrameDirs[detailKind];

		showLocation.href = file;
	} else {
		if (file == '')
			file = getDetailFileName(detailName);
		
		if (parent.frames.length == 0) {
			showLocation.href = Dora.getRedirectFramePath() + Dora.getQuery(dir, file+".html#" + detailName);
		} else {
			showLocation.href = Dora.getServerPath() + dir + "/" + file + ".html#" + detailName;
		}
		
		
	}
}

function getDetailFileName(detailName) {
	var exists = false;
	var file = "";
	var buff = detailName.substring(0, 2);
	for (var i = 0; i < volumePrefixes.length; i++) {
		if (buff == volumePrefixes[i]) {
			buff += "-";

			file = detailName.substring(3, 5);
			if (isNaN(file)) {
				file = "a";
				break;
			}

			n = eval(file)-1;

			hi = Math.floor((n+5)/5) * 5
			low = hi - (5-1);

			(low < 10) ? file =  '0' + low : file =  low;
			(hi  < 10) ? file += '0' + hi  : file += '' + hi;

			file = buff + file;

			exists = true;
			break;
		}
	}

	if (!exists) {
		file = getVoicelessChar(detailName.charAt(0));
		if (file != 'a') file += 'a';
	}
	
	return file;
}

function showCharacter(detailName) {
	showDetail(detailName, CHARACTER);
}

function showTool(detailName) {
	showDetail(detailName, TOOL);
}

function showPlace(detailName) {
	showDetail(detailName, PLACE);
}

function showData(detailName) {
	showDetail(detailName, DATA);
}

function showLink(file) {
	if (file != "") {
		var dir = "link";
		if (Dora.systemFrameExixts()) {
			desc.location.href = Dora.getServerPath() + dir + "/" + file + ".html"
		} else if (Dora.topFrameExixts()) {
			top.contents.location.href = Dora.getRedirectFramePath() + Dora.getQuery(dir, file+".html");
		} else {
			location.href = Dora.getServerPath() + "index.html" + Dora.getQuery(dir, file+".html");
		}
	}
}
