﻿// JScript 文件
/***********************************************
* by v-jianyz@microsoft.com 
2007-10-9
***********************************************/

function $(name){
            return document.getElementById(name);
        }
        
         /*
            icons 存放全局的图片对象
            current_icon_index 当前读取到图片的访问下标
            play_interval 图片切换的间隔
            trans_type trans的类型一共两种reveal 和 blend 
            tans_duration 持续间隔
            reveal_type 呈现样式 23 为随机 Random transition from above possible values.
            timer_switch 存放记时器对象
        */
        
        function imageSlide( id , alinkId )
        {
            this.imageId = id ;
            this.linkId = alinkId ;
            this.icons = new Array();
            this.currentIconIndex = 0 ;
            this.playInterval = 4000 ;
            this.transDuration = 3.000 ;
            this.revealType = 23;
            this.timerSwitch = null ;   
            this.transType = 'reveal';  
            
            //alert();     
        }
        
        imageSlide.prototype.init = function(){
            if(this.icons.length==0) return;
	        var objImg = $(this.imageId);
	        if(objImg == null) return;
	        this.setIcon(0);
	        this.setTitle(0);
	        this.setHref(0);
	        objImg.style.filter = (this.transType == 'reveal') ? 'revealTrans' : 'blendTrans';
	        objImg.style.filter.duration = this.transDuration;
	        objImg.style.filter.transition = this.revealType;
	        free(objImg);
	        //this.timerSwitch = window.setInterval(this.adRotateFade, this.playInterval);
        }
        
        //轮显函数
        imageSlide.prototype.adRotateFade = function(){
           if(this.icons.length==0) return;
           with($(this.imageId)){
		        if(this.transType == 'reveal'){
			        filters(0).transition = this.revealType;
		        }
		        if(this.currentIconIndex == (this.icons.length - 1)){
			        this.currentIconIndex = -1;
		        }
		        ++this.currentIconIndex;
 		        filters(0).apply(); 
 		        src = this.icons[this.currentIconIndex].sImgUrl;
		        filters(0).play();
		    }
		   this.setHref(this.currentIconIndex);
		    this.setTitle(this.currentIconIndex);
		    //setAdButtonStyle(current_icon_index);
        }

        imageSlide.prototype.setHref = function(iconIndex) {
            if (this.icons.length == 0) return;
            var obj = $(this.linkId);
            //if (obj == null || iconIndex > (this.icons.length - 1) || iconIndex < 0) return;
            obj.href = this.icons[iconIndex].sAHref;            
            free(obj);
        }
        
        imageSlide.prototype.setIcon = function(iconIndex){
            if(this.icons.length==0) return;
            var obj = $(this.imageId); 
            if (iconIndex < this.icons.length && iconIndex > -1){
                obj.src = this.icons[iconIndex].sImgUrl;
                obj.alt = this.icons[iconIndex].sAlt;
            }
            free(obj);                        
        }

        imageSlide.prototype.setTitle = function(iconIndex) {
            if (this.icons.length == 0) return;
            var obj = $(this.imageId + "_Title");

            if (obj != null && iconIndex < this.icons.length && iconIndex > -1) {
                obj.innerHTML = "<a href='" + this.icons[iconIndex].sAHref + "'>" + this.icons[iconIndex].sTitle + "</a>";
                
            }
            free(obj);
        }
        
        function malloc(name){
            return document.createElement(name);    
        }
        function free(obj){
            obj = null;
        }
        //icon对象
        //sImgurl 图片地址
        //sAlt 图片注解
        //sTarget 采用某种方式打开
        //sAHref 访问的网页地址
        //sTitle，图片说明
        function icon(sImgUrl, sAlt, sTarget, sAHref , title ){
	        this.sImgUrl = (sImgUrl == null || sImgUrl == '') ? '' : sImgUrl;
	        this.sAHref = (sAHref == null || sAHref == '') ? 'javascript:void(0);' : sAHref; 
	        this.sAlt = (sAlt == null || sAlt == '') ? 'image' : sAlt;
	        this.sTarget = (sTarget == null || sTarget == '') ? '_self': sTarget;
	        this.sTitle = title ;
        }