﻿// JScript 文件

function setbox(){
    //this.bindbtn();
}

setbox.prototype = {
    box:null,
    btnL:null,
    btnR:null,
    width:null,
    marginleft:null,
    runtime:null,
    runcount:1,
    runitem:1,
    gorun:true,
    bindbtn:function(obj){
        //绑定按钮1
        $("#"+obj.btnR).bind("click",function(){
            if(obj.runitem*obj.runcount < $(obj.box).size()&&obj.gorun==true){
                obj.gorun=false;
                var item = 0;
                $(obj.box).each(function(index,domEle){
                    if($(domEle).css("margin-left").replace("px","") >= 0){
                        item = index;
                        return false;
                    }
                });
                for(var i=0;i<obj.runcount;i++,item++){
                    $(obj.box).eq(item).animate({marginLeft:"-"+obj.width},obj.runtime,function(){});
                }
                obj.runitem++;
                obj.gorun=true;
            }
        });
        //绑定按钮2
        $("#"+obj.btnL).bind("click",function(){
            if(obj.runitem > 1&&obj.gorun==true){
                obj.gorun=false;
                var item = 0;
                $(obj.box).each(function(index,domEle){
                    if($(domEle).css("margin-left").replace("px","") >= 0){
                        item = index;
                        return false;
                    }
                });
                for(var i=0;i<obj.runcount;i++,item--){
                    $(obj.box).eq(item-1).animate({marginLeft:obj.marginleft},obj.runtime,function(){});
                }
                obj.runitem--;
                obj.gorun=true;
            }
        });
    }
}

$(function(){
    var a = new setbox();
    a.box=$("#boxtupian li");
    a.btnL="boxtupianL";
    a.btnR="boxtupianR";
    a.width="154px";
    a.marginleft="0px";
    a.runtime=300;
    a.runcount=4;
    a.bindbtn(a);
    
    
    var b = new setbox();
    b.box=$("#gundong li");
    b.btnL="goL";
    b.btnR="goR";
    b.width="208px";
    b.marginleft="13px";
    b.runtime=300;
    b.runcount=3;
    b.bindbtn(b);
})
