////JS代码


function TabPager(tabs, tabtype, clients, opt){
 this.tabs = document.getElementById(tabs);
 this.tabtype = tabtype;
 this.timer = 0;
 this.a = 1;


 if(opt.autoChange){
  this.autoChange = opt.autoChange;
 }else{
  this.autoChange = false;
 }


 if(opt.imgChange){
  this.imgChange = opt.imgChange;
 }else{
  this.imgChange = false;
 }


 if(opt.arr){
  this.arr = opt.arr;
 }else{
  this.arr = null;
 }


 var that = this;
 this.enable = function (start){
  if(that.disabled && start){
   that.disabled = false;
  }
  if(!that.disabled){
   if(that.autoChange){
    that.caller(true);
   }
  }
 }


 this.disable = function (stop){
  if(that.timer){
   clearTimeout(that.timer);
   that.timer = 0;
  }


  if(stop){
   if(that.disabled){
    that.enable(true);
   }else{
    that.disabled = true;
   }
  }
 }


 this.changePage = function (){
  if(arguments.length > 0){
   that.n = arguments[0];
  }


  if(that.n < 0){
   that.n = that.total - 1;
  }else if(that.n >= that.total){
   that.n = 0;
  }


  var reg = new RegExp(that.tabtype, 'i');
  var tablist = that.tabs.getElementsByTagName(tabtype);
  var j = 0;
  for(var i = 0; i < tablist.length; i++){
   var tab = tablist[i];
   if(tab.tagName && reg.test(tab.tagName) && tab.innerHTML){
    if(j == that.n){
     tab.className = tab.className.match('hover') ? tab.className : tab.className + ' hover';
    }else{
     tab.className = tab.className.replace(/ ?hover/, '');
    }
    j++;
   }
  }


  if(that.imgChange){
   if(that.arr[that.n].map){
    that.clients.childNodes[0].useMap = that.arr[that.n].map;
    that.clients.childNodes[0].src = that.arr[that.n].img;
    that.clients.childNodes[0].alt = that.arr[that.n].alt;
   }else{
    that.clients.childNodes[0].href = that.arr[that.n].lnk;
    that.clients.childNodes[0].title = that.arr[that.n].title;
    that.clients.childNodes[0].childNodes[0].src = that.arr[that.n].img;
    that.clients.childNodes[0].childNodes[0].alt = that.arr[that.n].alt;
   }
  }
  else
  {
   j = 0;
   for(var i = 0; i < that.clients.childNodes.length; i++){
    var client = that.clients.childNodes[i];
    if(client.tagName){
     client.style.display = (j == that.n ? '' : 'none');


     var classTemp = client.className.split(' ');
     for (k = 0; k < classTemp.length; k++){
      if(m = classTemp[k].match(/^(.*)_hidden$/)){
       classTemp[k] = m[1];
      }
     }
     client.className = classTemp.join(' ');


     if(j == that.n && that.arr){
      var imgs = client.getElementsByTagName('img');


      for(var k = 0; k < imgs.length; k++){
       if(!imgs[k].src || imgs[k].src.match('space.gif')){
        imgs[k].src = that.arr[j][k];
       }
      }
     }


     j++;
    }
   }
  }
 }


 this.caller = function (){
  if(that.timer){
   clearTimeout(that.timer);
   that.timer = 0;
  }


  if(!arguments[0]){
   that.n += that.a;
   that.changePage();
  }


  that.timer = setTimeout(that.caller, 3000);
 };


 var reg = new RegExp(this.tabtype, 'i');
 var k = 0, tab, oldonmouseover = new Array;
 var tablist = this.tabs.getElementsByTagName(tabtype);
 for(var i = 0; i < tablist.length; i++){
  tab = tablist[i];
  if(tab.tagName && reg.test(tab.tagName) && tab.innerHTML){
   if(tab.onmouseover){
    oldonmouseover[i] = tab.onmouseover;
   }
   eval('tab.onmouseover = function (){' + (tab.onmouseover ? 'oldonmouseover[' + i + ']();' : '') + 'that.disable();that.changePage(' + k +  '); }');
   tab.onmouseout = this.enable;
   k++;
  }
 }


 if(opt.clientEvent)
 {
  k = 0;
  var clientslist = document.getElementById(clients).childNodes;
  for(var i = 0; i < clientslist.length; i++){
   var client = clientslist[i];
   if(client.tagName){
    if(client.onmouseover){
     oldonmouseover[i] = client.onmouseover;
    }
    eval('client.onmouseover = function (){' + (client.onmouseover ? 'oldonmouseover[' + i + ']();' : '') + 'that.disable();that.changePage(' + k +  '); }');
    client.onmouseout = this.enable;
    k++;
   }
  }
 }


 this.total = k;
 this.n = 0;


 this.clients = document.getElementById(clients);
 this.clients.onmouseover = this.disable;
 this.clients.onmouseout = this.enable;


 if(this.autoChange){
  this.caller(true);
 }
}
