﻿
//
function _getOpacity(id){
  var fadeObj=$(id);
  var fun= navigator.isIE() ? function(){ return parseInt(fadeObj.filters["alpha"].opacity); }:
                              function(opacity){ return 100 * parseFloat(fadeObj.currentStyle.opacity); };
  return fun();
}
//
function _setOpacity(id,opa){
  var fadeObj=$(id);
  var fun=navigator.isIE() ? function(opacity){ fadeObj.style.filter = "alpha(opacity:" + opacity + ")"; }:
                 function(opacity){ fadeObj.style.opacity = opacity / 100; };
  fun(opa);
}
/*
 * author chenxing 2009 06 18
 * 渐变透明类
 */
var fadeOpactity={
   start:function(id){
      var oThis=this;
      oThis._id=id;
      oThis._timer=null;
      oThis.Step=25; //步长
      oThis.max=100;
	  oThis.timeInterval=5; //时间间隔
      oThis.run();
   }
   ,run:function(){
       var oThis=this;
       clearTimeout(oThis._timer); 
       this._finish=true;
       oThis.setOpacity(); 
       if(!this._finish)
         oThis._timer=setTimeout(function(){oThis.run();},oThis.timeInterval);
   }
  ,setOpacity: function() {
    var oThis=this;
    var iGet = this.Get(_getOpacity(oThis._id));
    if(isNaN(iGet)) return true;
       _setOpacity(oThis._id,iGet);
    return false;
  }
  ,Get:function(now){
       var iStep = (this.max - now) / this.Step;
       if(iStep){		
          this._finish = false;
          if(Math.abs(iStep) < 1){ iStep = iStep > 0 ? 1 : -1; }
          return now + iStep;
       }
   }
};
/*
 * author chenxing 2009 06 18
 * 循环播放图片类
 */ 
var cycleImage=Class.create();
cycleImage.prototype={
   initialize:function(imgUrlArr,idUl,linkUrlArr){
      var oThis=this;
	  oThis._imgUrlArr=imgUrlArr;
	  oThis._linkUrlArr=linkUrlArr;
	  oThis._maxV=imgUrlArr.length-1;
	  oThis._currentV=0;
	  oThis._idUl=idUl;
	  //
	  oThis._nextPic=Bind(this,this.nextPic);  //function(){return fun.apply(object, arguments);}
	  oThis._mouseOverEvent=BindAsEventListener(this,this.mouseOverEvent); 
	  //function(event) {return fun.call(object, (event || window.event));} 写出来
	  oThis._mouseOutEvent=Bind(this,this.mouseOutEvent);
	  oThis._timeInterval=8*1000; 
	  oThis._timeout=null;//定时器
   }
   ,initLiEvent:function(){
        var oThis=this;
        var li_arr=$(oThis._idUl).getElementsByTagName("li");  
	    for(var i=0;i<li_arr.length;i++){
		 li_arr[i].setAttribute("value",i); //set value 从0开始
		 var tt=function(){
		    var obj=li_arr[i];
		    Event.observe(obj,"mouseover",oThis._mouseOverEvent);    
			Event.observe(obj,"mouseout", oThis._mouseOutEvent);    
		 }
		 tt(); //init mouseover event
	  }
	  Event.observe($("imgUrlID"),"mouseover",function(){ clearInterval(oThis._timeout);});    
	  Event.observe($("imgUrlID"),"mouseout",oThis._mouseOutEvent); 
	  $("imgUrlID").src=oThis._imgUrlArr[0];
	  if(oThis._linkUrlArr[0]!="wu"){
		  $("linkUrlID").href=oThis._linkUrlArr[0]; 
	  }else{
	     $("linkUrlID").href="#";
	  }   
	  //start setTimeout
	  fadeOpactity.start("imgUrlID"); //透变的时间一定要比切换的时间不短
	  oThis._timeout=window.setInterval(function(){oThis._nextPic();},oThis._timeInterval);
   }
   ,mouseOverEvent:function(e){
      var oThis=this;
	  e=e||window.event;
	  var curObj=e.srcElement||e.target;
	  var imgUrlNum=parseInt(curObj.getAttribute("value"));
	  if(oThis._timeout) clearInterval(oThis._timeout); //when mouseover,stop nextPic_func 
	  oThis.changleName(imgUrlNum); //
	  //
	  $("cycimg_load").style.display="block"; 
      $("cycle_img1").style.display="none"; 
	  //
	  $("imgUrlID").src=oThis._imgUrlArr[imgUrlNum];
	  if(oThis._linkUrlArr[imgUrlNum]!="wu"){
		  $("linkUrlID").href=oThis._linkUrlArr[imgUrlNum];
	  }else{
	    $("linkUrlID").href="#";
	  }
	  _setOpacity("imgUrlID",50);
	  oThis._currentV=imgUrlNum;
	  fadeOpactity.start("imgUrlID"); //原因在此
   }
   ,mouseOutEvent:function(){
      var oThis=this;
	  oThis._timeout=window.setInterval(function(){oThis._nextPic();},oThis._timeInterval);
   }
   ,nextPic:function(){
	  var oThis=this; //一定要考虑this可能不是cycleImage.prototype
	  var num=oThis._currentV;
      num=(num<oThis._maxV)?++num:0;
	  oThis._currentV=num;
	  oThis.changleName(num); //
	  //
	  $("cycimg_load").style.display="block"; 
      $("cycle_img1").style.display="none"; 
	  //
	  
      $("imgUrlID").src=oThis._imgUrlArr[num];
	  if(oThis._linkUrlArr[num]!="wu"){
		  $("linkUrlID").href=oThis._linkUrlArr[num]; 
	  }else{
	    $("linkUrlID").href="javascript:void(0)";
	  }
	  _setOpacity("imgUrlID",50);
	  fadeOpactity.start("imgUrlID");
   }
   ,changleName:function(num){
       var li_arr=$("cycle_pager_ul").getElementsByTagName("li");
	   for(var i=0;i<li_arr.length;i++){
	        if(i!=num)
		      li_arr[i].className="pager_li";
			else{
			  li_arr[i].className="pager_li_over";
			}
	   }
   }
}
function loadCycleImg(){
  $("cycimg_load").style.display="none"; 
  $("cycle_img1").style.display="block"; 
}
/*
var imgUrlArr=["images/1.jpg","images/2.jpg","images/3.jpg","images/4.jpg","images/4.jpg"];
var linkUrlArr=["http://www.google.cn","http://www.baidu.com","wu","wu","wu"];
Event.observe(window,"load",function(){ 
  var obj=new cycleImage(imgUrlArr,"cycle_pager_ul",linkUrlArr);
  obj.initLiEvent();
});*/



