// JavaScript Document
var isIE=!(navigator.userAgent.indexOf('MSIE')==-1);
function ImagePlayer(pic,txt,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.childrenNodes(this.div.childNodes);
	}
	else{
		nodes=this.childrenNodes(this.div.childNodes);
	}
	if(nodes.length>0){
		//nodes[nodes.lenght-1].style.display="block";
		//nodes[nodes.lenght-1].style.display="block";
	}
	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--;
	this.play();
	//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);
	}

