﻿
//每次滚动宽度
var step=100;
//移动延迟时间,数字越大，移动越慢
var delayTime=40;
//移动延迟id
var moveInterval;
//自动播放器延迟
var autoPlayDelayTime=3000
//自动播放延迟id
var autoPlayInterval;
//容器id
var container=document.getElementById('img_x3_container');
//滚动目标
var scrollTarget=document.getElementById('scroll_container');
//目的坐标
var coordinate=0;
var tempCoordinate=0;
//目的坐标
var selectedNum=0;
//总图片数
var count=scrollTarget.getElementsByTagName('td').length;
//需要显示的最少图片数
var showCount=Math.floor(container.offsetWidth/scrollTarget.getElementsByTagName('td')[1].offsetWidth);

	function nextPic(){
		if(count>showCount){
			selectedNum=++selectedNum>=(count-showCount)?1:selectedNum;
			calculatCoordinate();
		}
	}

	function prevPic(){
		if(count>showCount){
			selectedNum=--selectedNum==0?(count-showCount):selectedNum;
			calculatCoordinate();
		}
	}

	function calculatCoordinate(){
		coordinate=-selectedNum*step;
		clearInterval(moveInterval)
		moveInterval=setInterval('gogogo()',delayTime)
	}

	function gogogo(){
		var diff=(coordinate-tempCoordinate)/2;

		if(Math.abs(diff)>0.5){
			tempCoordinate+=diff;
			}else{
				tempCoordinate=coordinate;
				clearInterval(moveInterval)
			}

		scrollTarget.style.left=tempCoordinate;
	}
	
	function startAutoPlay(){
		//kkk.value='开始自动播放'
		clearInterval(autoPlayInterval);
		autoPlayInterval=setInterval('nextPic()',autoPlayDelayTime)
	}

	function stopAutoPlay(){
		//kkk.value='停止播放'
		clearInterval(autoPlayInterval)
	}

	startAutoPlay();

