/*

	P.append('图片地址','链接地址','提示文字','展示文字')		//添加图片				[参数可选]
	P.width = 图片宽度										//设置图片宽度			[可选]
	P.height = 图片高度										//设置图片高度			[可选]
	P.time = 毫秒数											//设置自动切换间隔时间		[可选]
	P.first = 由0开始的图片索引值								//设置第一个显示的图片		[可选]
	P.target = 目标字符串										//设置链接目标			[可选]
	P.title = 是否显示标题									//设置显示项				[可选]
	P.position = {x:导航起始x坐标,y:导航起始y坐标}				//设置导航位置			[可选]
	P.startup()												//设置完参数之后再启动

*/
var P = {
	width : 704,
	height : 272,
	time : 5000,
	first : 0,
	nowIndex : null,
	nextIndex : null,
	interval : null,
	data : [],
	opacity : 100,
	free : false,
	tiled : true,
	loadInterval : null,
	loadTime : 0,
	title : false,
	position : {x:5,y:5},
	space : 1,
	border : {width:1,style:'solid',color:'cdcdcd'},
	target : '_blank',
	$ : function(){return document.getElementById(arguments[0])},
	setOpacity : !-[1,]?function(id,opacity){P.$(id).style.filter="alpha(opacity="+opacity+")"}:function(id,opacity){P.$(id).style.opacity=opacity/100},
	append : function(){
		var p = [];
		for(var i=0,l=arguments.length;i<l;i++){
			p.push(arguments[i]==undefined?'':arguments[i].replace('"','\"'));
		}
		P.data.push(p);
	},
	flashOpacity : function(){
		if(P.opacity>0){
			var step = Math.ceil((100-P.opacity+1)/5);
			if(step>5)step=5;
			if(P.opacity<step)step=P.opacity;
			P.opacity -= step;
			P.setOpacity("TopImage",P.opacity);
			if(P.opacity<50)P.setOpacity("Cover",P.opacity/.625);
			setTimeout("P.flashOpacity()",10);
		}else{
			P.$("TopImage").innerHTML = P.$("BottomImage").innerHTML;
			P.opacity = 100;
			P.setOpacity("TopImage",P.opacity);
			P.setOpacity("Cover",80);
			P.nowIndex = P.nextIndex;
			P.free = true;
		}
	},
	setFlash : function(index){
		if(index==undefined){
			index = P.nowIndex+1;
		}else{
			if(P.nowIndex==index||!P.free)return;
		}
		P.nextIndex = index;
		if(P.nextIndex==P.data.length)P.nextIndex=0;
		P.$("BottomImage").innerHTML = "<a href=\""+P.data[P.nextIndex][1]+"\" title=\""+P.data[P.nextIndex][2]+"\" target=\""+P.target+"\"><img src=\""+P.data[P.nextIndex][0]+"\" border=\"0\" width=\""+P.width+"\" height=\""+P.height+"\" /></a>";
		P.free = false;
		P.autoEnd();
		P.loadTime = 0;
		P.loadInterval = setInterval('P.plusTime()',1);
		P.$("BottomImage").getElementsByTagName('img')[0].onload = function(){
			clearTimeout(P.loadInterval);
			P.$("load").style.display = '';
			if(P.title)P.$("text").innerHTML = P.data[P.nextIndex][3];
			P.setButton();
			P.flashOpacity();
			P.autoBegin();
		};
	},
	plusTime : function(){
		P.loadTime++;
		if(P.loadTime>5){
			P.$('load').style.display='block';
			clearTimeout(P.loadInterval);
		}
	},
	startup : function(){
		var topElement = document.createElement("div");
		var coverElement = topElement.cloneNode(false);
		var bottomElement = coverElement.cloneNode(false);
		var string = '';
		if(!P.data.length){
			document.write('没有任何图片可以展示！<br /><br />添加方法为：P.append(\'图片地址\',\'链接地址\',\'提示文字\',\'展示文字\')');
			return;
		}
		document.write('\
			<style type="text/css">\
				#show{height:'+(P.height+5-P.position.y)+'px}\
				#show_inner{padding:'+P.space+'px;border:'+P.border.width+'px '+P.border.style+' #'+P.border.color+';width:'+P.width+'px;overflow:hidden}\
				#show .clear{clear:both}\
				#load{position:absolute;color:#fff;display:none;background:#09c;z-index:3;font-size:12px;padding:2px 5px;margin:'+(P.height-18>>1)+'px 0 0 '+(P.width-70>>1)+'px}\
				#textbg{position:absolute;z-index:3;margin-top:'+(P.height-25)+'px;width:'+P.width+'px;background:#000;filter:alpha(opacity=40);opacity:0.4;height:25px}\
				#text{position:absolute;z-index:4;margin-top:'+(P.height-25)+'px;width:'+(P.width-20)+'px;height:19px;overflow:hidden;color:#fff;padding:0 10px;font-size:14px;text-align:left;line-height:25px}\
				#show_guide{font-size:13px;margin:'+(P.height-22-P.position.y)+'px 0 0 '+(P.position.x)+'px;line-height:20px;text-align:left;position:absolute;z-index:5}\
				#show_guide #guide_list div{display:inline;float:left;margin-right:5px;text-align:center;height:20px;cursor:pointer;border:1px solid #fff;color:#000;padding:0 8px;background:#fff}\
				#show_guide #guide_list .now{border:1px solid #f45b2f;background:#ff7d05;color:#fff;cursor:default}\
				#TopImage{position:absolute;z-index:2;width:'+P.width+'px;height:'+P.height+'px;overflow:hidden}\
				#BottomImage{width:'+P.width+'px;z-index:1;height:'+P.height+'px;overflow:hidden}\
				#Cover{position:absolute;width:'+P.width+'px;height:'+P.height+'px;background:#000;filter:alpha(opacity=0);opacity:0}\
			</style>\
		');
		document.write('<div id="show"><div id="show_inner"><div id="show_guide"><div id="guide_list"></div><div style="clear:left"></div></div><div id="load">loading...</div>'+(P.title?'<div id="textbg"></div><div id="text"></div>':'')+'</div></div>');
		P.nowIndex = P.first;
		topElement.innerHTML = "<a href=\""+P.data[P.nowIndex][1]+"\" title=\""+P.data[P.nowIndex][2]+"\" target=\""+P.target+"\"><img src=\""+P.data[P.nowIndex][0]+"\" border=\"0\" width=\""+P.width+"\" height=\""+P.height+"\" /></a>";
		if(P.title)P.$("text").innerHTML = P.data[P.nowIndex][3];
		topElement.id = "TopImage";
		coverElement.id = "Cover"
		bottomElement.id = "BottomImage";
		P.$("show_inner").appendChild(topElement);
		P.$("show_inner").appendChild(coverElement);
		P.$("show_inner").appendChild(bottomElement);
		for(var i=0,l=P.data.length;i<l;i++)string += '<div onclick="P.setFlash('+i+')">'+(i+1)+'</div>';
		P.$('guide_list').innerHTML = string;
		P.setButton(true);
		P.loadInterval = setInterval('P.plusTime()',1);
		P.$("TopImage").getElementsByTagName('img')[0].onload = function(){
			clearTimeout(P.loadInterval);
			P.$("load").style.display = '';
			if(P.data.length>1){
				P.setOpacity("Cover",80);
				P.autoBegin();
				P.free = true;
				P.$('show').onmouseover = P.autoEnd;
				P.$('show').onmouseout = P.autoBegin;
			}
		}
	},
	setButton : function(t){
		var list = P.$("guide_list").getElementsByTagName("div");
		if(t){
			list[P.nowIndex].className = "now";
		}else{
			list[P.nowIndex].className = "";
			list[P.nextIndex].className = "now";
		}
	},
	autoBegin : function(){
		if(!P.interval)P.interval = setInterval("P.setFlash()",P.time);
	},
	autoEnd : function(){
		if(P.interval){
			clearInterval(P.interval);
			P.interval=undefined;
		}
	}
}
