var isIE=!(navigator.userAgent.indexOf('MSIE')==-1);
function ImagePlayer(pic,par,addNav)
{
 this.curNew=0;
  this.timer=0;
 this.news=new Array();
 this.div=document.getElementById(pic);
 this.div.style.position="relative";
 this.div.style.zIndex=1;
 //this.text=document.getElementById(txt);
 this.parent=par;//实例名
 this.delay=3000;//延时毫秒
 this.addNav=addNav;//加BUTTON
 this.init();
}
ImagePlayer.prototype.init=function(){
 var nav=document.createElement("DIV");
 nav.className="p-Nav";
 var nodes;
 if(isIE){
  nodes=this.div.childNodes;
 }
 else{
  nodes=this.childrenNodes(this.div.childNodes);
 }
 for(var i=nodes.length-1;i>=0;i--)
 {
  var element=nodes[i];
  this.news[i]={};
  this.news[i].Element=element;
  this.news[i].Text=element.getAttribute("title");
  this.news[i].Url=element.getAttribute("href");
  var button=document.createElement("span");
  button.innerHTML="<a herf=\"javascript:;\" onmouseover=\"javascript:"+this.parent+".curNew="+(i-1)+";"+this.parent+".play();\">"+(i+1)+"</a>";
  if(i==this.curNew)button.className="Cur";
  nav.appendChild(button);
  this.news[i].LinkElement=button;
 }
 
 if(this.addNav)
 this.div.appendChild(nav);
 
 this.curNew--;
 window.setTimeout(this.parent+".play()",this.delay);
}
ImagePlayer.prototype.childrenNodes=function (node)
 {
  var c=new Array();
  for(var i=0;i<node.length;i++)
  {
   if(node[i].nodeName.toLowerCase()=="a")
    c.push(node[i]);
  }
  return c;
 }
ImagePlayer.prototype.play=function()
 {
  if(!this.div)return;
  this.curNew=this.curNew+1;
  if(this.curNew>=this.news.length)this.curNew=0;
  for(var i=0;i<this.news.length;i++)
  {
   if(i==this.curNew)
   {
    this.news[i].Element.style.display="block";
    this.news[i].Element.style.visibility="visible";
    this.news[i].LinkElement.className="Cur";
    //this.text.innerHTML="<a href=\""+this.news[i].Url+"\" title=\""+this.news[i].Text+"\" target=\"_blank\">"+this.news[i].Text+"</a>";
   }
   else
   {
    this.news[i].Element.style.visibility="hidden";
    this.news[i].Element.style.display="none";
    this.news[i].LinkElement.className="Normal";
   }
  }
  if(this.timer)window.clearTimeout(this.timer);
  this.timer=window.setTimeout(this.parent+".play()",this.delay);
 }
 
 /*示例：

<div id="fs_pic"><a href="/cat.asp?catid=1912" title="" target="_blank" style="DISPLAY: block; VISIBILITY: visible"><img src="images/0617/fs-01.jpg" width="158" height="95" border="0" /></a><a href="/cat.asp?catid=1336" title="" target="_blank" style="DISPLAY: none; VISIBILITY: hidden"><img src="/images/0617/fs-02.jpg" width="158" height="95" border="0" /></a></div>

var player_2=new ImagePlayer("fs_pic","player_2",true);*/
