// JavaScript Document
var Sys = (function(ua){
var s = {};
s.IE = ua.match(/msie ([\d.]+)/)?true:false;
s.Firefox = ua.match(/firefox\/([\d.]+)/)?true:false;
s.Chrome = ua.match(/chrome\/([\d.]+)/)?true:false;
s.IE6 = (s.IE&&([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6))?true:false;
s.IE7 = (s.IE&&([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 7))?true:false;
s.IE8 = (s.IE&&([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 8))?true:false;
return s;
})(navigator.userAgent.toLowerCase());
var $_$ = function(id){
return document.getElementById(id);
};
var $$_$ = function(o,e){
return o.getElementsByTagName(e);
};
function Class(properties){
var _class = function(){return (arguments[0] !== null && this.initialize && typeof(this.initialize) == 'function') ? this.initialize.apply(this, arguments) : this;};
_class.prototype = properties;
return _class;
};
var Bind = function(object, fun) {
var args = Array.prototype.slice.call(arguments).slice(2);
return function() {
return fun.apply(object, args);
}
};
var Extend = function(destination, source){
for (var property in source) {
destination[property] = source[property];
}
};
var CurrentStyle = function(element){
return element.currentStyle || document.defaultView.getComputedStyle(element, null);
};
function Each(list, fun){
for (var i = 0, len = list.length; i < len; i++) {fun(list[i], i); }
};
var TweenMove = new Class({
options : {
t : 0, //t,b,c,d,都是缓动的参数
b : 0,
c : 0,
d : 0,
timer : null,
Tween : function(t,b,c,d){return -c * ((t=t/d-1)*t*t*t - 1) + b;}, //缓动公式
howgo : function(){this._obj.style.left = Math.round(this.Tween(this.t,this.b,this.c,this.d)) + "px"}, //哪些属性来执行缓动公式
Onstart : function(){},
Onmove : function(){},
Onend : function(){}
},
initialize : function(obj,options){
this._obj = obj;
var o ={};
Extend(o,this.options);
Extend(o,options||{});
Extend(this,o);
},
Start : function(){
this.Onstart();
this.Move();
},
Move : function(){
this.howgo();
this.Onmove();
if(this.t<this.d)
{this.t++;this.timer=setTimeout(Bind(this,this.Move),1)}
else
{this.t=0;this.Onend();}
},
Clear : function(){
clearTimeout(this.timer);
}
});
var gliding = new Class({
options : {
type : 1, //1表示是横着的 0表示是束者着的
direction : -1, //-1表示象上或者向左
num : 3, //多少个变化的元素
step : 0, //叫做步长吧 就是图片的宽度或者是高度
Time : 3000, //间隔
Onstart : function(){}
},
initialize : function(container,block,config,options){
this.container = container; //最外层容器
this.count = 1; //记录在第几个变化的图片上
this.timer = null; //是停顿多长时间换下张图片的定时器
var o ={};
Extend(o,this.options);
Extend(o,options||{});
Extend(this,o);
var _self = this;
Extend(config,{howgo:function(){
this._obj.style[_self.type?"left":"top"] = Math.round(this.Tween(this.t,this.b,this.c,this.d)) + "px";
},Onend:function(){
_self.count++;
if(_self.count == _self.num) _self.count = 0;
_self.Set();
},Onstart: function(){
_self.Onstart();
}});
this.Tweenmove = new TweenMove(block,config);
this.Tweenmove.Start();
},
Set : function(arg){
this.Tweenmove.Clear();
clearTimeout(this.timer); //清除2个定时器 一个是记录图片运动的(上面那个) 一个是控制多长时间后进行下次运动
this.Tweenmove.t = 0;
this.Tweenmove.b = parseInt(CurrentStyle(this.Tweenmove._obj)[this.type ? 'left' : 'top'])||0;
this.Tweenmove.c = this.count*this.step*this.direction - this.Tweenmove.b;
var _self = this;
arg = arg?0:this.Time; //如果是事件触发就直接执行;
this.timer = setTimeout(Bind(this.Tweenmove,this.Tweenmove.Start),arg);
}
});
