var ybvvjdt = function (id) { return "string" == typeof id ? document.getelementbyid(id) : id; }; var class = { create: function() { return function() { this.initialize.apply(this, arguments); } } } object.extend = function(destination, source) { for (var property in source) { destination[property] = source[property]; } return destination; } var transformview = class.create(); transformview.prototype = { initialize: function(container, slider, parameter, count, options) { if(parameter <= 0 || count <= 0) return; var ocontainer = ybvvjdt(container), oslider = ybvvjdt(slider), othis = this; this.index = 0; this._timer = null; this._slider = oslider; this._parameter = parameter; this._count = count || 0; this._target = 0; this.setoptions(options); this.up = !!this.options.up; this.step = math.abs(this.options.step); this.time = math.abs(this.options.time); this.auto = !!this.options.auto; this.pause = math.abs(this.options.pause); this.onstart = this.options.onstart; this.onfinish = this.options.onfinish; ocontainer.style.overflow = "hidden"; ocontainer.style.position = "relative"; oslider.style.position = "absolute"; oslider.style.top = oslider.style.left = 0; }, setoptions: function(options) { this.options = { up: true, step: 5, time: 10, auto: true, pause: 200, onstart: function(){}, onfinish: function(){} }; object.extend(this.options, options || {}); }, start: function() { if(this.index < 0){ this.index = this._count - 1; } else if (this.index >= this._count){ this.index = 0; } this._target = -1 * this._parameter * this.index; this.onstart(); this.move(); }, move: function() { cleartimeout(this._timer); var othis = this, style = this.up ? "top" : "left", inow = parseint(this._slider.style[style]) || 0, istep = this.getstep(this._target, inow); if (istep != 0) { this._slider.style[style] = (inow + istep) + "px"; this._timer = settimeout(function(){ othis.move(); }, this.time); } else { this._slider.style[style] = this._target + "px"; this.onfinish(); if (this.auto) { this._timer = settimeout(function(){ othis.index++; othis.start(); }, this.pause); } } }, getstep: function(itarget, inow) { var istep = (itarget - inow) / this.step; if (istep == 0) return 0; if (math.abs(istep) < 1) return (istep > 0 ? 1 : -1); return istep; }, stop: function(itarget, inow) { cleartimeout(this._timer); this._slider.style[this.up ? "top" : "left"] = this._target + "px"; } }; function each(list, fun){ for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); } }; function mytv(aa,bb,cc,dd,ee,ff,gg,hh,ii,jj){ var objs = ybvvjdt(aa).getelementsbytagname("li"); var tv = new transformview(bb,cc,dd,ee, { onstart : function(){ each(objs, function(o, i){ o.classname = tv.index == i ? "on" : ""; }) }//��ť��ʽ }); each(objs, function(o, i){ function autoplay(){ //tv.index = i; tv.up = ff; tv.pause = gg; tv.step = hh; if(ii==true){ tv.auto=true; tv.start();} else{ tv.auto = false; tv.start(); } } autoplay(); if(jj=="onmouseover"){ o.onmouseover = function(){ o.classname = "on"; tv.index = i; ii=false; autoplay(); } o.onmouseout = function(){ o.classname = ""; ii=true; autoplay(); } } if(jj=="onclick"){ o.onclick = function(){ o.classname = "on"; tv.index = i; autoplay(); } } }) }