﻿// JScript source code
//图片滚动展示 Start

var AdCarousel = function(){
    this.counts = 3;
    this.imgObject = [];
    this.imglist = [];
    //this.smallImgPath = '/images/icon/';
    this.nn = 0;
    this.key = 0;
    this.tt = null;
    this.instance = null;
    this.delay = 3000;  //速度
    
    //imglist = [{src:"",url:"",alt:""},{src:"",url:"",alt:""}]  
    this.init = function(imglist,w,h,delay,instanceName){
        if(imglist==null) return;
        this.counts = imglist.length;
        this.imglist = imglist;
        this.instance = instanceName;
        if(delay!=null)
        	this.delay = delay;
        for(var i=0;i<imglist.length;i++){
            this.imgObject[i] = new Image();
            this.imgObject[i].src = imglist[i].src;
        }
        document.write('<div class="picshow_main" style="width:'+w+'px;height:'+h+'px">');
        document.write('<div><a id="url"><img id="pic" class="imgbig" style="width:'+w+'px;height:'+h+'px"/></a></div>');
        //document.write('<div class="picshow_change">');
       // for ( var i = 0; i < this.counts; i++) {
       //     document.write('<a href="javascript:'+instanceName+'.click(' + i
       //             + ');" id="ad_c' + i
       //             + '" class="axx" target="_self"><img src="' + this.smallImgPath +'adb'+ (i+1)
        //            + '.gif"></a>');
       // }
        //document.write('</div></div>');
        document.write('</div>');
    }
    
    this.changeimg = function (ins){
        if (this.key == 0) {    //控制第一次不使用过渡效果
            this.key = 1;
        } else if (document.all) {
            document.getElementById("pic").filters[0].Apply();
            document.getElementById("pic").filters[0].Play(duration = 2);
        }
        document.getElementById("pic").src = ad.imgObject[ad.nn].src;
        document.getElementById("url").href=this.imglist[this.nn].url;
        document.getElementById("pic").alt=this.imglist[this.nn].alt;
        document.getElementById("url").target = "_blank"
        document.getElementById("url").style.cursor = "pointer"
       // for ( var i = 0; i < this.counts; i++) {
       //     document.getElementById("ad_c" + i).className = 'axx';
        //}
       // document.getElementById("ad_c" + this.nn).className = 'bxx';
        this.nn++;
        if (this.nn > (this.counts-1)) {
            this.nn = 0;
        }
        
    }
    
    this.play = function(){
        var _ad = eval(this.instance);
        _ad.changeimg();
        _ad.tt = window.setInterval(function(){_ad.changeimg()}, _ad.delay);
    }
    
    this.click = function(n){
        var _ad = eval(this.instance);
        window.clearInterval(_ad.tt);
        _ad.nn = n;
        _ad.changeimg();
        window.setTimeout(function(){_ad.play()},_ad.delay);
    }
    
}
