var firstHList = new Array();
var secondHAllList = new Array();
var thirdHList = new Array();
var fourthHList = new Array();
var tagList = new Array();
var productList = new Array();
var secondHList = new Array();
var rootCompositionList = new Array();

// -------------------------------------------------------------------
// 製品情報 Start
// -------------------------------------------------------------------

// 使用する第２階層を設定
//var factoryList = "0,1,2,3,4,5,6,7,8,9";
//var consumerList = "0,1,2,4,7,8,9";
//var officeList = "0,1,2,4,7,8,9,";

//1st release
//var factoryList = "0,1,2,3,4,5,6,7,8,9,10";
//var consumerList = "0,1,2,4,6,7,8,9";
//var officeList = "0,1,2,4,7,8,9,";

//var factoryList = "0,1,2,3,4,5,6,7,8,9,10,11";
//var consumerList = "0,1,2,3,6,7,8,11";
//var officeList = "0,1,2,4,7,8,11";

var factoryList = "0,1,3,4,5,7,9,11";
var consumerList = "0,1,3,7,11";
var officeList = "0,1,4,7,11";

var productList = "";

// 第１階層の設定
firstHList = new Array("factory=工場", "consumer=家庭", "office=オフィスビル");

// 第２階層の設定
secondHAllList = new Array(
                           "wbvrt=Embedded VRT",
                           "hdm4939=HDM4939", 
                        //   "nomadicnode=レイヤゼロ<br />NomadicNode&reg;&nbsp;ソリューション",
                           "xport=LANTRONIX&nbsp;XPort&nbsp;関連&nbsp;Products ",
                           "brproducts=B&R&nbsp;Products",
                           "systemmonitor=システム監視ボード",
                           "vxwin=VxWin",
                           "kukavxwin=KUKA-VxWin",
                           "cente=Cente&nbsp;ミドルウェア",
 //                          "bsquare=BSQUARE&nbsp;Products ",
                           "collabnet=CollabNet&nbsp;Enterprise&nbsp;Edition",
                           "arib= ARIB Middleware",
                           "at-em= AT-EM",
                           "dmcs= Full HD Digital Media Center Solution"
                          );

// 第３階層の設定
thirdHList = new Array(
//1st release          new Array("xport", "xportipv6=XPortAR&nbsp;with&nbsp;IPv6,xportnomadicnode=XPortAR&nbsp;with&nbsp;NomadicNode&reg;,dtfree=DT-Free"),
                       new Array("xport", "dtfree=DT-Free"),
//                     new Array("brproducts", "industrialpcs=Industrial&nbsp;PCs,iosystem=IO&nbsp;System,motioncontrol=MotionControl,powersupply=PowerSupply,networkfieldbus=Network/Fieldbus"),
                       new Array("cente", "filesystem=ファイルシステムパッケージ,network=ネットワークパッケージ,devicedriver=デバイスドライバパッケージ"),
                       new Array("bsquare", "sdiohx=BSQUARE&nbsp;SDIO&nbsp;Hx,schemabsp=BSQUARE&nbsp;SchemaBSP,devkitdp=BSQUARE&nbsp;DevkitIDP")
                      );

// 第４階層の設定
fourthHList = new Array(
                        new Array("industrialpcs", "panel=Panel,pc=PC"),
                        new Array("motioncontrol", "driver=Driver,motor=Motor"),
                        new Array("networkfieldbus", "can=CAN,profi=Profi,devicenet=DeviceNet,ethernetpoerlisk=EthernetPoerLisk"),
                        new Array("devkitdp", "pxa32x=Intel&nbsp;PXA32x&nbsp;DevkitIDP,pxa270=Intel&nbsp;PXA270&nbsp;DevkitIDP,pxa255=Intel&nbsp;PXA255&nbsp;DevkitIDP")
                       );

// 製品ヘッダの設定（タグジャンプ用）
tagList = new Array(
    new Array("wbvrt", "tag01=概要,tag02=ソフトウェア概念図,tag03=特長,tag04=スケジュール管理,tag05=デバイスドライバの共有,tag06=RTOSへの機能拡張,tag07=デモ動画(ARM版),tag08=デモ動画(Atom版),tag09=Embedded VRTサポートアーキテクチャ,tag10=Embedded VRT評価キット,tag11=ダウンロード"),
                    new Array("brproducts", "tag01=統合プログラミングツール"),
                    new Array("pxa32x", "tag01=特長,tag02=ブロック図,tag03=主な仕様,tag04=ダウンロード"),
                    new Array("pxa270", "tag01=特長,tag02=ブロック図,tag03=主な仕様,tag04=ダウンロード"),
                    new Array("pxa255", "tag01=特長,tag02=ブロック図,tag03=主な仕様,tag04=ダウンロード"),
                    new Array("filesystem", "tag01=ファイルシステムパッケージ一覧,tag02=FileSystem,tag03=SD Card Driver,tag04=SmartMedia Driver,tag05=NAND Flash Driver"),
                    new Array("network", "tag01=ネットワークパッケージ一覧,tag02=IPv6,tag03=IPSec,tag04=TCP/IPv4,tag05=HTTPd/c,tag06=SMTP/POP,tag07=PPP,tag08=SNMPv2,tag09=SSL,tag10=開発中のネットワークパッケージ"),
                    new Array("devicedriver", "tag01=デバイスドライバパッケージ一覧,tag02=802.11g PRISM,tag03=802.11b PRISM,tag04=USB1.1 Device,tag05=開発中のドライバパッケージ"),
                    new Array("cente", "tag01=概要,tag02=特長,tag03=各種パッケージ"),
                    new Array("sdiohx", "tag01=特長,tag02=ご使用前,tag03=ご使用後"),
//                    new Array("bsquare", "tag01=bSQUAREとは？,tag02=製品ラインナップ"),
                    new Array("systemmonitor", "tag01=特長,tag02=概要,tag03=ダウンロード"),
                    new Array("dtfree", "tag01=概要,tag02=ブロック図,tag03=仕様,tag04=ダウンロード"),
                    new Array("nomadicnode", "tag01=機能,tag02=特長,tag03=ウェルインテクノロジーでは・・・,tag04=ダウンロード"),
                    new Array("xport", "tag01=特長,tag02=ウェルインテクノロジーでは・・・,tag03=製品仕様,tag04=Xport03/AR+StackBoard<br/>&nbsp製品仕様,tag05=Xport03/AR+StackBoard<br/>&nbsp特長,tag06=ダウンロード"),
                    new Array("hdm4939", "tag01=概要,tag02=特長,tag03=その他対応可能及びアプリケーション,tag04=ダウンロード"),
                    new Array("vxwin", "tag01=特長,tag02=システム構成,tag03=TCP/IPパッケージの構成,tag04=TCP/IPパッケージの特長,tag05=UPS機能"),
                    new Array("kukavxwin", "tag01=割り込みはVxWorks優先で,tag02=BluescreenとRTOS??,tag03=OS間通信,tag04=システム要求,tag05=採用実績,tag06=ダウンロード"),
                    new Array("schemabsp", "tag01=サポート状況,tag02=ハードウェア回路図,tag03=ハードウェアサンプルリスト"),
                    new Array("collabnet", "tag01=概要,tag02=特徴,tag03=アーキテクチャ概要,tag04=ビジネス効果,tag05=画面イメージ,tag06=ダウンロード"),
                    new Array("arib", "tag01=特長,tag02=ソフトウェア構成,tag03=リファレンスハードウェア構成,tag04=製品仕様"),
		    		new Array("at-em", "tag01=特長,tag02=ソフトウェア構成,tag03=リファレンスハードウェア構成,tag04=製品仕様"),
		    		new Array("dmcs", "tag01=使用例,tag02=機能一覧,tag03=ダウンロード")
                    //new Array("vmm", "tag01=特長,tag02=状態遷移図,tag03=システム構成,tag04=Memory Allocation,tag05=スタートアップ・シーケンス,tag06=ダウンロード"),
                   );

// -------------------------------------------------------------------
// 製品情報 End
// -------------------------------------------------------------------

// HTML引数の設定
var strParam = location.search.substring(1).split('&');
var prm1 = strParam[0].split('=')[1];	// 第１引数
var prm2 = strParam[1].split('=')[1];	// 第２引数

// 製品コンテンツより遷移した場合
if(strParam[0].split('=')[1] != "top")
{
	if(prm1 == firstHList[0].split('=')[0])
	{
		productList = factoryList;
	}
	else if(prm1 == firstHList[1].split('=')[0])
	{
		productList = consumerList;
	}
	else if(prm1 == firstHList[2].split('=')[0])
	{
		productList = officeList;
	}
	
	// 第１階層の設定
	strNavi = getFirstHString();
	document.write(strNavi);
}
// トップページより遷移した場合
else
{
	for(var secondHAllListCnt=0; secondHAllListCnt<secondHAllList.length; secondHAllListCnt++)
	{
		productList = productList + secondHAllListCnt;
		if(secondHAllListCnt != secondHAllList.length-1) productList = productList + ",";
	}
}

var strNavi = "";
var selectedSecondHString = "";
var productAllCnt = 0;

productList = productList.split(',');
for(var productListCnt=0; productListCnt<productList.length; productListCnt++)
{
	secondHList.push(secondHAllList[productList[productListCnt]]);
}

// 第２階層の設定
strNavi = getSecondHFollowString();
document.write(strNavi);
if(document.getElementById(prm2))
{
	document.getElementById(prm2).style.display = "block";
}

// 選択された製品の紐付けを表示する
getCurrentStyle();

//==============================
// 第１階層の設定
//==============================
function getFirstHString()
{
	var rtnValue = "";

	rtnValue = rtnValue + "<div id=\"navitop\"><ul>";
	for(var firstCnt = 0; firstCnt < firstHList.length; firstCnt++)
	{
		firstHKey = firstHList[firstCnt].substring(0).split('=');
		var incDir = "";
		if(c == "4")
		{
			incDir = "../../";
		}
		else if(c == "5")
		{
			incDir = "../../../";
		}
		else if(c == "6")
		{
			incDir = "../../../../";
		}
		rtnValue = rtnValue + "<li class=\"top\"><a href=\"./" + incDir + firstHKey[0] + ".html?prm1=" + firstHKey[0] + "&prm2=\"";

		// 選択されたページの場合
		if(prm1 == firstHKey[0])
		{
			rtnValue = rtnValue + "class=\"current\"";
		}
		rtnValue = rtnValue + " >" + firstHKey[1] + "</a></li>";
	}
	rtnValue = rtnValue + "</ul></div>";

	return rtnValue;
}

//==============================
// 第２階層以下の設定
//==============================
function getSecondHFollowString()
{
	var rtnValue = "";
	var buttomNum = "";
	var thirdHString = "";
	var fourthHString = "";
	var secondCnt = 0;
	var thirdCnt = 0;
	var fourthCnt = 0;
	var thirdDetailCnt = 0;

	rtnValue = rtnValue + "<ul>";

	for(secondCnt = 0; secondCnt < secondHList.length; secondCnt++)
	{
		buttomNum = "2";
		thirdHString = "";
		fourthHString = "";

		for(thirdCnt = 0; thirdCnt < thirdHList.length; thirdCnt++)
		{
			// 第３階層が存在した場合
			if(secondHList[secondCnt].split('=')[0] == thirdHList[thirdCnt][0])
			{
				buttomNum = "3";
				thirdHString = thirdHList[thirdCnt][1];
				thirdHString = thirdHString.split(',');
			}
		}
		
		// 第２階層の作り込み
		rtnValue = rtnValue + getHTMLString(secondHList[secondCnt].split('=')[0], "", "", secondHList[secondCnt].split('=')[1], "2", buttomNum);
		// 第３階層の作り込み
		if(thirdHString.length != 0)
		{
			rtnValue = rtnValue + getToggleString(secondHList[secondCnt].split('=')[0]);
			for(thirdDetailCnt = 0; thirdDetailCnt < thirdHString.length; thirdDetailCnt++)
			{
				fourthHString = "";
				buttomNum = "3";
				for(fourthCnt = 0; fourthCnt < fourthHList.length; fourthCnt++)
				{
					if(thirdHString[thirdDetailCnt].split('=')[0] == fourthHList[fourthCnt][0])
					{
						buttomNum = "4";
						fourthHString = fourthHList[fourthCnt][1];
						fourthHString = fourthHString.split(',');
					}
				}
				rtnValue = rtnValue + getHTMLString(secondHList[secondCnt].split('=')[0], thirdHString[thirdDetailCnt].split('=')[0], "", thirdHString[thirdDetailCnt].split('=')[1], "3", buttomNum);
				// 第４階層の作り込み
				if(fourthHString.length != 0)
				{
					rtnValue = rtnValue + getToggleString(thirdHString[thirdDetailCnt].split('=')[0]);
					for(fourthDetailCnt = 0; fourthDetailCnt < fourthHString.length; fourthDetailCnt++)
					{
						rtnValue = rtnValue + getHTMLString(secondHList[secondCnt].split('=')[0], thirdHString[thirdDetailCnt].split('=')[0], fourthHString[fourthDetailCnt].split('=')[0], fourthHString[fourthDetailCnt].split('=')[1], "4", buttomNum);
					}
					rtnValue = rtnValue + "</ul>";
				}
			}
			rtnValue = rtnValue + "</ul>"
		}
	}

	rtnValue = rtnValue + "</ul>";

	return rtnValue;
}

//==============================
// HTML文字列の作成
//==============================
function getHTMLString(secondKey, thirdKey, fourthKey, value, parentNum, buttomNum)
{
	var rtnValue = "";
	var strClass = "";
	var strHref = "";
	var strTagJump = "";
	var srtClassCurrent = "";
	var strOnMouse = "";
	var strExplanation = "";
	var strTagJump = "";
	var key = secondKey;
	var strSecondDir = "";
	var strThirdDir = "";
	var strFourthDir = "";

	if(secondKey != "")
	{
		strSecondDir = secondKey + "/";
	}
	if(thirdKey != "")
	{
		key = thirdKey;
		strThirdDir = thirdKey + "/";
	}
	if(fourthKey != "")
	{
		key = fourthKey;
		strFourthDir = fourthKey + "/";
	}

	productAllCnt++;
	rootCompositionList.push(prm1 + "," + secondKey + "," + thirdKey + "," + fourthKey + "," + productAllCnt);

	if(key == prm2)
	{
		srtClassCurrent = "class=\"current\"";
	}
	if(prm2 == "")
	{
		strHref = strHref + "./";
	}
	else
	{
		if(c == "4")
		{
			strHref = strHref + "../../";
		}
		else if(c == "5")
		{
			strHref = strHref + "../../../";
		}
		else if(c == "6")
		{
			strHref = strHref + "../../../../";
		}
	}
	strHref = strHref + "list/" + strSecondDir + strThirdDir + strFourthDir + "index.html?prm1=" + prm1 + "&prm2=" + key;

	for(var prodictCnt = 0; prodictCnt < tagList.length; prodictCnt++)
	{
		if(key == tagList[prodictCnt][0] && srtClassCurrent != "")
		{
			strTagJump = getTagJumpString(tagList[prodictCnt][1]);
		}
	}

	if(parentNum == "2")
	{
		strOnMouse = getOnMouseString(key);
		strExplanation = getExplanationString(key);
	}
	rtnValue = rtnValue + "<li class=\"sublist\"><a href=\"" + strHref + "\" " + strOnMouse + srtClassCurrent + ">" + value + "</a></li>" + "\n";
	rtnValue = rtnValue + strExplanation;

	return rtnValue + strTagJump;
}

//==============================
// トグル文字列の作成
//==============================
function getToggleString(key)
{
	var rtnValue = "";

	rtnValue = "<ul id=\"" + key + "\" style=\"display:none\">";
	
	return rtnValue;
}

//==============================
// タグジャンプの設定
//==============================
function getTagJumpString(productTagList)
{
	var rtnValue = "";
	var productTagArray = productTagList.split(',');
	for(var productTagArrayCnt = 0; productTagArrayCnt < productTagArray.length; productTagArrayCnt++)
	{
		rtnValue = rtnValue + "<li class=\"taglist\"><a href=\"?prm1=" + prm1 + "&prm2=" + prm2 + "#" + productTagArray[productTagArrayCnt].split('=')[0] + "\">" + productTagArray[productTagArrayCnt].split('=')[1] + "</a></li>" + "\n";
	}

	return rtnValue;
}

//==============================
// マウス遷移時の設定
//==============================
function getOnMouseString(key)
{
	var rtnValue = "";

	rtnValue = rtnValue + " onmouseover=\"showExplanation('explanation_" + key + "'); return true; \"";
	rtnValue = rtnValue + " onmouseout=\"hideExplanation('explanation_" + key + "'); return true; \"";

	return rtnValue;
}

//==============================
// 選択製品の設定
//==============================
function getCurrentStyle()
{
	var toggleSecond = "";
	var toggleThird = "";
	var toggleKey = prm2;

	for(var i=0; i<rootCompositionList.length; i++)
	{
		if(toggleKey == rootCompositionList[i].split(',')[3] &&
		   rootCompositionList[i].split(',')[3] != "")
		{
			toggleThird = rootCompositionList[i].split(',')[2];
			toggleKey = toggleThird;
		}
	}
	for(var i=0; i<rootCompositionList.length; i++)
	{
		if(toggleKey == rootCompositionList[i].split(',')[2] &&
		   rootCompositionList[i].split(',')[2] != "")
		{
			toggleSecond = rootCompositionList[i].split(',')[1];
		}
	}

	if(toggleSecond != "")
	{
		document.getElementById(toggleSecond).style.display = "block";
	}
	if(toggleThird != "")
	{
		document.getElementById(toggleThird).style.display = "block";
	}
}

//==============================
// 製品説明の作成
//==============================
function getExplanationString(key)
{
	var rtnValue = "";

	for(var i=0; i<productslist.length; i++)
	{
		if(productslist[i][0] == key)
		{
			rtnValue = rtnValue + "<div id=\"subnavi\">";
			rtnValue = rtnValue + "<div id=\"explanation_" + productslist[i][0] + "\">";
			rtnValue = rtnValue + "<span class=\"spn\">" + productslist[i][3] + "</span>";
			rtnValue = rtnValue + "</div>";
			rtnValue = rtnValue + "</div>";
		}
	}

	return rtnValue + "\n";
}
