
function ImagePlayer() {
    this._playerName = null;
    this._timer = null;
    this._items = [];
    this._container = null;
    this._index = 0;
    this._imgs = [];
    this.intervalTime = 3000;//轮播间隔时间
    this._width = 0;
    this._height = 0;
    this._titleDivID = null;
    this.init = function(playerName, playerDivID, w, h, time, titleDivID) {
        this.intervalTime = time || this.intervalTime;
        this._playerName = playerName;
        this._titleDivID = titleDivID;
        this._width = w;
        this._height = h;
        this._container = document.getElementById(playerDivID);
        this._container.style.display = "block";
        this._container.style.width = w + "px";
        this._container.style.height = h + "px";
        this._container.style.position = "relative";
        this._container.style.overflow = "hidden";
        //this._container.style.border = "1px solid #fff";   
        var linkStyle = "display: block; TEXT-DECORATION: none;";
        if (document.all) {
            linkStyle += "FILTER:";
            linkStyle += "progid:DXImageTransform.Microsoft.Barn(duration=0.5, motion='out', orientation='vertical') ";
            linkStyle += "progid:DXImageTransform.Microsoft.Barn ( duration=0.5,motion='out',orientation='horizontal') ";
            linkStyle += "progid:DXImageTransform.Microsoft.Blinds ( duration=0.5,bands=10,Direction='down' )";
            linkStyle += "progid:DXImageTransform.Microsoft.CheckerBoard()";
            linkStyle += "progid:DXImageTransform.Microsoft.Fade(duration=0.5,overlap=0)";
            linkStyle += "progid:DXImageTransform.Microsoft.GradientWipe ( duration=1,gradientSize=1.0,motion='reverse' )";
            linkStyle += "progid:DXImageTransform.Microsoft.Inset ()";
            linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=PLUS,motion=out )";
            linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=PLUS,motion=in )";
            linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=DIAMOND,motion=in )";
            linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=SQUARE,motion=in )";
            linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=0.5,irisStyle=STAR,motion=in )";
            linkStyle += "progid:DXImageTransform.Microsoft.RadialWipe ( duration=0.5,wipeStyle=CLOCK )";
            linkStyle += "progid:DXImageTransform.Microsoft.RadialWipe ( duration=0.5,wipeStyle=WEDGE )";
            linkStyle += "progid:DXImageTransform.Microsoft.RandomBars ( duration=0.5,orientation=horizontal )";
            linkStyle += "progid:DXImageTransform.Microsoft.RandomBars ( duration=0.5,orientation=vertical )";
            linkStyle += "progid:DXImageTransform.Microsoft.RandomDissolve ()";
            linkStyle += "progid:DXImageTransform.Microsoft.Spiral ( duration=0.5,gridSizeX=16,gridSizeY=16 )";
            linkStyle += "progid:DXImageTransform.Microsoft.Stretch ( duration=0.5,stretchStyle=PUSH )";
            linkStyle += "progid:DXImageTransform.Microsoft.Strips ( duration=0.5,motion=rightdown )";
            linkStyle += "progid:DXImageTransform.Microsoft.Wheel ( duration=0.5,spokes=8 )";
            linkStyle += "progid:DXImageTransform.Microsoft.Zigzag ( duration=0.5,gridSizeX=4,gridSizeY=40 ); width: 100%; height: 100%";
        }
        //
        var ulStyle = "margin:0;width:" + w + "px;position:absolute;z-index:999;FILTER:Alpha(Opacity=50,FinishOpacity=50, Style=1);overflow: hidden;bottom:3px;right:3px;height:16px; border-right:1px solid #fff;";
        //   
        var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";
        //   
        var baseSpacStyle = "clear:both; display:block; width:23px;line-height:18px; font-size:12px; FONT-FAMILY:'宋体';opacity: 0.6;";
        baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;";
        baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; ";
        //   
        var ulHTML = "";
        for (var i = this._items.length - 1; i >= 0; i--) {
            var spanStyle = "";
            if (i == this._index) {
                spanStyle = baseSpacStyle + "background:#ff0000;";
            } else {
                spanStyle = baseSpacStyle + "background:#000;";
            }
            ulHTML += "<li style=\"" + liStyle + "\">";
            ulHTML += "<span onmouseover=\"imgPlayerMouseOver(this);\" onmouseout=\"imgPlayerMouseOut(this);\" style=\"" + spanStyle + "\" onclick=\"eval('" + this._playerName + ".play(" + i + ")');return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i + 1) + "</span>";
            ulHTML += "</li>";
        }
        //
        var html = "<a target=\"_blank\" href =\"" + this._items[this._index].link + "\" title=\"" + this._items[this._index].title + "\"  style=\"" + linkStyle + "\"><img style=\"border:0px;max-width:" + this._width + "px;\"/></a><ul style=\"" + ulStyle + "\">" + ulHTML + "</ul>";
        this._container.innerHTML = html;

        this.play(this._index);
    };
    this.addItem = function(_title, _link, _imgURL) {
        this._items.push({ title: _title, link: _link, img: _imgURL });
        this._imgs.push(_imgURL);
    };
    this.play = function(index) {
        if (index != null) {
            this._index = index;
            clearInterval(this._timer);
            this._timer = setInterval("eval('" + this._playerName + ".play()');", this.intervalTime);
        } else {
            this._index = this._index < this._items.length - 1 ? this._index + 1 : 0;
        }
        var link = this._container.getElementsByTagName("A")[0];
        if (link.filters) {
            var ren = Math.floor(Math.random() * (link.filters.length));
            link.filters[ren].Apply();
            link.filters[ren].play();
        }
        link.href = this._items[this._index].link;
        link.title = this._items[this._index].title;

        var img = this._container.getElementsByTagName("img")[0];
        img.src = this._items[this._index].img;
        img.alt = this._items[this._index].title;
        img.width = this._width;
        img.height = this._height;

        //   
        var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";
        var baseSpacStyle = "clear:both; display:block; width:23px;line-height:18px; font-size:12px; FONT-FAMILY:'宋体'; opacity: 0.6;";
        baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;";
        baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; ";

        var ulHTML = "";
        for (var i = this._items.length - 1; i >= 0; i--) {
            var spanStyle = "";
            if (i == this._index) {
                spanStyle = baseSpacStyle + "background:#ff0000;";
            } else {
                spanStyle = baseSpacStyle + "background:#000;";
            }
            ulHTML += "<li style=\"" + liStyle + "\">";
            ulHTML += "<span onmouseover=\"imgPlayerMouseOver(this);\" onmouseout=\"imgPlayerMouseOut(this);\" style=\"" + spanStyle + "\" onclick=\"eval('" + this._playerName + ".play(" + i + ")');return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i + 1) + "</span>";
            ulHTML += "</li>";
        }
      
        if (this._titleDivID != null) {
            var titleDiv = document.getElementById(this._titleDivID);
            if (titleDiv != null) {
                titleDiv.innerHTML = "<a target=\"_blank\" href=\"" + this._items[this._index].link + "\">" + img.alt + "</a>";
            }
        }

        this._container.getElementsByTagName("UL")[0].innerHTML = ulHTML;
    };
}

function imgPlayerMouseOver(obj) {
    var i = parseInt(obj.innerHTML);
    if (this._index != i - 1) {
        obj.style.color = "#ff0000";
    }
};
function imgPlayerMouseOut(obj) {
    obj.style.color = "#fff";
};

function imgPlayerPlay(obj) {
    obj.style.color = "#fff";
}; 
