var SliderDoctor = function($target, $targetA)
{
	
	var num = $('#doctorThumb a').size();
	var thumbW = $('#doctorThumb a').width() + 20;
	var margin = 16;
	var count = 0;
	var flag = true;
	var flagAuto = true;
	var speed = 600;
	var ary = new Array();
	
	for(var i = 0;i < 4;i++){
		if(i != 0){
			$('#doctorThumb a:eq(' + i + ')').css('left',(i * (thumbW + margin)) + 'px');
		}
		else{
			$('#doctorThumb a:eq(' + i + ')').css('left',(i * thumbW) + 'px');
		}
	}
	
	if(num > 4){
		$('#doctorThumb a:last').css('left','-' + (thumbW + margin) + 'px');
	}
	else if(num <= 3){
		count = 1;
		$('.doctorBox .btnNext').hide();
		$('.doctorBox .btnBack').hide();
	}
	else{
		count = 1;
	}
	
	$('.doctorBox .btnNext').click(function(){
		if(flag){
			flagAuto = false;
			telop('next');
		}
		return false;
	});
	
	$('.doctorBox .btnBack').click(function(){
		if(flag){
			flagAuto = false;
			telop('back');
		}
		return false;
	});
	
	setInterval(function(){
		if(num > 3){
			if(flag && flagAuto){
				telop('timer');
			}
			else{
				flagAuto = true;
			}
		}
	},5000);
	
	function telop(btn){
		if(btn == 'next' || btn == 'timer'){
			flag = false;
			if(count == (num - 4)){
				ary.splice(0,4,count+1,count+2,count+3);
			}
			else if(count == (num - 3)){
				ary.splice(0,4,count+1,count+2,0);
			}
			else if(count == (num - 2)){
				ary.splice(0,4,count+1,0,1);
			}
			else if(count == (num - 1)){
				ary.splice(0,4,0,1,2);
			}
			else{
				ary.splice(0,4,count+1,count+2,count+3);
			}
			for(var i = 0;i < 4;i++){
				if(i == 3){
					$('#doctorThumb a').eq(count).animate({'left': '-=' + (thumbW + margin) + 'px'},speed,'easeInOutCubic');
				}
				else{
					$('#doctorThumb a').eq(ary[i]).animate({'left': '-=' + (thumbW + margin) + 'px'},speed,'easeInOutCubic');
				}
			}
			setTimeout(function(){
				$('#doctorThumb a').eq(count - 1).css('left',(thumbW + margin) * 3 + 'px');
				if(count == (num - 1)){
					count = 0;
				}
				else{
					count++;
				}
				flag = true;
			},(speed + 100));
		}
		else if(btn == 'back'){
			flag = false;
			if(count == 0){
				$('#doctorThumb a').eq(num - 2).css('left','-' + (thumbW + margin) + 'px');
				ary.splice(0,4,count-1,count+1,count+2);
			}
			else if(count == (num - 1)){
				$('#doctorThumb a').eq(num - 3).css('left','-' + (thumbW + margin) + 'px');
				ary.splice(0,4,count-1,0,1);
			}
			else if(count == (num - 2)){
				$('#doctorThumb a').eq(num - 4).css('left','-' + (thumbW + margin) + 'px');
				ary.splice(0,4,count-1,count+1,0);
			}
			else if(count == (num - 3)){
				$('#doctorThumb a').eq(num - 5).css('left','-' + (thumbW + margin) + 'px');
				ary.splice(0,4,count-1,count+1,count+2);
			}
			else{
				$('#doctorThumb a').eq(count - 2).css('left','-' + (thumbW + margin) + 'px');
				ary.splice(0,4,count-1,count+1,count+2);
			}
			for(var i = 0;i < 4;i++){
				if(i == 3){
					$('#doctorThumb a').eq(count).animate({'left': '+=' + (thumbW + margin) + 'px'},speed,'easeInOutCubic');
				}
				else{
					$('#doctorThumb a').eq(ary[i]).animate({'left': '+=' + (thumbW + margin) + 'px'},speed,'easeInOutCubic');
				}
			}
			setTimeout(function(){
				if(count == 0){
					count = num - 1;
				}
				else{
					count--;
				}
				flag = true;
			},(speed + 100));
		}
	}
	
	/*
	var $view = $target;
	var $viewA = $targetA;
	var $active = $($viewA).first();
	var total = $($viewA).length;
	var maxNUM = total - 3;
	var margin = 16;
	var thmubW = 192 + margin;
	var totalW = thmubW * total;
	$($view).css("width", totalW + "px");
	
	//サムネイルの初期化
	$($viewA).first().addClass("active");
	$($viewA).css("float", "left");
	$($viewA).css("margin-right", margin);
	
	// ループスタート
	var aspect = 'right';
	var numCurrent = 1;
	var numNext;
	
	//アニメーションのループ
	this.move = function()
	{
		play = setInterval(function(){
			translate();
			rotate();
		}, 5000);
	};
	
	//移動時のサムネイル表示設定とメインの移動値設定
	rotate = function()
	{
		var triggerID = $active.attr("rel") - 1;
		
		$($viewA).removeClass('active');
		$active.addClass('active');
		
		//サムネイルの移動
		var thumbPosX = triggerID * thmubW;
		$($view).animate({ 
			left: -thumbPosX
		}, 700, "easeOutCubic" );
	}; 

	
	//アニメーション時の移動について設定
	translate = function()
	{
		var currentID = $($viewA).filter(".active").attr("rel");
		
		if (aspect == 'right')
		{
			if (currentID < maxNUM)
			{
				$active = $($viewA).filter(".active").next();
			}
			else
			{
				aspect = 'left';
				$active = $($viewA).filter(".active").prev();
			}
		}
		else
		{
			if (currentID > 1)
			{
				$active = $($viewA).filter(".active").prev();
			}
			else
			{
				aspect = 'right';
				$active = $($viewA).filter(".active").next();
			}
		}
	};
	
	//Next移動ボタンクリック時
	$(".doctorBox .btnNext").click(function() {
		var currentID = $($viewA).filter(".active").attr("rel");
		
		if (currentID < maxNUM)
		{
			$active = $($viewA).filter(".active").next();
		}
		else
		{
			$active = $($viewA).first();
		}
		
		rotate();
		return false;
	});
	
	//Back移動ボタンクリック時
	$(".doctorBox .btnBack").click(function() {
		var currentID = $($viewA).filter(".active").attr("rel");
		
		if (currentID > 1)
		{
			$active = $($viewA).filter(".active").prev();
		}
		else
		{
			$active = $($viewA + ":nth-child(" + maxNUM + ")");
		}
		
		rotate();
		return false;
	});
	*/

}
