/*----------------------------------------------------------
*****************  伍剑 斗地主 1.0  *****************
作者：张辉
网站：http://www.wj008.net 
程序员代号：wj008
联系QQ：496865687
版权：版权全体,源代码公开,各种用途均可免费使用
**********************************************************
----------------------------------------------------------*/
function $(obj){return document.getElementById(obj)}
var OPtm=0;
var EPtm=0;
var MPtm=10;
var Images=new Array();
var ErrImg=new Array();
function preload(img,Okback,Errback)
{
	var a =new Array();
	for (var i=0; i<img.length; i++)
	{
	var src =img[i];
	a[i]=document.createElement("img");
	a[i].style.display = "none";
	document.body.appendChild(a[i])
	a[i].onload = function()
		{
		document.body.removeChild(this);
		this.onload=null;
		this.style.display = "";
		Okback();
		}
	a[i].onerror=function()
		{
		document.body.removeChild(this);
		this.onerror=null;
		this.style.display = "";
		Errback(this.src);	
		}
		a[i].src = src;
	}
}

function addImg(img)
{
	if ( img.constructor == window.Array ) 
   {
	for (var i=0; i<img.length; i++)
	Images[Images.length]=img[i];
   }
   else
   {
	Images[Images.length]=img;
   }
}
function addErrImg(img)
{
	if ( img.constructor == window.Array ) 
   {
	for (var i=0; i<img.length; i++)
	ErrImg[ErrImg.length]=img[i];
   }
   else
   {
	ErrImg[ErrImg.length]=img;
   }
}
function ImgOk()
{
	OPtm++;
	var p=parseInt((OPtm/MPtm)*100);
	$("lopc").width=p+"%";
	$("pc").innerHTML=p+"%";
	
	if(OPtm==MPtm)
	setTimeout('setOk()',500);
	if(EPtm!=0&&EPtm+OPtm==MPtm)
	setTimeout('ErrLoadImg()',2000);
}
function ImgErr(str)
{
	EPtm++;
	addErrImg(str)
	if(EPtm+OPtm==MPtm)
	setTimeout('ErrLoadImg()',2000);

}
var TimeEr=0;
function Jishi()
{
	TimeEr++;
	if(TimeEr>=61)
	{
	if(OPtm!=MPtm)
	setTimeout('setOk()',500);
	return;
	}
	
	setTimeout('Jishi()',1000);
}
function ErrLoadImg()
{
	EPtm=0;
	preload(ErrImg,ImgOk,ImgErr);
	ErrImg=[];
}

function InitGame()
{
	Jishi();
	MPtm=Images.length;
	preload(Images,ImgOk,ImgErr);
	
}
function openWin(str,w,h)
{
window.showModelessDialog(str+"?r="+ new Date().getTime()+Math.random(),"","dialogHeight:"+h+"px;dialogWidth:"+w+"px;status:0;scroll:0;");
//window.open(str,'newwindow','width='+w+',heigh='+h+',location=0,directories==0,status=0,menubar=0,scrollbars=0')
}
function setOk()
{
	parent.main.location='about:blank';
	var p=parent.document.getElementById("loading")
	p.style.display="none";
	parent.openWin('game.asp',1020,740);
}