function GetAvatarInit(items, headnum)
// ¾Æ¹ÙÅ¸ÀÇ ÃÊ±â ¼³Á¤
{
	if(headnum==null) headnum=1;
	var a = items.split(",");
	var wears = new Array(LAYER_NUM + 1);
	for(var i=0;i<a.length;i++)
	{
		if(a[i] == "") continue;
		DressOne(a[i],wears,headnum);
	}
	var objItem;
	var itemNum = new Object;
	document.write("<div style='width:130;height:150;' align='left' valign='top'>");
	for(i=1;i<=LAYER_NUM;i++)
	{
		if(wears[i])
		{
			objItem = new Item(wears[i], headnum);
/*			if(objItem.itemType == 'HEA' || objItem.itemType == 'COL' || objItem.itemType == 'ALL')
			{

				file = objItem.makeCode();
				t = file.split(".");
				if(headnum != 1 && headnum!="")
				{
					file = t[0] + "_" + headnum + "." + t[1];
				}

				document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+file+"\" width=\"130\" height=\"150\" >" +
					   "</div>");
			}
			else
			{

			document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>");
			}
*/
			document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>");

		}
	}
	document.write("<div style='position:absolute;z-index:200;width:130;height:150;cursor:hand;background-color:#fcf9f9;filter:progid:DXImageTransform.Microsoft.Alpha( style=1,opacity=0,finishOpacity=0,startX=0,finishX=0,startY=0,finishY=0);' onMouseOver='this.filters.item(0).opacity=40;' onMouseOut='this.filters.item(0).opacity=0' onclick=\"ShowAvatarPopMenu('"+items+"');return false;\" onContextMenu=\"ShowAvatarPopMenu('"+items+"');return false;\"></div>");
	document.write("</div>");
}

function RtnAvatarInit(items, headnum)
// ¾Æ¹ÙÅ¸ÀÇ ÃÊ±â ¼³Á¤
{
	var avatar_str="";
	if(headnum==null) headnum=1;
	var a = items.split(",");
	var wears = new Array(LAYER_NUM + 1);
	for(var i=0;i<a.length;i++)
	{
		if(a[i] == "") continue;
		DressOne(a[i],wears,headnum);
	}
	var objItem;
	var itemNum = new Object;
	avatar_str +="<div style='width:130;height:150;' align='left' valign='top'>";
	for(i=1;i<=LAYER_NUM;i++)
	{
		if(wears[i])
		{
			objItem = new Item(wears[i], headnum);
/*			if(objItem.itemType == 'HEA' || objItem.itemType == 'COL' || objItem.itemType == 'ALL')
			{

				file = objItem.makeCode();
				t = file.split(".");
				if(headnum != 1 && headnum!="")
				{
					file = t[0] + "_" + headnum + "." + t[1];
				}

				document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+file+"\" width=\"130\" height=\"150\" >" +
					   "</div>");
			}
			else
			{

			document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>");
			}
*/
			avatar_str +="<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>";

		}
	}
	avatar_str +="<div style='position:absolute;z-index:200;width:130;height:150;cursor:hand;background-color:#fcf9f9;filter:progid:DXImageTransform.Microsoft.Alpha( style=1,opacity=0,finishOpacity=0,startX=0,finishX=0,startY=0,finishY=0);' onMouseOver='this.filters.item(0).opacity=40;' onMouseOut='this.filters.item(0).opacity=0' onclick=\"ShowAvatarPopMenu('"+items+"');return false;\" onContextMenu=\"ShowAvatarPopMenu('"+items+"');return false;\"></div>";

	avatar_str +="</div>";
	return avatar_str;
}
var oAvatarPopMenu = window.createPopup();

function ShowAvatarPopMenu(items)
{
	var oPopupBody = oAvatarPopMenu.document.body;
	var oPopup_srcElement = event.srcElement;

	oPopupBody.innerHTML = MakeAvatarPopMenu(items);
	oAvatarPopMenu.show(0, 0, 0, 0, 0);

	var realWidth = oPopupBody.scrollWidth;
	var realHeight = oPopupBody.scrollHeight;
	var posX = event.offsetX;
	var posY = event.offsetY;//realHeight*-1;
	oAvatarPopMenu.hide();
	oAvatarPopMenu.show(posX, posY, realWidth, realHeight, oPopup_srcElement);

}

function MakeAvatarPopMenu(items)
{
	var rtnHtml = "";
	rtnHtml += "<menu style='width:130;margin:0;font-size:9pt;border-color:#e7c1c1;border-width:1 1 1 5;border-style:solid;background-color:#fcf9f9;'>";
	rtnHtml += "	<li style='padding:5 3 0 5;cursor:hand;' onMouseOver=\"this.style.backgroundColor='#fae6e6';\" onMouseOut=\"this.style.backgroundColor='#fcf9f9'\" onclick=\"parent.ShowAvatarWearItems('"+items+"');return false;\">Âø¿ë¾ÆÀÌÅÛº¸±â";
	rtnHtml += "	<li style='padding:5 3 2 5;cursor:hand;' onMouseOver=\"this.style.backgroundColor='#fae6e6';\" onMouseOut=\"this.style.backgroundColor='#fcf9f9'\" onclick=\"parent.ShowAvatarWearItemsBuy('"+items+"');return false;\">Âø¿ë¾ÆÀÌÅÛ±¸¸ÅÇÏ±â";
	rtnHtml += "</menu>";

	return rtnHtml;

}

function ShowAvatarWearItems(items)
{
	var winHandle = window.open('/avatar/avatar_wear_items.htm?items='+items, '', 'width=400, height=400, top=100 ,left=100, scrollbars=yes,status=yes');

	winHandle.focus();

}

function ShowAvatarWearItemsBuy(items)
{
	var winHandle = window.open('/avatar/avatar_wear_items_buy.htm?items='+items, '', 'width=600, height=500, top=100 ,left=100, scrollbars=yes,status=yes');

	winHandle.focus();

}

//===============================================================================================================//
//================================¾Æ¹ÙÅ¸ Ç¥Á¤ ¹Ù²Ù±â ½ÃÀÛ======================================================//


var cur_items = "";
var cur_facetype = "";
function GetAvatarInit_new(items, headnum)
// ¾Æ¹ÙÅ¸ÀÇ ÃÊ±â ¼³Á¤
{

	var avatar_str="";
	cur_items = items;
	cur_facetype = headnum;

	if(headnum==null) headnum=1;
	var a = items.split(",");
	var wears = new Array(LAYER_NUM + 1);
	for(var i=0;i<a.length;i++)
	{
		if(a[i] == "") continue;
		DressOne(a[i],wears,headnum);
	}
	var objItem;
	var itemNum = new Object;
	avatar_str +="<div style='width:130;height:150;' align='left' valign='top'>";
	for(i=1;i<=LAYER_NUM;i++)
	{
		if(wears[i])
		{
			objItem = new Item(wears[i], headnum);
/*			if(objItem.itemType == 'HEA' || objItem.itemType == 'COL' || objItem.itemType == 'ALL')
			{

				file = objItem.makeCode();
				t = file.split(".");
				if(headnum != 1 && headnum!="")
				{
					file = t[0] + "_" + headnum + "." + t[1];
				}

				document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+file+"\" width=\"130\" height=\"150\" >" +
					   "</div>");
			}
			else
			{

			document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>");
			}
*/
			avatar_str +="<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;cursor:hand;\" onclick=\"chg_facetype()\" onContextMenu=\"chg_facetype();return false;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>";

		}
	}
	avatar_str +="</div>";
	//avatar_str +="<div id='FaceUserInfo' style='position:absolute; left:130px; top:120px; visibility:hidden;'>»ç¿ëÀÚÁ¤º¸</div>";
	avatar_str +="<iframe name='dummy' src='about:blank'  style='display:none'></iframe>";

	return avatar_str;

}
function facetypeString()
{
	var retval;
	

	retval = "<table width=100 border=1 cellspacing=0 cellpadding=0  bordercolorlight=#CEE085 bordercolordark=#CEE085 bgcolor=#CEE085>";
	retval+= "<tr><td style=\"CURSOR:hand\">";
	retval+= "<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor='#CEE085' style=\"CURSOR:hand\">";
	retval+= "<tr><td ><img src='/images/avata/bg_layertop.gif' border='0'></td></tr>";
	retval+= "<tr><td width='66' height='22' class='green01' style='padding-left:8px;cursor:hand' bgcolor='#F9FBB4' onclick='funcChgFace();'>Ç¥Á¤¹Ù²Ù±â</td></tr>";
	retval+= "<tr><td height='1'></td></tr>";
	retval+= "<tr><td><div id='head_list' style='position:absolute; display:none;'></div></td></tr>";
	retval+= "<tr><td height='22' class='green01' style='padding-left:8px;cursor:hand' bgcolor='#F9FBB4' onclick='goMychest();'>¿ÊÀå°¡±â</td></tr>";
	retval+= "<tr><td height='1'></td></tr>";
	retval+= "<tr><td height='22' class='green01' style='padding-left:8px;cursor:hand' bgcolor='#F9FBB4' onclick='goAvatarShop();'>¼îÇÎÇÏ±â</td></tr>";
	retval+= "</table>";
	retval+= "</td></tr>";
	retval+= "</table>";
	return retval;
}

function goAvatarShop()
{
	location.href='/myavatar/niceshop_avatar.php';

}

function goMychest()
{
	location.href='/myavatar/mychest.php';
}

function chg_facetype()
{
	show_div = 1;
	tgObj = document.all.RoomUserInfo;
	tgObj.innerHTML = facetypeString();
	tgObj.style.top = event.y + document.body.scrollTop - 5;
	tgObj.style.left = event.x + document.body.scrollLeft + 10;
	tgObj.style.visibility = 'visible';
}


function headtype(head_list)
{
	var tmp_str="";
	tmp_str += "<table width=90 border=1 cellspacing=0 cellpadding=0  bordercolorlight=#BABABA bordercolordark=#F3F3F3 bgcolor=E8E9C1>";
	arr_list = head_list.split("|");
	for(i=0 ; i<arr_list.length ;  i++)
	{
		a = i+1;
		tmp_str +="<tr><td onclick='select_face("+a+")' class='green01' style='padding-left:7; height=20; color:7E7E7E;' onMouseOver='this.style.backgroundColor=\"#DDF0DA\"' onMouseOut='this.style.backgroundColor=\"\"'>"+arr_list[i]+"</td></tr>";

	}

	tmp_str += "</table>";

	show_div = 1;
	document.all.head_list.innerHTML=tmp_str;
	document.all.head_list.style.display = 'inline';
	document.all.RoomUserInfo.style.visibility = 'visible';

}

function select_face(facetype)
{
	if(cur_facetype != facetype)
	{
		dummy.location.href='/avatar/facetypechange.php?facetype='+facetype;
	}
}

function funcChgFace()
{
	if(	head_list.style.display == "none")
	{
		dummy.location.href='/avatar/headtype.php?items='+cur_items;
		//head_list.style.display = "inline";

	}else {
		head_list.style.display = "none";
		document.all.RoomUserInfo.style.visibility = 'visible';
	}


}

function faceChange(facetype)
{
	document.all.avatar_display.innerHTML = GetAvatarInit_new(cur_items,facetype);

	if( document.all.FaceType != null)
	{
		document.all.FaceType.value = facetype;
	}
}


//================================¾Æ¹ÙÅ¸ Ç¥Á¤ ¹Ù²Ù±â ³¡======================================================//
//===============================================================================================================//





function GetAvatarInitforIntroduce(items, headnum)
// ¾Æ¹ÙÅ¸ÀÇ ÃÊ±â ¼³Á¤
{
	if(headnum==null) headnum=1;
	var a = items.split(",");
	var wears = new Array(LAYER_NUM + 1);
	for(var i=0;i<a.length;i++)
	{
		if(a[i] == "") continue;
		DressOne(a[i],wears,headnum);
	}
	var objItem;
	var itemNum = new Object;
	var returnval;
	returnval= "<div style='width:130;height:150;' align='left' valign='top'>";
	for(i=1;i<=LAYER_NUM;i++)
	{
		if(wears[i])
		{
			objItem = new Item(wears[i], headnum);
/*			if(objItem.itemType == 'HEA' || objItem.itemType == 'COL' || objItem.itemType == 'ALL')
			{

				file = objItem.makeCode();
				t = file.split(".");
				if(headnum != 1 && headnum!="")
				{
					file = t[0] + "_" + headnum + "." + t[1];
				}

				document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+file+"\" width=\"130\" height=\"150\" >" +
					   "</div>");
			}
			else
			{

			document.write("<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>");
			}
*/
			returnval+="<div style=\"position:absolute;zindex:" + i + ";width:130;height:150;\">" +
					   "<img src=\""+objItem.makeCode()+"\" width=\"130\" height=\"150\">" +
					   "</div>";

		}
	}
	returnval+="</div>";
	return returnval;
}

function DressOne(itemcode,wears)	// ¿ÊÀ» ÇÑ°³ ÀÔÀ»¶§ »ç¿ë
{
	var objItem;
	objItem = new Item(itemcode);
	var delLayers = oRemoveLayerOfEachItem[objItem.itemType];	// ·¹ÀÌ¾î ¼³Á¤À» °¡Á®¿Â´Ù.
	var i;

	if(itemcode == wears[objItem.itemLayer]) //ÇöÀç ÀÔ°í ÀÖ´Â ¾ÆÀÌÅÛÀÌ¶ó¸é
	{
		if(objItem.itemType == "HAI" || objItem.itemType == "HEA") return; // ¸Ó¸®ÀÏ °æ¿ì ¹þ±âÁö ¾Ê´Â´Ù.
		for(i=0;i<delLayers.length;i++)
		{
			RemoveOne(wears[Math.abs(delLayers[i])],wears); // ÇØ´ç À§Ä¡ÀÇ ·¹ÀÌ¾î¸¦ Áö¿î´Ù.
		}
	}
	else
	{
		for(i=0;i<delLayers.length;i++)
		{
			if(delLayers[i] > 0)
			{
//				wears[Math.abs(delLayers[i])] = objItem.makeCode();
				wears[Math.abs(delLayers[i])] = itemcode;
			}
			else
			{
				wears[Math.abs(delLayers[i])] = "";
			}
		}
	}
}

function RemoveOne(itemcode,wears)	// ¾ÆÀÌÅÛ¿¡ °ü·ÃµÈ ·¹ÀÌ¾î¸¦ »èÁ¦ÇÑ´Ù.
{
	if(itemcode == "") return;

	var objItem;
	objItem = new Item(itemcode);
	var delLayers = oRemoveLayerOfEachItem[objItem.itemType];	// ·¹ÀÌ¾î ¼³Á¤À» °¡Á®¿Â´Ù.
	var i;

	for(i=0;i<delLayers.length;i++)
	{

		wears[Math.abs(delLayers[i])] = "";
	}
}