/* 対象一覧 */
var accrodion_list = new Array();
/* 画像分の高さ */
var height_img = 112;
/* テキスト分の高さ */
var height_txt = 82;
/* 現在表示 */
var current = 1;
/* */
var timer = null;
/* 移動処理の間隔（小さいほど早い） */
var interval = 1;
/* 移動の差分（大きいほど早い） */
var delay = 6;
/* */
var move = 0;

//IE判定
var ie = false;
if( navigator.appName == "Microsoft Internet Explorer" ) {
	ie = true;
}
else {
	//FF用に調整
	delay = 36;
}

window.onload = function() {
	//初期化処理
	var banner_base = document.getElementById( "accordion_list" );
	if( banner_base ) {
		var list = banner_base.getElementsByTagName( "div" );

		var cnt = 0;

		for( var idx=0; idx<list.length; idx++ ) {
			if( list[ idx ].className == "accordion" ) {
				cnt ++;

				list[ idx ].id = "accordion" + cnt;

				list[ idx ].style.zIndex = list.length - idx + 1;
				list[ idx ].style.top = ( cnt - 1 ) * height_txt +  "px";

				setToggle( list[ idx ] );

				//一覧に追加
				accrodion_list.push( list[ idx ] );
			}
		}
	}
}

/**
 *	トグル設定
 */
function setToggle( e ) {
	var toggle = null;
	var list = e.getElementsByTagName( "div" );

	for( var idx=0; idx<list.length; idx++ ) {
		if( list[ idx ].className == "accordion_txt" ) {
			toggle = list[ idx ];
			break;
		}
	}

	if( toggle ) {
		toggle.onmouseover = function() {
			show_image( this );
		}
	}
}

/**
 *	アコーディオン表示開始
 */
function show_image( toggle ) {
	var accordion = toggle.parentNode;
	if( accordion && accordion.id.match( /accordion([0-9]+)/ ) ) {

		var index = RegExp.$1;
		if( index != current ) {
			if( timer ) {
				//移動中の為、不可
				return;
			}

			move = 0;
			timer = setTimeout( "move_accordion(" + index + ")", interval );
		}
	}
}

/**
 *
 */
function move_accordion( index ) {
	var start;
	var end;

	var x = delay;
	if( move + x >= height_img ) {
		x = height_img - move;
	}

	if( index < current ) {
		//現在より上の物を表示
		start = index;
		end = current;

		for( idx=start; idx<end; idx++ ) {

			accrodion_list[ idx - 1 ].style.top = ( parseInt( accrodion_list[ idx - 1 ].style.top ) + x ) + "px";
		}
	}
	else if( index > current ) {
		//現在より下の物を表示
		start = current;
		end = index;

		for( idx=start; idx<end; idx++ ) {
			accrodion_list[ idx - 1 ].style.top = ( parseInt( accrodion_list[ idx - 1 ].style.top ) - x ) + "px";
		}
	}

	move += delay;

	if( move < height_img ) {
		timer = setTimeout( "move_accordion(" + index + ")", interval );
	}
	else {
		current = index;
		timer = null;
	}
}
