function slide(container, options, callback, obj){ this.container=$(container); this.list=$(container+' .j_slide_list'); this.handle=$(container+' .j_slide_trigger li'); this.item=$(container+' .j_slide_item'); this.itemwh=0; this.count=this.handle.length; this.timer=null; this.etime=null; this.options=$.extend({ auto:true, delay:8, duration:500, effect:'slide', event:'mouseover', firstdelay:null, index:1, vertical:false },options); this.init(); if(callback){ callback.call(this, obj); } } slide.prototype={ init:function(){ var slideclip, itemw, itemh, itemwh, that=this, list=this.list, item=this.item, count=this.count, op=this.options, auto=!!op.auto, vertical=!!op.vertical; if(op.effect==='fade'){ list.css({position:'relative'}); item.css({position:'absolute'}); } if(op.effect==='slide'){ list.css({position:'absolute'}); if(!list.parent().hasclass('j_slide_clip')){ list.wrap('
'); } itemw=item.outerwidth(true); itemh=item.outerheight(true); this.container.find('.j_slide_clip').css({position:'relative',overflow:'hidden',height:itemh,width:itemw}); this.itemwh=vertical?itemh:itemw; if(!vertical){ item.css({'float':'left'}); list.width(item.width()*item.length); } } this.handle.bind(op.event, function(){that._trigger(this)}); if(op.index==='r'){ op.index=this._random(count); } if(op.index> count||op.index<1){ op.index=1; } this._showfirst(op.index); if(auto){ this._auto(op.firstdelay); this.container.hover(function(){that._stop();},function(){that._auto();}); } }, _random:function(max){ return parseint(math.random() * max + 1); }, _trigger:function(o){ var index, op=this.options, handle=this.handle; if(op.index===(handle.index(o)+1)){ return; } index=op.index=handle.index(o)+1; this._show(index); }, _show:function(i){ var that=this, op=this.options, vertical=!!op.vertical; this.handle.removeclass('cur').eq(i-1).addclass('cur'); if(op.effect==='fade'){ cleartimeout(this.etime); this.etime=settimeout(function(){that.item.not(that).css({zindex:-1}).eq(i-1).css({zindex:9}).animate({opacity:1},that.options.duration,function(){ that.item.not(this).css({opacity:0}) });},150); } if(op.effect==='slide'){ itemwh=this.itemwh; if(vertical){ this.list.stop().animate({left:-itemwh*(i-1)},this.options.duration); }else{ this.list.stop().animate({left:-itemwh*(i-1)},this.options.duration); } } }, _showfirst:function(i){ var op=this.options, vertical=!!op.vertical; this.handle.removeclass('cur').eq(i-1).addclass('cur'); if(op.effect==='fade'){ this.item.not(this).css({zindex:-1, opacity:0}).eq(i-1).css({zindex:9, opacity:1}); } if(op.effect==='slide'){ itemwh=this.itemwh; if(vertical){ this.list.css({top:-itemwh*(i-1)}); }else{ this.list.css({left:-itemwh*(i-1)}); } } }, _auto:function(delay){ var that=this, op=that.options; this.timer=settimeout(function(){ op.index = op.index< that.count? ++op.index: 1; that._show(op.index); that._auto(); }, delay ? delay*1000 : op.delay*1000); }, _stop:function(){ cleartimeout(this.timer); } };