
var flg_browser = 'etc';					//ブラウザ判別フラグ
var mouseOutTimer = '';
var backPass;
/*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()
{
	var Atag	= document.getElementsByTagName('A');
	var txtF;
	var txtE;
	var pass;
	
	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);

		}
	}
}


/*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';
	
	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;

}


/*プルダウンリスト箇所にマウスオーバーしてる場合
------------------------------------------------------------------------------------*/
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
	{		
		//alert(document.defaultView.getComputedStyle(pass, '').backgroundPositionY);
		return document.defaultView.getComputedStyle(pass, '')[styleType];
	}
	
	
}
