/*グローバル変数
-----------------------------------------------------------------------*/
var flg_browser;							//ブラウザの判別　IE = true
var httpOj;										//外部xml読み込み
var imgList = new Array();		//ランダムした画像を代入
var alphaTimer = '';					//アルファ時のタイマー変数
var changeTimer = '';					//表示切替時のタイマー変数
var alpha = 0;							//透明度
var counter = 0;							//現在表示している画像の配列番号
//var host = 'http://' + location.host + '/';
//var url;
var num  = 1;

window.onBeforeUnload = browser_check();


/*ブラウザ判別
-----------------------------------------------------------------------*/
function browser_check(){
	var browser = navigator.userAgent.toLowerCase();
	if(browser.indexOf("msie") != -1) flg_browser = 'ie';
	else flg_browser = 'etc';
	OnloadAddEvent();
}


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

/*トップ画像オープン
------------------------------------------------------------------------------------*/
function firstImgOpen(){
	var imgPass = document.getElementById("MVimg1").style;
	imgPass.visibility = 'visible';

	alphaTimer = setTimeout('firstImgOpen()',15);

	imgPass.filter = 'alpha(opacity=' + (alpha) + ')';
	imgPass.opacity = alpha / 100;

	if(alpha >= 100){
		clearTimeout(alphaTimer);
		alphaTimer = '';
		alpha = 0;
		num = num + 1;
		changeTimer = setTimeout('mvImgOpen()',7000);
	}else{
		alpha += 0.3 + (alpha*1.1 / 100);
	}

}

function mvImgOpen(){
	
		
	var imgPass = document.getElementById("MVimg"+num).style;
	imgPass.visibility = 'visible';

	alphaTimer = setTimeout('mvImgOpen()',15);

	imgPass.filter = 'alpha(opacity=' + (alpha) + ')';
	imgPass.opacity = alpha / 100;

	if(alpha >= 100){
		clearTimeout(alphaTimer);
		alphaTimer = '';
		alpha = 0;
/*		if(num == 1){
			document.getElementById("MVimg4").style.visibility = 'hidden';			
			document.getElementById("MVimg4").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg4").style.opacity = 0;			
			document.getElementById("MVimg1").style.zIndex = 1;			
		}else if(num == 2){
			document.getElementById("MVimg1").style.visibility = 'hidden';
			document.getElementById("MVimg1").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg1").style.opacity = 0;			
			document.getElementById("MVimg1").style.zIndex = 10;			
		}else if(num == 3){
			document.getElementById("MVimg2").style.visibility = 'hidden';
			document.getElementById("MVimg2").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg2").style.opacity = 0;			
		}else if(num == 4){
			document.getElementById("MVimg3").style.visibility = 'hidden';
			document.getElementById("MVimg3").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg3").style.opacity = 0;			
		}*/
		if(num == 1){
			document.getElementById("MVimg4").style.visibility = 'hidden';			
			document.getElementById("MVimg4").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg4").style.opacity = 0;			
			document.getElementById("MVimg1").style.zIndex = -5;			
		}else if(num == 2){
			document.getElementById("MVimg1").style.visibility = 'hidden';
			document.getElementById("MVimg1").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg1").style.opacity = 0;			
			document.getElementById("MVimg1").style.zIndex = -1;			
		}else if(num == 3){
			document.getElementById("MVimg2").style.visibility = 'hidden';
			document.getElementById("MVimg2").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg2").style.opacity = 0;			
		}else if(num == 4){
			document.getElementById("MVimg3").style.visibility = 'hidden';
			document.getElementById("MVimg3").style.filter = 'alpha(opacity=' + (0) + ')';		
			document.getElementById("MVimg3").style.opacity = 0;			
		}
		num = num + 1;
		if(num == 5) num = 1;
		changeTimer = setTimeout('mvImgOpen()',12000);
		/*changeTimer = setTimeout('mvImgOpen()',2000);*/
	}else{
		alpha += 0.9 + (alpha*1.1 / 100);
	}

}













/*画像の重なり順番を変更
-----------------------------------------------------------------------*/
function openImg()
{	
	var num = counter;
	document.getElementById('jsChangeNumber' + num).style.zIndex = '-1';
	if(num >= imgList.length - 1) num = 0;
	else num++;
	
	document.getElementById('jsChangeNumber' + num).style.zIndex = '-2';
	document.getElementById('jsChangeNumber' + num).style.visibility = 'visible';
	
	document.getElementById('jsMainImgDisplayBOX').style.visibility = 'visible';
	changeTimer = setTimeout('closeImg()',5000);
	/*changeTimer = setTimeout('closeImg()',1000);*/
}


/*img非表示アニメーション
-----------------------------------------------------------------------*/
function closeImg()
{
	if(changeTimer != '')
	{
		clearTimeout(changeTimer);
		changeTimer = '';
	}
	
	var pass = document.getElementById('jsChangeNumber' + counter).style;
	
	alphaTimer = setTimeout('closeImg()',20);
		
	pass.filter = 'alpha(opacity=' + (alpha) + ')';
	pass.opacity = alpha / 100;
		
	if(alpha <= 0)
	{
		clearTimeout(alphaTimer);
		alphaTimer = '';
		document.getElementById('jsChangeNumber' + counter).style.zIndex = (counter + 100) * (-1);
		alpha = 100;
		pass.filter = 'alpha(opacity=' + (alpha) + ')';
		pass.opacity = alpha / 100;
		if(counter >= imgList.length - 1) counter = 0;
		else counter++;
		openImg();
	}
	else alpha -= 2 + (alpha / 130);
}
