/**
 * DDNavi.js Ver 1.0
 * Powered by hisato http://chibinowa.net/
 */

function DDNavi(targetID)
{
	// マウスオーバーからアクションが発生するまでの時間1000→1秒
	this.open_sleep = 100;

	// マウスアウトからアクションが発生するまでの時間1000→1秒
	this.close_sleep = 100;


	this.timer = null;

	this.active_oSubUl = null;

	if (document.getElementById(targetID)) {
		this.init(targetID);
	}
}

DDNavi.prototype.init = function(targetID)
{
	var rn = document.getElementById(targetID);
	for (i=0; i < rn.childNodes.length; i++) {//>
		var oMain = rn.childNodes[i];
		if (oMain.nodeName == "LI") {
			for (r=0; r < oMain.childNodes.length; r++) {//>
				var oSub = oMain.childNodes[r];
				if (oSub.nodeName == "UL") {
					oSubUl = oSub;
					EventListener.add(oMain, "mouseover", function(self, oSubUl){ return function(){self.open(oSubUl)} }(this, oSubUl), false);
					EventListener.add(oMain, "mouseout", function(self, oSubUl){ return function(){self.close(oSubUl)} }(this, oSubUl), false);
				}
			}
		}
	}
	EventListener.add(document.documentElement, "click", function(self){ return function(){self._close()} }(this), false);
}

DDNavi.prototype.open = function(oSubUl)
{
	// タイマーをリセット
	if (this.timer) {
		this.resetTimer();
	}

	// 既に開いてるものを終了or同じIDなら継続
	if (this.active_oSubUl) {
		if (this.active_oSubUl != oSubUl)
			this._close();
		//else
		//	return;
	}

	this.active_oSubUl = oSubUl;

	// オープン用のタイマーをセット
	this.timer = setTimeout(function(self){ return function(){self._open()} }(this), this.open_sleep);

}

DDNavi.prototype.close = function(oSubUl)
{
	// タイマーをリセット
	if (this.timer) {
		this.resetTimer();
	}
	// クローズ用のタイマーをセット
	this.timer = setTimeout(function(self){ return function(){self._close()} }(this), this.close_sleep);
}

DDNavi.prototype._open = function()
{
	this.active_oSubUl.style.visibility = "visible";
}

DDNavi.prototype._close = function()
{
	if (this.active_oSubUl) {
		this.active_oSubUl.style.visibility = "hidden";
		this.resetTimer();
		this.active_oSubUl = null;
	}
}

DDNavi.prototype.resetTimer = function()
{
	clearTimeout(this.timer);
	delete this.timer;
}

// プルダウン化したいリストIDを登録する
EventListener.add(window, "load", function(){ new DDNavi('NaviMenu') }, false);
EventListener.add(window, "load", function(){ new DDNavi('NaviMenu1') }, false);
EventListener.add(window, "load", function(){ new DDNavi('NaviMenu2') }, false);
EventListener.add(window, "load", function(){ new DDNavi('NaviMenu3') }, false);
EventListener.add(window, "load", function(){ new DDNavi('NaviMenu4') }, false);
EventListener.add(window, "load", function(){ new DDNavi('NaviMenu5') }, false);
EventListener.add(window, "load", function(){ new DDNavi('NaviMenu6') }, false);





