var MaxImg2;
var NowImg2 = 1;
var begin2;
var interval2 = 4000;  /** 切换间隔 */
var hasNum2=false;  /** 是否有数字快捷切换的判断 */

function initMax2(){  /** 修正总数并触发动作 */
  for (var i=1;i<=20;i++){
    if(!document.getElementById("2pic"+i)){
      MaxImg2=i-1;
      break;
    }else{
      addMouseActions(document.getElementById("2pic"+i));
    }
  }  

  if(document.getElementById("2num1")) hasNum2=true;
  if(MaxImg2 > 0)
    playit2();  /**   第一次开始计时 */
}

function initialization2(){   /**  自动切换 */
  if(NowImg2 == MaxImg2) 
    next = 1;
  else
   next = NowImg2 + 1;

  document.getElementById("2pic" + next).style.display="";
  filterShowIt(document.getElementById("2pic" + next));
  document.getElementById("2pic" + NowImg2).style.display="none";

  if(hasNum2) {
    for (var i=1;i<=MaxImg2;i++){
       document.getElementById("2num"+i).className="link";
      if(i == next){
        document.getElementById("2num"+i).className="current";
      }
    }      
  }

  if(NowImg2 == MaxImg2) 
    NowImg2 = 1;
  else
    NowImg2++;    

  playit2();    /**  新的计时 */

}

function showit2(x){    /**   手动切换 */
  if(NowImg2==x)return;
  if(MaxImg2 > 1){
    stopit2();
    for (var i=1;i<=MaxImg2;i++){
      document.getElementById("2pic" + i).style.display="none";
      if(hasNum2)
        document.getElementById("2num"+i).className="link";
      if(i == x){
        document.getElementById("2pic" + i).style.display="block";
        if(hasNum2)
          document.getElementById("2num"+i).className="current";
        filterShowIt(document.getElementById("2pic" + i));
      }    
    }  
    NowImg2=x;
  }
}

function playit2(){  /**  重新开始自动计时 */
  if(MaxImg2 > 1){
    clearTimeout(begin2); 
    begin2 = setTimeout('initialization2()', interval2);  
  }
}

function stopit2(){   /**  停止计时 */
  if(MaxImg2 > 1)
    clearTimeout(begin2); 
}

if(document.all)
window.attachEvent('onload',initMax2);
else
window.addEventListener('load',initMax2,false);
