var NowFrame = 0;
var arrPhoto = [];
var pIndex = 0;
var countLoaded = 0;
var divSlide;
SLIDE_TIME = 5000;

addLoadEvent(loadPhotoSlide);

//加载图片
function loadPhotoSlide(){
	var objImg;
	var i;
	if(!document.getElementById) return;
	divSlide = document.getElementById("PhotoSlide");
	if(divSlide){
		divSlide.innerHTML = '<span>Loading...</span>';
		//加载
		//debugger;
		for(i=0;i<arrPhoto.length;i++){
			var objImg = document.createElement("img");//new Image();
			objImg.src = arrPhoto[i][0];
			objImg.style.display = 'none';
			if(isIE&&!isIE5){
				//objImg.onload = Function("countLoaded++;putImageToDiv(this);");
				//objImg.onreadystatechange = Function("putImageToDiv(this)");//Function("countLoaded++;putImageToDiv(this);");
				putImageToDiv(objImg);
			}
			else{
				divSlide.appendChild(objImg);
			}
		}
		if(!isIE||isIE5){
			//去掉文字层，随机显示一张图片
			divSlide.removeChild(divSlide.getElementsByTagName("span")[0]);
			if(arrPhoto.length > 0){
				divSlide.getElementsByTagName("img")[Math.round(Math.random() * arrPhoto.length) - 1].style.display = '';
			}
		}
	}
}

//将加载完毕的图片放入指定位置
function putImageToDiv(objImg){
	//判断是否已经加载完毕
	//if(objImg.readyState=="complete"){
		countLoaded++;
		divSlide.appendChild(objImg);
	//}
	//如果全部加载完毕
	if(countLoaded==arrPhoto.length){
		//去掉文字层，开始显示
		divSlide.removeChild(divSlide.getElementsByTagName("span")[0]);
		if(countLoaded > 0){
			divSlide.getElementsByTagName("img")[0].style.display = '';
		}
		slidePhotoShow();
	}
}

function slidePhotoShow(){
	var objImgs;
	var i;
	try{
		objImgs = divSlide.getElementsByTagName("img");
		if(objImgs.length==0){ return; }
		NowFrame = NowFrame % (objImgs.length);
		divSlide.filters[0].Apply();
		for(i=0;i<objImgs.length;i++){
			objImgs[i].style.display = ((i==NowFrame)?'':'none');
		}
		divSlide.filters[0].Play(duration=2);
		NowFrame++;
		setTimeout('slidePhotoShow()',SLIDE_TIME);
	}
	catch(e){
		//
	}
}