//滚动动画js
function gundong(DivId,fangxiang){
    this.left=$("#"+DivId+" .left").eq(0);//
    this.right=$("#"+DivId+" .right").eq(0);//
	this.UlObj=$("#"+DivId+" .list dl").eq(0);//ul对象
	this.LiObj=$("#"+DivId+" .list dl dd");//li对象
	this.liNum=this.LiObj.length;//li个数
	this.liWidth=this.LiObj.eq(0).outerWidth(true);//li宽度
    this.ulWidth=this.liWidth*this.liNum;//ul宽度
    this.tempLeft=0;//临时距左边的值
	this.timeer='';//定时器
	this.speed=5000;//动画执行速度，越小越快
    this.fangxiang=fangxiang?fangxiang:'left';//默认左滚动
    this.index=0;
}
//初始化
gundong.prototype.Init=function(){
    //执行条件
    if(this.liNum<4){
        return;
    }
    this.UlObj.width(this.ulWidth);//2倍内容，2倍原来宽
    //this.tempHtml=this.UlObj.html();//ul中的li内容
    //this.UlObj.append(this.tempHtml);//插入ul中内容
    this.setEvent();//设置事件
    this.play();//
}

gundong.prototype.setEvent=function(){
    var theObj=this;
    theObj.UlObj.hover(function(){
        clearInterval(theObj.timeer);
    },function(){
        theObj.play();
    })
    theObj.left.click(function(){
        clearInterval(theObj.timeer);
        theObj.fangxiang='left';
        theObj.showOne();
        theObj.play();
    })
    theObj.right.click(function(){
        clearInterval(theObj.timeer);
        theObj.fangxiang='right';
        theObj.showOne();
        theObj.play();
    })
}
gundong.prototype.play=function() {
    var theObj=this;
    theObj.timeer=setInterval(function(){
        theObj.showOne();
    },theObj.speed);
}
gundong.prototype.showOne=function() {
    var theObj=this;
    if(theObj.fangxiang=='left') {
        theObj.index--;
        if (theObj.index <0) {
            theObj.index=theObj.liNum-4;
        }
        theObj.UlObj.stop(1,1).animate({"margin-left":  -theObj.index*theObj.liWidth + "px"},300);

    }else{
        theObj.index++;
        if (theObj.index >theObj.liNum-4) {
            theObj.index=0;
        }
        theObj.UlObj.stop(1,1).animate({"margin-left":  -theObj.index*theObj.liWidth + "px"},300);
    }
}
