// JavaScript Document
var	tm=null;
var	distance=0;
var speedtime=4;
var move_status=1;
var autoTime=4000;

function button_position(){
	//next and prev 
	$id("prev").style.left=getX($id("scrollimg"))-30+"px";
	$id("prev").style.top=getY($id("scrollimg"))+"px";
	$id("next").style.left=getX($id("scrollimg"))+815+"px";
	$id("next").style.top=getY($id("scrollimg"))+"px"; 
}

function nextScroll(){
	speed=Math.ceil((($id("scrollimg").clientWidth/(2*picNUM))-distance)/speedtime);
	if($id("scrollimg").parentNode.scrollLeft<($id("scrollimg").clientWidth/2)){		
		//div width<9 时 $id("scrollimg").parentNode.scrollLeft 永远小于  $id("scrollimg").clientWidth/2
        $id("scrollimg").parentNode.scrollLeft=$id("scrollimg").parentNode.scrollLeft+speed;  
	}else {  
		$id("scrollimg").parentNode.scrollLeft=0+speed;	
	}  
	distance=distance+speed;	
	if(speed<=0){
		move_status=1;
		clearInterval(tm);	
		clearTimeout(auto);
		auto=setTimeout('next()',autoTime); 
	}
	
}

function prevScroll(){
	speed=Math.ceil((($id("scrollimg").clientWidth/(2*picNUM))-distance)/speedtime);
	if($id("scrollimg").parentNode.scrollLeft>0){
		$id("scrollimg").parentNode.scrollLeft=$id("scrollimg").parentNode.scrollLeft-speed;    
	}else {  
		$id("scrollimg").parentNode.scrollLeft=$id("scrollimg").clientWidth/2-speed;
	}  
	distance=distance+speed;
	if(speed<=0){
		move_status=1;
		clearInterval(tm);	
		clearTimeout(auto);
		auto=setTimeout('prev()',autoTime); 
	}
}

function movePic()   {   
	$id("simg1").innerHTML=$id("simg").innerHTML; 	
	button_position();	 
	$id("next").style.display="block";
	$id("prev").style.display="block";
	auto=setTimeout('next()',autoTime); 
}  

function  next()   
{   
    if(move_status==1){
		distance=0;
		move_status=0;
		tm=setInterval('nextScroll()',20); 		
	}
}  

function  prev()   
{   
	if(move_status==1){
		distance=0;
		move_status=0;
		tm=setInterval('prevScroll()',20); 		
	}
}  

if(window.attachEvent){
	 window.attachEvent("onload",   movePic);
	 window.attachEvent("onresize",   button_position);
}else if(window.addEventListener){
	 window.addEventListener('load',   movePic,  false);
	 window.addEventListener('resize',   button_position,  false);
}