/*2009/08/11 KKato
------------------------------------------------------------------------------------*/
var flg_browser = 'etc';					//ブラウザ判別フラグ
var mouseOutTimer = '';
var backPass;

/*ブラウザ判別(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 pass;
	var txtF;
	var txtE;
	
	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',timerClear);
				document.getElementById(pass).attachEvent('onmouseout',listOut);
			}
			else
			{
				Atag[i].addEventListener('mouseover',pullDownOver,false);
				Atag[i].addEventListener('mouseout',pullDownOut,false);
				document.getElementById(pass).addEventListener('mouseover',timerClear,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));
	var flg;
	
	if(backPass != pass && backPass != undefined)
	{
		document.getElementById(backPass).style.visibility = 'hidden';
	}
	
	document.getElementById(pass).style.visibility = 'visible';
		
	if(styleY.indexOf('%') != -1)
	{
		flg = true;
	}
	else flg = false;
	
	if(flg && styleY.indexOf('100%') == -1)
	{
		document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' center';
	}
	else if(!flg && styleY.indexOf('bottom') == -1)
	{
		document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' center';
	}
	
	timerClear();
}


/*マウスアウト時
------------------------------------------------------------------------------------*/
function pullDownOut()
{	
	var pass = pullDownJudge(this);
	var styleX = bgPositionXGet(idGet(this));
	var styleY = bgPositionYGet(idGet(this));
	var flg;
	
	if(mouseOutTimer != '')
	{
		clearTimeout(mouseOutTimer);
		mouseOutTimer = null;
	}
	
	mouseOutTimer = setTimeout('mouseOut()', 200);
	backPass = pass;
	
	if(styleY.indexOf('%') != -1)
	{
		flg = true;
	}
	else flg = false;
	
	if(flg && styleY.indexOf('100%') == -1)
	{
		document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' top';
	}
	else if(!flg && styleY.indexOf('bottom') == -1)
	{
		document.getElementById(idGet(this)).style.backgroundPosition = styleX + ' top';
	}
}


/*プルダウンリスト箇所にマウスオーバーしてる場合
------------------------------------------------------------------------------------*/
function timerClear()
{
	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];
}