/**************************************************   
名称: 图片轮播类   
示例:   
        页面中已经存在名为imgPlayer(或者别的ID也行)的节点.   
        advPImgPlayer.addItem( "test", "url", "pic");   
        advPImgPlayer.addItem( "test2", "url", "pic");   
        advPImgPlayer.addItem( "test3", "url", "pic");   
        advPImgPlayer.init( "imgPlayer", 200, 230 );   
备注:   
        适用于一个页面只有一个图片轮播的地方.   
***************************************************/   
var advPImgPlayer = {   
        _timer : null,   
        _items : [],   
        _container : null,   
        _index : 0,   
        _imgs : [],   
        intervalTime : 3500,        //轮播间隔时间   
        init : function( objID, w, h, time ){   
                this.intervalTime = time || this.intervalTime;   
                this._container = document.getElementById( objID );   
                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 = "0px solid #fff"; 
				this._container.style.zIndex="1";
                var linkStyle = "display: block; TEXT-DECORATION: none;";   
                if( document.all ){   
                        linkStyle += "FILTER:"; 
                        linkStyle += "progid:DXImageTransform.Microsoft.Fade(duration=0.5,overlap=0); width: 100%; height: 100%";     
                }   
                //   
                var ulStyle = "margin-bottom:20px;width:"+w+"px;position:absolute;z-index:99;right:40px;FILTER:Alpha(Opacity=50,FinishOpacity=60, Style=1);overflow: hidden;bottom:-1px;height:18px;line-height:16px; border-right:1px solid #D5D5D5;";   
                //   
                var liStyle = "list-style-type: none; margin:0;padding:0; float:right;";   
                //   
                var baseSpacStyle = "clear:both; display:block; width:23px; font-size:12px; FONT-FAMILY:'Arial';opacity: 0.6;";   
                baseSpacStyle += "border:1px solid #D5D5D5;border-right: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:#990000;";   
                        } else {                                   
                                spanStyle = baseSpacStyle + "background:#000;";   
                        }   
                        ulHTML += "<li style=\""+liStyle+"\">";   
                        ulHTML += "<span onmouseover=\"advPImgPlayer.mouseOver(this);\" onmouseout=\"advPImgPlayer.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"advPImgPlayer.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";   
                        ulHTML += "</li>";   
                }   
                //   
                var html = "<a href=\""+this._items[this._index].link+"\" title=\""+this._items[this._index].title+"\" target=\"_self\" style=\""+linkStyle+"\"></a><ul style=\""+ulStyle+"\">"+ulHTML+"</ul>";   
                this._container.innerHTML = html;   
                var link = this._container.getElementsByTagName("A")[0];           
                link.style.width = w + "px";   
                link.style.height = h + "px";   
                link.style.background = 'url(' + this._items[0].img + ') no-repeat center center';   
                //   
                this._timer = setInterval( "advPImgPlayer.play()", this.intervalTime );   
        },   
        addItem : function( _title, _link, _imgURL ){   
                this._items.push ( {title:_title, link:_link, img:_imgURL } );   
                var img = new Image();   
                img.src = _imgURL;   
                this._imgs.push( img );   
        },   
        play : function( index ){   
                if( index!=null ){   
                        this._index = index;   
                        clearInterval( this._timer );   
                        this._timer = setInterval( "advPImgPlayer.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;   
                link.style.background = 'url(' + this._items[this._index].img + ') no-repeat center center';   
                //   
                var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";   
                var baseSpacStyle = "clear:both; display:block; width:23px; font-size:12px; FONT-FAMILY:'Arial'; opacity: 0.6;";   
                baseSpacStyle += "border:1px solid #D5D5D5;border-right: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:#990000;";   
                        } else {                                   
                                spanStyle = baseSpacStyle + "background:#000;";   
                        }   
                        ulHTML += "<li style=\""+liStyle+"\">";   
                        ulHTML += "<span onmouseover=\"advPImgPlayer.mouseOver(this);\" onmouseout=\"advPImgPlayer.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"advPImgPlayer.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";   
                        ulHTML += "</li>";   
                }   
                this._container.getElementsByTagName("UL")[0].innerHTML = ulHTML;           
        },   
        mouseOver : function(obj){   
                var i = parseInt( obj.innerHTML );   
                if( this._index!=i-1){   
                        obj.style.color = "#FFFFFF";   
                }   
        },   
        mouseOut : function(obj){   
                obj.style.color = "#fff";   
        }   
}   
