// JavaScript Document
var tableWidth = 667;
var tdWidth = 112;
var chgItems;
var isActive = false;

// メニュークリック時
function changePanel(currentItem)
{
	i = 1;
	
	do {
		document.getElementById("sliderButton" + i).className = "slider";
		document.getElementById("sliderContent" + i).style.display = "none";
		i++;
	}while(document.getElementById("sliderButton" + i));
	
	document.getElementById("sliderButton" + currentItem).className = "sliderActive";
	document.getElementById("sliderContent" + currentItem).style.display = "block";
}

// テーブルの左端の位置を取得
function getLeftPosition(sliderTable)
{
	// 現在のテーブルの要素を取得
	chgItems = document.getElementById(sliderTable);
		
	if(chgItems.currentStyle) {		// IE
		return parseInt(chgItems.currentStyle["left"]);
	}
	else {		// FireFox, Oper
		return parseInt(document.defaultView.getComputedStyle(chgItems, null).getPropertyValue("left"));
	}
}

// 左ボタンのクラス変更
function changeButtonClass(sliderTable)
{
	if(null != chgItems)
	{
		chgItems = document.getElementById(sliderTable);
		
		var currentPosition = parseInt(getLeftPosition(sliderTable));
		
		if(currentPosition >= 0)
			document.getElementById("previous").className = "previousBtn";
		else
			document.getElementById("previous").className = "previousBtnActive";
		
		if(Math.abs(currentPosition) + tableWidth >= chgItems.offsetWidth)
			document.getElementById("next").className = "nextBtn";
		else
			document.getElementById("next").className = "nextBtnActive";
	}
}

// 左ボタンクリック時
function previousBtn(sliderTable)
{
	// テーブルの要素を取得
	chgItems = document.getElementById(sliderTable);
	// テーブル左端の位置を取得
	var currentPosition = parseInt(getLeftPosition(sliderTable));
	
	if((currentPosition + tdWidth) <= 0 && isActive == false)
	{
		isActive = true;
		// 左に1項目分移動
		moveLeftPosition(sliderTable, tdWidth);
	}
}

// 左に1項目分移動
function moveLeftPosition(sliderTable, x)
{
	chgItems = document.getElementById(sliderTable);
	
	var currentPosition = parseInt(getLeftPosition(sliderTable));
	
	chgItems.style.left = (currentPosition + x) + "px";
	isActive = false;
	
	changeButtonClass(sliderTable);
}

// 右ボタンクリック時
function nextBtn(sliderTable)
{
	// テーブルの要素を取得
	chgitems = document.getElementById(sliderTable);
	// テーブル左端の位置を取得
	var currentPosition = parseInt(getLeftPosition(sliderTable));
	
	if(Math.abs(currentPosition - tdWidth) < chgItems.offsetWidth) {
		if(Math.abs(currentPosition - tableWidth) < chgItems.offsetWidth) {
			isActive = true;
			moveRightPosition(sliderTable, tdWidth);
		}
		else
		{
			isActive = false;
		}
	}
}

function moveRightPosition(sliderTable, x)
{
	chgItems = document.getElementById(sliderTable);
	var currentPosition = parseInt(getLeftPosition(sliderTable));
	
	chgItems.style.left = (currentPosition - x) + "px";
	isActive = false;
	
	changeButtonClass(sliderTable);
}
