﻿//这是一个动态显示图片新闻的脚本
//调用代码样例：
//var imgabc;
//var imageRepeatMethod = 'imgabc.nextImage()';
//function doabc(){
//    debugger;
//    var imgNews = new Array();
//    var imgLinks = new Array();
//    imgNews[0] = "Images/Category/200619hyq.gif";
//    imgLinks[0] = "abc.asp";
//    imgNews[1] = "Images/Category/200619yousheng.gif";
//    imgLinks[1] = "def.asp";
//    
//    imgabc = new ImageTransition(imgNews,imgLinks,'imageNewrotator');
//}

//HTML代码样例：
//<body onload="doabc()">
//<a onmouseover="imgabc.displayStatusMsg();return document.returnValue" href="javascript:imgabc.jump2url()" target="_self">
//<img style="filter: revealTrans(duration=2,transition=20)" src="javascript:imgabc.nextImage('imageNewRotator')"
//    id=" imageNewRotator" name="imageNewRotator" vspace="1" hspace="1">
//</a>
//</body>

//最近修改时间:2006.9,zouyong
//images为图片新闻的数组，imgLinks为每张图片的链接地址,imgRotator为显示图片的控件ID
function ImageTransition(images,imgLinks,imgTexts,imgRotator,imgTextPanel){
    this.images = images;
    this.imgLinks = imgLinks;
    this.imgTexts = imgTexts;
    this.imgRotator = document.getElementById(imgRotator);
    this.imgTextPanel = document.getElementById(imgTextPanel);

    this.imgIndex = 0;

    this.preLoadedImages = new Array();
    for (i = 0; i < this.images.length; i++){
        this.preLoadedImages[i] = new Image();
        this.preLoadedImages[i].src = this.images[i];
    }
    this.nextImage();
}
    //程序入口
ImageTransition.prototype.nextImage = function(){
    if(this.imgIndex < this.images.length-1){
        this.imgIndex++;
    }
    else{
        this.imgIndex = 0;
    }
    this.setTransition();
    this.imgRotator.src = this.images[this.imgIndex];
    this.playTransition();
    theTimer = setTimeout(imageRepeatMethod, 4000);
}

//设置变换效果
ImageTransition.prototype.setTransition = function(){
    if (document.all){
        this.imgRotator.filters.revealTrans.Transition = Math.floor(Math.random()*23);
        this.imgRotator.filters.revealTrans.apply();
    }
}
//播放效果
ImageTransition.prototype.playTransition = function(){
    if (document.all){
        this.imgRotator.filters.revealTrans.play();
        this.imgTextPanel.innerHTML = imgTexts[this.imgIndex];
    }
}

//跳转到指定的URL
ImageTransition.prototype.jump2url = function(){
    jumpUrl = this.imgLinks[this.imgIndex];
    jumpTarget = '_blank';
    if (jumpUrl != ''){
        if (jumpTarget != ''){
            window.open(jumpUrl,jumpTarget);
        }
        else{
            location.href = jumpUrl;
        }
    }
}
//显示状态信息
ImageTransition.prototype.displayStatusMsg = function() { 
    status = this.imgLinks[this.imgIndex];
    document.returnValue = true;
}