//焦点图轮换
(function(_scope) {
//定义初始方法
var getEl = function(a1,a2) { return a2 ? a1.getElementById(a2) : document.getElementById(a1) };
var getTag = function (a1,a2) { return a2 ? a1.getElementsByTagName(a2) : document.getElementsByTagName(a1) };
var setStyle = function ( a1,a2,a3) { a1.style[a2] = a3 };
var hiddenImg = function (ar) {
for ( var i=0; i< ar.length; i++ ) {
setStyle (ar[i],'display','none');
}
};
var hiddenClassName = function (ar) {
for ( var i=0; i< ar.length; i++ ) {
ar[i].className = '';
}
};
//定义window对象方法adShow
_scope.adShow = function(photoTab,photoShow) {
//this.box = photoBox;
this.imgAr = getTag (photoShow,'li');
this.liAr = getTag (photoTab,'li');
if ( this.imgAr.length == 0 || this.liAr.length == 0 ) return;
this.current = 0;
this.init();
};
var proto = _scope.adShow.prototype;
//adShow方法的原型方法init，初始化对象
proto.init = function() {
var _self = this;
hiddenImg (this.imgAr);
setStyle (this.imgAr[0],'display','');
this.liAr[0].className = 'selected';
this.timer = setTimeout ( function(){ _self.scrolling() },3000);
this.hoverFuc();
};
//adShow方法的原型方法scrolling，自动切换
proto.scrolling = function() {
var _self = this, f = arguments.callee;
if (this.current == 4) {
setStyle (this.imgAr[this.current],'display','none');
setStyle (this.imgAr[0],'display','');
this.liAr[this.current].className = '';
this.liAr[0].className = 'selected';
this.current = 0;
}
else {
setStyle (this.imgAr[this.current],'display','none');
setStyle (this.imgAr[this.current + 1],'display','');
this.liAr[this.current].className = '';
this.liAr[this.current + 1].className = 'selected';
this.current++;
}
this.timer = setTimeout (function(){f.call(_self)},3000);
};
//adShow方法的原型方法hoverFuc，鼠标事件
proto.hoverFuc = function () {
var _self = this;
//li滑过事件处理函数
var Func = function (n) {
this.overFunc = function(){
_self.stop();
hiddenImg (_self.imgAr);
hiddenClassName (_self.liAr);
setStyle (_self.imgAr[n],'display','');
_self.liAr[n].className = 'selected';
_self.current = n;
};
};
//li鼠标滑过事件
for ( var i = 0; i < this.liAr.length; i++ ) {
this.liAr[i].onmouseover = (new Func(i)).overFunc;
this.liAr[i].onmouseout = function() { _self.rescrolling() };
}
//img鼠标滑过事件
for ( var i = 0; i < this.imgAr.length; i++ ) {
this.imgAr[i].onmouseover = function() {  _self.stop() };
this.imgAr[i].onmouseout = function() { _self.rescrolling() };
}
};
//adShow方法的原型方法stop，停止自动切换
proto.stop = function () {
clearTimeout(this.timer);
};
//adShow方法的原型方法rescrolling，回到自动切换
proto.rescrolling = function () {
var _self = this;
if ( this.timer ) {
this.stop();
}
this.timer = setTimeout(function(){ _self.scrolling()},3000);
}
})(window);
window.onload = function () {
var photoScroll = new adShow(document.getElementById('imgtab'),document.getElementById('imgShow'));
};
