var girlshow="0>0>0>0>0>0>0>7>6>5>0>4>0>3>2>0>0>0>1>0>0>0>0>0>0";
var boyshow="0>0>0>0>0>0>0>14>13>12>0>11>0>10>9>0>0>0>8>0>0>0>0>0>0";

document.body.onload=new Function("bodyload();");

function openScript(url, width, height)
{
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=no,menubar=no,status=no' );
	//var s = new Object();
	//k =showModalDialog(url,s,"dialogWidth:"+width+"px;status:no;scroll=no;help=no;dialogHeight:"+height+"px");
}

function cameraprompt(url, width, height)
{
	ans=prompt("请输入照片主题","");
	if (ans==null) return;
	openScript(url+'&explain='+ans, width, height);
}

function presentprompt(url, width, height)
{
	ans=prompt("请输入赠送对象的用户名","");
	if (ans==null) return;
	openScript(url+'&getid='+ans, width, height);
}

function bodyload()
{
	myshow=readCookies("Show");
//	alert(myshow);
	if (myshow == undefined)
	{
		if(readCookies("sex")=="female") myshow=girlshow;
		else myshow=boyshow;
	}
	showit(myshow);
}

function init()
{
	mysex=readCookies("sex");
	if(mysex=="female") myshow=girlshow;
	else myshow=boyshow;
	showit(myshow);
}

function showit(usershow)
{
	mysex=readCookies("sex");
	showlayers=usershow.split('>');
	str="";
	for(i=0;i<showlayers.length;i++)
	{
		if (showlayers[i]==0 || showlayers[i]=='')
		{
			switch (i)
			{
				case 7 :
					if (mysex=="female") showlayers[i]=7;
					else showlayers[i]=14;
					break;
				case 8 :
					if (mysex=="female") showlayers[i]=6;
					else showlayers[i]=13;
					break;
				case 9 :
					if (mysex=="female") showlayers[i]=5;
					else showlayers[i]=12;
					break;
				case 11 :
					if (mysex=="female") showlayers[i]=4;
					else showlayers[i]=11;
					break;
				case 13 :
					if (mysex=="female") showlayers[i]=3;
					else showlayers[i]=10;
					break;
				case 14 :
					if (mysex=="female") showlayers[i]=2;
					else showlayers[i]=9;
					break;
				case 18 :
					if (mysex=="female") showlayers[i]=1;
					else showlayers[i]=8;
					break;
				default :
					break;
			}
		}
		if(showlayers[i]!='0' && showlayers[i]!='')
		{
			str+="<img src=http://qqshow-item.tencent.com/"+showlayers[i]+"/"+i+"/00/' style='padding:0;position:absolute;top:0;left:0;width:140;height:226;z-index:"+(i+1)+";'>";
		}
	}
	str+="<img src='http://game.qq.com/images/base/blank.gif' style='padding:0;position:absolute;top:0;left:0;width:140;height:226;z-index:100;'>";
	
	if(showform.usershow) showform.usershow.value=tempshow=usershow;
	setCookies(tempshow)

	bodyshow.innerHTML=str;
}


function dressit(layer,img)
{
	//readCookie()
	showlayers=tempshow.split('>');
	newshow="";
		for(i=0;i<showlayers.length;i++)
		{
			if(i==layer)
			{
				if(img!=showlayers[i]) newshow+=img;
				else newshow+="0";
			}
			else newshow+=showlayers[i];
			if(i+1!=showlayers.length) newshow+=">";
		}
	showit(newshow);
}

function testdress(layers,img,sex)
{
	if (readCookies("sex")=="female") {sex2=0;}
	else {sex2=1;}
	if (sex==sex2 || sex==2)
	{
		layer=layers.split('_');
		for(j=0;j<layer.length;j++)
		{
			dressit(layer[j],img);
		}
	}
	else
	{
		alert("对不起，性别不符，不能试穿");
	}
}

function setCookies(myshow){
    var Then = new Date()        
    Then.setTime(Then.getTime() + 60*1000 )   //60秒
    document.cookie = "Show="+myshow
}


function readCookies(cookie)
{
	var the_cookie = document.cookie;
	var broken_cookie = the_cookie.split(";");
	for(i=0;i<broken_cookie.length;i++)
	{
		var show_cookie = broken_cookie[i].split("=");
		if (show_cookie[0].indexOf("sex")==1 && cookie=="sex") {return(show_cookie[1]);}
		if (show_cookie[0]=="Show" && cookie=="Show") {return(show_cookie[1]);}
		if (show_cookie[0]=="nowshow" && cookie=="nowshow") {return(show_cookie[1]);}
	}
}

