////////////////////////////////////////////////////////////////////
// 設定
////////////////////////////////////////////////////////////////////
//
//商品データの総数
var totalNo=4;
//
//productBoxの横幅
var productBoxWidth=901;
//
//移動スピード
var moveSpeed=2000;
//
//自動的に移動させる間隔
var timerInterval=8000;//1000=1秒 
//注意：間隔が移動スピード以下になると動作しなくなります。
//
//何かボタンを押してもタイマーを継続して使用する場合は0。使用しない場合は1。
var timerType=1;
//
////////////////////////////////////////////////////////////////////
// ↑設定ここまで。以下は編集不可。

var nowNo=1;
var timerID = setTimeout("autoMove()",timerInterval);
function autoMove(){
	//キューに何も入ってない状態のとき実行
	if($('#productNaviData').queue().length==0){
		if(nowNo>=totalNo){
			nowNo=0;
		}
		var x = -1*nowNo*productBoxWidth;
		nowNo++;
		$('#productNaviData').animate({
			left: x
		}, moveSpeed, function() {
		});
		clearTimeout(timerID);
		timerID = setTimeout("autoMove()",timerInterval);
	}
}

//ナビボタンを押したときの処理
$("[rel^='productNaviGoto']").live("click",function(){
	//キューをクリア
	$('#productNaviData').clearQueue();
	var relText=$(this).attr('rel');
	var gotoNum=relText.replace(/productNaviGoto/ig, '');
	if(nowNo!=gotoNum){
		nowNo=gotoNum;
		gotoNum--;
		var x = -1*gotoNum*productBoxWidth + 'px';
		$('#productNaviData').animate({
			left: x
		}, moveSpeed, function() {
			// Animation complete.
		});
	}
	if(timerType==1){
		//タイマーをクリア
		clearTimeout(timerID);
	}else{
		//タイマーをクリアして再度セット
		clearTimeout(timerID);
		timerID = setTimeout("autoMove()",timerInterval);
	}
	return false;
});
//nextボタンを押したときの処理
$("[rel='productNaviNext']").live("click",function(){
	//キューをクリア
	$('#productNaviData').clearQueue();
	autoMove();
	if(timerType==1){
		//タイマーをクリア
		clearTimeout(timerID);
	}else{
		//タイマーをクリアして再度セット
		clearTimeout(timerID);
		timerID = setTimeout("autoMove()",timerInterval);
	}
	return false;
});
//prevボタンを押したときの処理
$("[rel='productNaviPrev']").live("click",function(){
	//キューをクリア
	$('#productNaviData').clearQueue();
	nowNo--;
	if(nowNo<=0){
		nowNo=totalNo;
	}
	var x = -1*(nowNo-1)*productBoxWidth;
	$('#productNaviData').animate({
		left: x
	}, moveSpeed, function() {
		// Animation complete.
	});
	if(timerType==1){
		//タイマーをクリア
		clearTimeout(timerID);
	}else{
		//タイマーをクリアして再度セット
		clearTimeout(timerID);
		timerID = setTimeout("autoMove()",timerInterval);
	}
	return false;
});

// yamastar productNavi.js

