/*2009/08/11 KKato
------------------------------------------------------------------------------------*/
var flg_browser = 'etc';										//ブラウザ判別フラグ
var mouseOutTimer = '';											//マウスアウト時のタイマー変数
var backPass;																//表示中のID
var array_flgCurrentDirectory = new Array;	//現在のページでカレントボタンの判定用


/*ブラウザ判別(onload前の処理)
------------------------------------------------------------------------------------*/
window.onBeforeUnload = browser_check();

function browser_check()
{
	var browser = navigator.userAgent.toLowerCase();
		
	if(browser.indexOf('msie')	!= -1)	flg_browser = 'ie';
	
	OnloadAddEvent();
}


/*イベントハンドラ追加
------------------------------------------------------------------------------------*/
function OnloadAddEvent()
{	
	if(flg_browser == 'ie')	window.attachEvent('onload',Atag_addFunc);
	else	window.addEventListener('load',Atag_addFunc,false);
}

function Atag_addFunc()
{
	currentSet();
	var Atag	= document.getElementsByTagName('A');
	var txtF;
	var txtE;
	var pass;
	var id;
	
	for(i = 0; i < Atag.length; i++)
	{
		if(Atag[i].getAttribute('rel') == null) continue;
		if(Atag[i].getAttribute('rel').indexOf('pullDown') != -1)
		{						
			txtF = Atag[i].getAttribute('rel').indexOf('[') + 1;
			txtE = Atag[i].getAttribute('rel').indexOf(']');
			pass = Atag[i].getAttribute('rel').substring(txtF,txtE);
			
			if(flg_browser == 'ie')
			{
				Atag[i].attachEvent('onmouseover',pullDownOver);
				Atag[i].attachEvent('onmouseout',pullDownOut);
				document.getElementById(pass).attachEvent('onmouseover',listOver);
				document.getElementById(pass).attachEvent('onmouseout',listOut);
			}
			else
			{
				Atag[i].addEventListener('mouseover',pullDownOver,false);
				Atag[i].addEventListener('mouseout',pullDownOut,false);
				document.getElementById(pass).addEventListener('mouseover',listOver,false);
				document.getElementById(pass).addEventListener('mouseout',listOut,false);
			}
			
			Atag[i].setAttribute('rel',pass);
			array_flgCurrentDirectory[pass] = false;
			id = Atag[i].getAttribute('id');
			
			if(bgPositionYGet(id).indexOf('%') != -1 && bgPositionYGet(id).indexOf('100%') != -1)
			{
				array_flgCurrentDirectory[pass] = true;
			}
			if(bgPositionYGet(id).indexOf('%') == -1 && bgPositionYGet(id).indexOf('bottom') != -1)
			{
				array_flgCurrentDirectory[pass] = true;
			}
			
		}
	}
}


/*グローバルメニューカレント表示
------------------------------------------------------------------------------------*/
function currentSet()
{
	var url = location.href;
	if(url.lastIndexOf('/nichimoly/') != -1 || url.lastIndexOf('/aerosol/') != -1 || url.lastIndexOf('/rik/') != -1 || url.lastIndexOf('/ship/') != -1)
	{
		document.getElementById('t_jigyobu').style.backgroundPosition = '-225px bottom';
	}
	else if(url.lastIndexOf('/company/') != -1) document.getElementById('t_kigyo').style.backgroundPosition = '0px bottom';
	else if(url.lastIndexOf('/recruit/') != -1) document.getElementById('t_recruit').style.backgroundPosition = '-450px bottom';
	else if(url.lastIndexOf('/contact/') != -1) document.getElementById('t_contact').style.backgroundPosition = '-675px bottom';
}


/*pass取得
------------------------------------------------------------------------------------*/
function pullDownJudge(This)
{
	var pass;
	
	if(flg_browser == 'ie')
	{
		//pass = IEPassSet();
		pass = event.srcElement;
		pass.blur();
	}
	else pass = This;
	
	return pass.getAttribute('rel');
}


/*マウスオーバー時
------------------------------------------------------------------------------------*/
function pullDownOver()
{
	var pass = pullDownJudge(this);
	var styleX = bgPositionXGet(idGet(this));
	var styleY = bgPositionYGet(idGet(this));
	
	if(backPass != pass && backPass != undefined)
	{
		document.getElementById(backPass).style.visibility = 'hidden';
	}

	document.getElementById(pass).style.visibility = 'visible';
	
	if(array_flgCurrentDirectory[pass] != true)
	{
		if(styleY.indexOf('%') != -1 && styleY.indexOf('100%') == -1)
		{
			document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' bottom';
		}
		if(styleY.indexOf('%') == -1 && styleY.indexOf('bottom') == -1)
		{
			document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' bottom';
		}
	}
	
	listOver();
}


/*マウスアウト時
------------------------------------------------------------------------------------*/
function pullDownOut()
{	
	var pass = pullDownJudge(this);
	var styleX = bgPositionXGet(idGet(this));
	var styleY = bgPositionYGet(idGet(this));
	
	if(mouseOutTimer != '')
	{
		clearTimeout(mouseOutTimer);
		mouseOutTimer = null;
	}
	
	mouseOutTimer = setTimeout('mouseOut()', 200);
	backPass = pass;

	if(array_flgCurrentDirectory[pass] != true)
	{
		if(styleY.indexOf('%') != -1 && styleY.indexOf('100%') != -1)
		{
			document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' top';
		}
		if(styleY.indexOf('%') == -1 && styleY.indexOf('bottom') != -1)
		{
			document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' top';
		}
	}

}


/*プルダウンリスト箇所にマウスオーバーしてる場合
------------------------------------------------------------------------------------*/
function listOver()
{
	if(mouseOutTimer != '')
	{
		clearTimeout(mouseOutTimer);
		mouseOutTimer = null;
	}
}


/*プルダウンリスト箇所にマウスアウトした場合
------------------------------------------------------------------------------------*/
function listOut()
{
	mouseOutTimer = setTimeout('mouseOut()', 200);
}


/*表示非表示処理
------------------------------------------------------------------------------------*/
function mouseOut()
{
	document.getElementById(backPass).style.visibility = 'hidden';
}


/*クリックした箇所のidを取得
------------------------------------------------------------------------------------*/
function idGet(This)
{
	var pass;
	
	if(flg_browser == 'ie')
	{
		pass = event.srcElement;
		pass.blur();
	}
	else pass = This;

	return pass.getAttribute('id');
}


/*選択されたIDの背景ポジションX取得
------------------------------------------------------------------------------------*/
function bgPositionXGet(idPass)
{
	var bgpositionX;
	
	if(flg_browser == 'ie')
	{
		bgpositionX = cssStyleGet(idPass , 'backgroundPositionX');
	}
	else
	{
		var bgPosition = cssStyleGet(idPass , 'backgroundPosition');
		var space = bgPosition.indexOf(' ');
		bgpositionX = bgPosition.substring(0,space);
	}

	return bgpositionX;
}


/*選択されたIDの背景ポジションY取得
------------------------------------------------------------------------------------*/
function bgPositionYGet(idPass)
{
	var bgpositionY;
	
	if(flg_browser == 'ie')
	{
		bgpositionY = cssStyleGet(idPass , 'backgroundPositionY');
	}
	else
	{
		var bgPosition = cssStyleGet(idPass , 'backgroundPosition');	
		var space = bgPosition.indexOf(' ');
		bgpositionY = bgPosition.substring(space + 1);
	}
	
	return bgpositionY;
}


/*選択されたIDのCSS取得
------------------------------------------------------------------------------------*/
function cssStyleGet(idPass,styleType)
{	
	var pass = document.getElementById(idPass);
	
	if(flg_browser == 'ie')
	{
		return pass.currentStyle[styleType];
	}
	else return document.defaultView.getComputedStyle(pass, '')[styleType];
}