<!-- Begin to hide script contents from old browsers.
var AVT_URL = "http://md5.enppy.com/avt";
var AVT_ACC_URL = "http://md5.enppy.com/avt/accss";
var AVT_PATHBKG1 = "";
var AVT_PATHBKG2 = "";
var AVT_PATHACC1 = "";
var AVT_PATHACC2 = "";
var AVT_b1_PTTNUM = [3,2]; // hair = 3, clothes = 2
var AVT_b1_ZIDX = ["000000000000","000000000000","111100111111","110100101111","000000000011","000000000011"];
var AVT_b2_PTTNUM = [3,3]; // hair = 3, clothes = 3
var AVT_b2_ZIDX = ["000000000000","000001000000","000000000000","000100000000","000101000000","000000000000","111110111110","111101100000","000000000000"]; 
					//AA, AB, AC, BA, BB, BC, CA, CB, CC
var AVT_NULLIMG = "http://md.enppy.com.com/x.gif";
var AVT_PANGIMG = "http://md5.enppy.com/zpublic/trans/pang.gif"

function av_avatar()
{
	this.m_pause = 300;
	this.m_timer = null;
	
	this.m_style = "new";
	this.m_type	= "";
	this.m_gender = "";
	this.m_head	= "";
	
	this.m_hair	= "";
	this.m_hdepth = "";
	this.m_hiid	= "";
	this.m_hpattern = "";
	
	this.m_clothes = "";
	this.m_cdepth = "";
	this.m_ciid	= "";
	this.m_cpattern = "";
	
	this.m_accessory = "";
	this.m_accssdepth = "";
	
	//this.m_fixcode= "";
	this.m_face	= "";
	this.m_pungflag = false;

	this.m_layername = "";

	//by bogus
	this.m_layername_face = "";
	this.m_sfaceimg = "";	
	this.m_imgobj4 = new Array();
	this.m_imgobj5 = new Array();
	this.m_imgfaceobj = new Array(5);
	for (i = 0; i <= 5; i++) this.m_imgfaceobj[i] = null;

	this.m_imgobj4[0] = null;
	this.m_imgobj4[1] = null;
	this.m_imgobj5[0] = null;
	this.m_imgobj5[1] = null;
	this.m_imgpang = null;
	this.m_imgnull = null;
	
	// accessory
	for (i = 1; i <= 10; i++) eval("this.m_imgacc" + i + " = null");

	this.m_zidx = new Array();
	this.m_zidx[0] = "0";
	this.m_zidx[1] = "0";
	
	this.m_imghair = new Array();
	this.m_imgclothes = new Array();
	this.m_imghead = new Array();
	
	this.m_imghair[0] = new Image();
	this.m_imghair[1] = new Image();
	this.m_imgclothes[0] = new Image();
	this.m_imgclothes[1] = new Image();
	this.m_imghead[0] = new Image();
	this.m_imghead[1] = new Image();
	
	this.m_animate = true;
	this.m_self = "";

	this.m_recentype = "";
	this.m_recentcpattern = "A";
	this.m_recentclothes = "001";
	this.m_initclothes = "001";
	this.m_inithair = "001";
	this.m_recenthpattern = "A";
	this.m_recenthair = "001";

	this.m_initaccessory = "";

	//private
	this.chgavatar 	= av_chgavatar;
	this.animate	= av_animate;
	this.chkpattern	= av_chkpattern;
	this.setHC		= av_setHC;
	this.stop		= av_stop;
	this.chgproperty= av_chgproperty;
	this.random		= av_random;
	this.animold	= av_animateold;
	this.animnew	= av_animatenew;

	this.showimage = av_showimage;

	this.chgaccessory = av_chgaccessory;
	this.chgaccessory_depth = av_chgaccessory_depth;
	// by jolly
	this.animateext	= av_animateext;
	this.hideimage	= av_hideimage;
	
	//public
	this.init	= av_init;
	this.normal = av_normal;
	this.angry 	= av_angry;
	this.cry 	= av_cry;
	this.smile 	= av_smile;
	this.weird 	= av_weird;
	this.chilly = av_chilly;
	this.chgface= av_chgface;

	this.chghead= av_chghead;
	this.chghead_init= av_chghead_init;
	
	this.chgaccessory_init = av_chgaccessory_init;
	this.try_on	= av_try_on;

	this.chgall = av_chgall;
	this.buyall = av_buyall;
	this.giftall = av_giftall;
	this.rsvall = av_rsvall;
	
	this.put_on = av_put_on;
	this.put_hair = av_put_hair;
	this.try_hair = av_try_hair;

	this.put_accessory = av_put_accessory;
	this.try_accessory = av_try_accessory;
	this.getfilename = av_getfilename;
}

function av_normal()
{
	this.chgproperty("face", "11");
	this.chgavatar();
}

function av_angry()
{
	this.chgproperty("face", "21");
	this.chgavatar();
}

function av_cry()
{
	this.chgproperty("face", "31");
	this.chgavatar();
}

function av_smile()
{
	this.chgproperty("face", "41");
	this.chgavatar();
}

function av_weird()
{
	this.chgproperty("face", "51");
	this.chgavatar();
}

function av_chilly()
{
	this.chgproperty("face", "61");
	this.chgavatar();
}

function av_chgface(rtn_url)
{
	var submit_url = "http://my.enppy.com/common/chgface_exec.asp?face=" + this.m_face + "&nurl=" + rtn_url; 
	self.document.location = submit_url;
}

//clothes => pattern + old clothes
function av_put_on(clothes, ciid, cdepth)
{
	var str = "";
	var action = "";
	var type = ciid.substring(1,2);
	if (this.m_type != type)
		action = "this.chgavatar(1);";
	else
		action = "this.chgavatar();";

	if (this.m_recentype != "b"){	//´ëÇ¥Ä³¸¯ÅÍ°¡ Áß¼ºÀÏ¶§´Â Çì¾î´Â ¹«Á¶°Ç 001ÀÌ´Ù
		this.m_recenthpattern = "A";
		this.m_recenthair = "001";
	}

	if (this.m_type == "b"){
		this.m_recenthpattern = this.m_hpattern;
		this.m_recenthair = this.m_hair;
		this.m_recentcpattern = this.m_cpattern;
		this.m_recentclothes = this.m_clothes;
	}
	
	if (type != "b"){
		if (clothes.charCodeAt(0) >= 65 && clothes.charCodeAt(0) <= 90)
			str = clothes.substr(1);
		this.chgproperty('hair',str);  //Áß¼º¿¡ ´ëÇØ¼­´Â ¸ðµç ÀÇ»óÀº Çì¾î¿Í °°Àº iid¸¦ ¾´´Ù
		this.chgproperty('hpattern','A');
		this.chgproperty('hiid', '');	//Âø¿ë»óÇ° ±¸ÀÔ¿¡ Çì¾î°¡ Á¸ÀçÄ¡ ¾Ê´Ù´Â°É Ç¥½Ã
	}
	else{
		if (this.m_type != "b"){
			this.chgproperty('hair', this.m_recenthair);
			this.chgproperty('hpattern', this.m_recenthpattern);
		}
	}

	this.chgproperty('type',type);
	if (this.m_style == "old"){
		if (clothes.charCodeAt(0) >= 65 && clothes.charCodeAt(0) <= 90)
			clothes = clothes.substr(1);
		this.chgproperty('clothes',clothes);
	}
	else if (this.m_style == "new"){
		this.chgproperty('cpattern',clothes.substr(0,1));
		this.chgproperty('clothes',clothes.substr(1));
	}
	else return;
	this.chgproperty('cdepth',cdepth);
	this.chgproperty('ciid',ciid);
	if (type != "b")
		this.chghead(clothes.substr(1));
	else{
		if( this.m_type == type)
			this.chghead(this.m_recenthair);
	}
	eval(action);
}

function av_try_on(clothes, ciid)
{
	var action = "";
	var str = "";
	var type = ciid.substring(1,2);
	if (this.m_type != type)
		action = "this.chgavatar(1);";
	else
		action = "this.chgavatar();";

	if (this.m_type == "b"){
		this.m_recenthpattern = this.m_hpattern;
		this.m_recenthair = this.m_hair;
		this.m_recentcpattern = this.m_cpattern;
		this.m_recentclothes = this.m_clothes;
	}
	
	if (type != "b"){
		if (clothes.charCodeAt(0) >= 65 && clothes.charCodeAt(0) <= 90)
			str = clothes.substr(1);
		this.chgproperty('hair',str);  //Áß¼º¿¡ ´ëÇØ¼­´Â ¸ðµç ÀÇ»óÀº Çì¾î¿Í °°Àº iid¸¦ ¾´´Ù
		this.chgproperty('hpattern','A');
		this.chgproperty('hiid', '');	//Âø¿ë»óÇ° ±¸ÀÔ¿¡ Çì¾î°¡ Á¸ÀçÄ¡ ¾Ê´Ù´Â°É Ç¥½Ã
	}
	else{ 
		if (this.m_type != "b"){
			this.chgproperty('hair', this.m_recenthair);
			this.chgproperty('hpattern', this.m_recenthpattern);
		}
	}
	this.chgproperty('type',type);
	if (this.m_style == "old"){
		if (clothes.charCodeAt(0) >= 65 && clothes.charCodeAt(0) <= 90)
			str = clothes.substr(1);
		this.chgproperty('clothes',str);
	}
	else if (this.m_style == "new"){
		this.chgproperty('cpattern',clothes.substr(0,1));
		this.chgproperty('clothes',clothes.substr(1));
	}
	//this.chgproperty('cdepth',cdepth);
	this.chgproperty('ciid',ciid);
	if (type != "b")
		this.chghead(clothes.substr(1));
	else{
		if( this.m_type == type)
			this.chghead(this.m_recenthair);
	}
	eval(action);
}

function av_put_hair(hair, hiid, hdepth)
{
	var action = "";
	if (this.m_type != "b"){
		action = "this.chgavatar(1);";
		this.chgproperty('type','b');	//Áß¼º¿¡ ´ëÇÑ ±âº» Ä³¸¯ÅÍ
		this.chgproperty('clothes','000');	//Áß¼º¿¡ ´ëÇÑ ±âº» ÀÇ»ó
		this.chgproperty('ciid', '');	//Âø¿ë»óÇ° ±¸ÀÔ¿¡ ÀÇ»ó°¡ Á¸ÀçÄ¡ ¾Ê´Ù´Â°É Ç¥½Ã
	}
	else
		action = "this.chgavatar();";

	if (this.m_style == "old"){
		if (hair.charCodeAt(0) >= 65 && hair.charCodeAt(0) <= 90)
			hair = hair.substr(1);
		this.chgproperty('hair',hair);
	}
	else if (this.m_style == "new"){
		this.chgproperty('hpattern',hair.substr(0,1));
		this.chgproperty('hair',hair.substr(1));
	}
	
	this.chgproperty('hdepth',hdepth);
	this.chgproperty('hiid',hiid);
	this.chghead(hair.substr(1));
	eval(action);
}

function av_put_accessory(aiid,adepth)
{
	var accstr = aiid.substr(1);
	this.chgaccessory_depth(accstr,adepth);
}

function av_try_hair(hair, hiid)
{
	var action = "";
	if (this.m_type != "b"){
		action = "this.chgavatar(1);";
		this.chgproperty('type','b');	//Áß¼º¿¡ ´ëÇÑ ±âº» Ä³¸¯ÅÍ
		this.chgproperty('clothes','000');	//Áß¼º¿¡ ´ëÇÑ ±âº» ÀÇ»ó
		this.chgproperty('ciid', '');	//Âø¿ë»óÇ° ±¸ÀÔ¿¡ ÀÇ»ó°¡ Á¸ÀçÄ¡ ¾Ê´Ù´Â°É Ç¥½Ã
	}
	else
		action = "this.chgavatar();";

	if (this.m_style == "old"){
		if (hair.charCodeAt(0) >= 65 && hair.charCodeAt(0) <= 90)
			hair = hair.substr(1);
		this.chgproperty('hair',hair);
	}
	else if (this.m_style == "new"){
		this.chgproperty('hpattern',hair.substr(0,1));
		this.chgproperty('hair',hair.substr(1));
	}
	
	this.chgproperty('hiid',hiid);
	this.chghead(hair.substr(1));
	eval(action);
}


function av_try_accessory(aiid)
{
	var accstr = aiid.substr(1);
	this.chgaccessory(accstr);
}


function av_chgall(rtn_url)
{
	if((this.m_hiid == '' || this.m_hair == this.m_inithair) && (this.m_ciid == '' || this.m_clothes == this.m_initclothes) && this.m_initaccessory.indexOf(this.m_accessory) >= 0)
		alert("Çì¾î³ª ÀÇ»ó ¾Ç¼¼»ç¸®¸¦ ¸ÕÀú ¼±ÅÃÇÏ¼¼¿ä");
	else{
		var submit_url = "http://my.enppy.com/common/chgall_exec.asp?hdepth=" + this.m_hdepth + "&hiid=" + this.m_hiid + "&hptrn=" + this.m_hpattern + "&try_type=" + this.m_type + this.m_gender + "&cdepth=" + this.m_cdepth + "&ciid=" + this.m_ciid + "&cptrn=" + this.m_cpattern + "&accss=" + this.m_accessory + "&nurl=" + rtn_url;
		self.document.location.href = submit_url;
	}
}

function av_buyall()
{
	if(this.m_hiid == '' && this.m_ciid == '' && this.m_initaccessory.indexOf(this.m_accessory) >= 0)
		alert("Çì¾î³ª ÀÇ»ó ¾Ç¼¼»ç¸®¸¦ ¸ÕÀú ¼±ÅÃÇÏ¼¼¿ä");
	else{
		if (this.m_accessory == '') var thisaccessory = "";
		else var thisaccessory = "_" + this.m_accessory;

		var thisfile = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hpattern + this.m_hair + "_" + this.m_cpattern + this.m_clothes + thisaccessory
		var submit_url = "http://mall.enppy.com/common/all/all_buy_view.asp?thisfile=" + thisfile;
		ap_openwin(submit_url,'mallpopup',400,440,3,false,true,false);
	}
}

function av_giftall()
{
	if(this.m_hiid == '' && this.m_ciid == '' && this.m_initaccessory.indexOf(this.m_accessory) >= 0)
		alert("Çì¾î³ª ÀÇ»ó ¾Ç¼¼»ç¸®¸¦ ¸ÕÀú ¼±ÅÃÇÏ¼¼¿ä");
	else{
		if (this.m_accessory == '') var thisaccessory = "";
		else var thisaccessory = "_" + this.m_accessory;

		var thisfile = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hpattern + this.m_hair + "_" + this.m_cpattern + this.m_clothes + thisaccessory
		var submit_url = "http://mall.enppy.com/common/all/all_gift_view.asp?thisfile=" + thisfile;
		ap_openwin(submit_url,'mallpopup',400,440,3,false,true,false);
	}
}


function av_rsvall()
{
	if(this.m_hiid == '' && this.m_ciid == '' && this.m_accessory == '')
		alert("Çì¾î³ª ÀÇ»ó ¾Ç¼¼»ç¸®¸¦ ¸ÕÀú ¼±ÅÃÇÏ¼¼¿ä");
	else{
		if (this.m_accessory == '') var thisaccessory = "";
		else var thisaccessory = "_" + this.m_accessory;
		var thisfile = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hpattern + this.m_hair + "_" + this.m_cpattern + this.m_clothes + thisaccessory;
		var submit_url = "http://mall.enppy.com/common/all/all_rsv_view.asp?thisfile=" + thisfile;
		ap_openwin(submit_url,'mallpopup',400,440,3,false,true,false);
	}
}


function av_random(n)
{
	return (Math.floor(Math.random()*100000) % n);
}

function av_chgproperty(member, value)
{
	eval("this.m_" + member + " = '" + value + "';");
}

function av_chgavatar(mode)
{
	readycount = 0;
	var action;

	av_showimage( this.m_imgobj4[0], false );
	av_showimage( this.m_imgobj4[1], false );
	av_showimage( this.m_imgobj5[0], false );
	av_showimage( this.m_imgobj5[1], false );
	
	//else return;

	if (mode == 1)
		action = "this.animate(1);";
	else
		action = "this.animate();";

	this.chkpattern();
	this.setHC();

	this.stop();
	eval(action);
}



// accessory ----------------------------------------------------------

function av_chgaccessory(accstr)
{
	if (accstr != '' && accstr != null) {
		var thisaccary = this.m_accessory.split("_");
		var accurl = AVT_ACC_URL + "/" + accstr.substr(0,2) + "/" + accstr.substr(2,1) + "/C" + accstr + ".gif";
		eval("this.m_imgacc" + accstr.substr(0,2)*1 + ".src = accurl;");
	
		for(var i=0; i < thisaccary.length; i++) {
			if(accstr.substr(0,2) == thisaccary[i].substr(0,2) && accstr == thisaccary[i]){
				this.m_accessory = eval("this.m_accessory.replace(/" + thisaccary[i] + "_/g, '')");
				this.m_accessory = eval("this.m_accessory.replace(/_" + thisaccary[i] + "/g, '')");
				this.m_accessory = eval("this.m_accessory.replace(/" + thisaccary[i] + "/g, '')");
				eval("this.m_imgacc" + accstr.substr(0,2)*1 + ".src = AVT_NULLIMG ");
				break;
			}
			else if(accstr.substr(0,2) == thisaccary[i].substr(0,2) && accstr != thisaccary[i]){
				this.m_accessory = eval("this.m_accessory.replace(/" + thisaccary[i] + "/g, '" + accstr + "')");
				break;
			}
		}

		if (i == thisaccary.length && this.m_accessory == '') this.m_accessory = accstr;
		else if(i == thisaccary.length && this.m_accessory != '') this.m_accessory = this.m_accessory + "_" + accstr;
	}
}

function av_chgaccessory_depth(accstr,adepth)
{
	if (accstr != '' && accstr != null) {
		var thisaccary = this.m_accessory.split("_");
		var accurl = AVT_ACC_URL + "/" + accstr.substr(0,2) + "/" + accstr.substr(2,1) + "/C" + accstr + ".gif";
		eval("this.m_imgacc" + accstr.substr(0,2)*1 + ".src = accurl;");
	
		for(var i=0; i < thisaccary.length; i++) {
			if(accstr.substr(0,2) == thisaccary[i].substr(0,2)){
				this.m_accessory = eval("this.m_accessory.replace(/" + thisaccary[i] + "/g, '" + accstr + ":" + adepth + "')");
				break;
			}
		}

		if (i == thisaccary.length && this.m_accessory == '') this.m_accessory = accstr + ":" + adepth;
		else if(i == thisaccary.length && this.m_accessory != '') this.m_accessory = this.m_accessory + "_" + accstr + ":" + adepth;
	}
}

// accessory ----------------------------------------------------------


function av_setHC()
{
	
	var counter = Number(this.m_face + "") + 1;
	if (this.m_style == "old") {
		var filepath = "http://md5.enppy.com/character/" + this.m_type + "/" + this.m_gender + "/" + this.m_head + "/" + this.m_hair + "/";
		var filename1 = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hair + "_" + this.m_clothes + "_" + this.m_fixcode + "_" + this.m_face + ".png";
		var filename2 = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hair + "_" + this.m_clothes + "_" + this.m_fixcode + "_" + counter + ".png";
	
		this.m_imgobj5[0].src = filepath + filename1 + "";
		this.m_imgobj5[1].src = filepath + filename2 + "";
		this.m_imgobj4[0].src = AVT_NULLIMG;
		this.m_imgobj4[1].src = AVT_NULLIMG;
	}
	else if(this.m_style == "new"){
		if (this.m_type == "b" && this.m_head == "001"){
			this.m_imgobj4[0].src = AVT_URL + "/hair/" + this.m_type + "/" + this.m_gender + "/" + this.m_head + "/" + this.m_hair + "/" + this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hpattern + this.m_hair + "_" + this.m_face + ".png";
			this.m_imgobj4[1].src = AVT_URL + "/hair/" + this.m_type + "/" + this.m_gender + "/" + this.m_head + "/" + this.m_hair + "/" + this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hpattern + this.m_hair + "_" + counter + ".png";
		}else{
			this.m_imgobj4[0].src = AVT_NULLIMG;
			this.m_imgobj4[1].src = AVT_NULLIMG;
		}
		
		this.m_imgobj5[0].src = AVT_URL + "/clothes/" + this.m_type + "/" + this.m_gender + "/" + this.m_head + "/" + this.m_clothes + "/" + this.m_type + this.m_gender + "_" + this.m_cpattern + this.m_clothes + "_" + this.m_face + ".png";
		this.m_imgobj5[1].src = AVT_URL + "/clothes/" + this.m_type + "/" + this.m_gender + "/" + this.m_head + "/" + this.m_clothes + "/" + this.m_type + this.m_gender + "_" + this.m_cpattern + this.m_clothes + "_" + counter + ".png";
	}
	else{
		this.m_imgobj4[0].src = AVT_NULLIMG;
		this.m_imgobj4[1].src = AVT_NULLIMG;
		this.m_imgobj5[0].src = AVT_NULLIMG;
		this.m_imgobj5[1].src = AVT_NULLIMG;
	}
}

function av_chkpattern()
{
	if (this.m_style == "old") return;
	if (this.m_type != "b"){
		this.m_zidx[0] = "0";
		this.m_zidx[1] = "0";
		return;
	}
	var mx_hpattern = eval("AVT_b" + this.m_gender + "_PTTNUM[0]");
	var mx_cpattern = eval("AVT_b" + this.m_gender + "_PTTNUM[1]");
	var ptt1 = Number((this.m_hpattern).charCodeAt(0)) - 65; //65:A
	var ptt2 = Number((this.m_cpattern).charCodeAt(0)) - 65;
	var str = "AVT_b" + this.m_gender + "_ZIDX";
	
	if (!eval(str)){
		this.m_zidx[0] = "0";
		this.m_zidx[1] = "0";
		return;
	}
	
	var idx = (ptt1 * mx_cpattern) + ptt2
	
	str = str + "[" + idx + "]";
	
	str = eval(str);
	idx = Number((this.m_face + "").substr(0,1));
	idx = (idx - 1) * 2;
	this.m_zidx[0] = str.substr(idx,1);
	idx ++;
	this.m_zidx[1] = str.substr(idx,1);
	return ;
}

function av_animateext ()
{
	var av_templyrobj = ap_getlyr( this.m_layername );
	var av_templyrflag = av_templyrobj.visibility;

	this.animate();
	this.stop();
}

function av_hideimage ()
{
	av_showimage( this.m_imgobj4[0], false );
	av_showimage( this.m_imgobj4[1], false );
	av_showimage( this.m_imgobj5[0], false );
	av_showimage( this.m_imgobj5[1], false );
	av_showimage( this.m_imgpang, false );
}

function av_animate (mode)
{
	if(mode == 1){
		av_showimage( this.m_imgobj4[0], false );
		av_showimage( this.m_imgobj4[1], false );
		av_showimage( this.m_imgobj5[0], false );
		av_showimage( this.m_imgobj5[1], false );
		
		if (this.m_imgpang.src != AVT_PANGIMG) this.m_imgpang.src = AVT_PANGIMG;
		av_showimage( this.m_imgpang, true );

		
		this.stop();
		this.m_timer = setTimeout(this.m_self + ".animate()", 1500);
		return;
	}

	if (this.m_style == "new")
		this.animnew();
	else if (this.m_style == "old")
		this.animold();
	else
		return;
}

var readycount = 0;
function av_animatenew ()
{
	var rnd = 0;
	var rndp = 0;
	var obj1 = null;
	var obj2 = null;
	var idx1 = 0;
	var idx2 = 0;
	
	rnd = this.random(2);
	if (rnd == 0) rndp = 1;
	
	obj1 = this.m_imgobj4[rnd];
	obj2 = this.m_imgobj5[rnd];

	if (this.m_zidx[rnd] == "0"){
		if (obj1.style.zIndex > obj2.style.zIndex){
			idx = obj1.style.zIndex;
			obj1.style.zIndex = obj2.style.zIndex;
			obj2.style.zIndex = idx;
		}
	}
	else if(this.m_zidx[rnd] == "1"){
		if (obj1.style.zIndex <= obj2.style.zIndex){
			idx = obj2.style.zIndex;
			obj2.style.zIndex = obj1.style.zIndex;
			obj1.style.zIndex = idx;
		}
	}
	else
		return;

	obj1 = this.m_imgobj4[rndp];
	obj2 = this.m_imgobj5[rndp];
	
	if (this.m_zidx[rndp] == "0"){
		if (obj1.style.zIndex > obj2.style.zIndex){
			idx = obj1.style.zIndex;
			obj1.style.zIndex = obj2.style.zIndex;
			obj2.style.zIndex = idx;
		}
	}
	else if(this.m_zidx[rndp] == "1"){
		if (obj1.style.zIndex <= obj2.style.zIndex){
			idx = obj2.style.zIndex;
			obj2.style.zIndex = obj1.style.zIndex;
			obj1.style.zIndex = idx;
		}
	}
	else
		return;

	av_showimage( this.m_imgobj4[rnd], false );
	av_showimage( this.m_imgobj4[rndp], true );
	av_showimage( this.m_imgobj5[rnd], false );
	av_showimage( this.m_imgobj5[rndp], true );
	av_showimage( this.m_imgpang, false );

	this.stop();
	this.m_timer = setTimeout(this.m_self + ".animate()", this.m_pause * (this.random(2) + 1));
	return;
}

function av_animateold()
{
	var rnd = 0;
	var rndp = 0;

	rnd = this.random(2);
	if (rnd == 0) rndp = 1;
	
	av_showimage( this.m_imgobj4[rnd], false );
	av_showimage( this.m_imgobj4[rndp], false );
	av_showimage( this.m_imgobj5[rnd], false );
	av_showimage( this.m_imgobj5[rndp], true );
	av_showimage( this.m_imgpang, false );
	
	
	this.stop();
	this.m_timer = setTimeout(this.m_self + ".animate()", this.m_pause * (this.random(2) + 1));
	return;
}

function av_stop()
{
	if (this.m_timer != null)
		clearTimeout(this.m_timer);
}

function av_init(avatar, layername, objname)
{
	var code = 0;

	var avtlng = avatar.length;
	if (avatar == "" || avatar == null || (IE4 && !IE5) || NS)
		return;
	if ( avtlng == 21){
		var avtary = avatar.split("_");
		this.m_style 	= "old";
		this.m_type 	= avtary[0].substr(0,1);
		this.m_gender 	= avtary[0].substr(1,2);
		this.m_head 	= avtary[1];
		this.m_hpattern = "";
		this.m_hair 	= avtary[2];
		this.m_cpattern	= "";
		this.m_clothes	= avtary[3];
		this.m_fixcode	= avtary[4];
		this.m_face 	= Number(avtary[5]);

		this.m_accessory = "";
	}
	else if ( avtlng == 35){
		var avtary = avatar.split("_");
		this.m_style	= "new";
		this.m_type 	= avtary[0].substr(0,1);
		this.m_gender 	= avtary[0].substr(1,2);
		this.m_head 	= avtary[1];
		this.m_hpattern = avtary[2].substr(0,1);
		this.m_hair 	= avtary[2].substr(1);
		
		code = (this.m_hpattern).charCodeAt(0);
		if(code < 65 || code > 90){
			this.m_hpattern = "A";
			this.m_hair = avtary[2];
		}
		this.m_cpattern	= avtary[3].substr(0,1);
		this.m_clothes	= avtary[3].substr(1);
		this.m_face 	= Number(avtary[8]);

		this.m_accessory = "";
	}
	else {
		var avtary = avatar.split("_");
		this.m_style	= "new";
		this.m_type 	= avtary[0].substr(0,1);
		this.m_gender 	= avtary[0].substr(1,2);
		this.m_head 	= avtary[1];
		this.m_hpattern = avtary[2].substr(0,1);
		this.m_hair 	= avtary[2].substr(1);
		
		code = (this.m_hpattern).charCodeAt(0);
		if(code < 65 || code > 90){
			this.m_hpattern = "A";
			this.m_hair = avtary[2];
		}
		this.m_cpattern	= avtary[3].substr(0,1);
		this.m_clothes	= avtary[3].substr(1);
		this.m_face 	= Number(avtary[avtary.length-1]);
		//accessory
		if(avtary.length == 5)	// no accessory
			this.m_accessory = ""	
		else
			this.m_accessory = avatar.substring(17,avatar.length-3);
	}
	
	if ( this.m_type == "" || this.m_gender == "" || this.m_head == "" )
		return;
	
	this.m_recentype	= this.m_type;
	
	this.m_inithair = this.m_hair;
	this.m_initclothes = this.m_clothes;
	this.m_initaccessory = this.m_accessory;

	if ( this.m_type == "b" ){
		this.m_recenthair	= this.m_hair;
		this.m_recentclothes= this.m_clothes;
	}
	else{
		this.m_recenthair	= "001";
		this.m_recentclothes= "001";
	}

	eval("this.m_layername = '" + layername + "'");
	eval("this.m_layername_face = '" + layername + "_face'");
	
	var str = "" + 
			  // avatar view
			  "<IMG ID=" + layername + "_img4 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:0; left:0; position:absolute; width:96; height:128; z-index=13;\">" +
			  "<IMG ID=" + layername + "_img4p SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:0; left:0; position:absolute; width:96; height:128; z-index=14;\">" +
			  "<IMG ID=" + layername + "_img5 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:0; left:0; position:absolute; width:96; height:128; z-index=15;\">" +
			  "<IMG ID=" + layername + "_img5p SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:0; left:0; position:absolute; width:96; height:128; z-index=16;\">" + 
			  // special avatar change
			  "<IMG ID=" + layername + "_imgpang SRC='" + AVT_PANGIMG + "' BORDER=0 STYLE=\"top:0; left:0; position:absolute; width:96; height:128; z-index=19;\">" +
			  // accessory view
			  "<IMG ID=" + layername + "_acc1 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=1;\">" +
			  "<IMG ID=" + layername + "_acc2 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=2;\">" +
			  "<IMG ID=" + layername + "_acc3 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=3;\">" +
			  "<IMG ID=" + layername + "_acc4 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=4;\">" +
			  "<IMG ID=" + layername + "_acc5 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=5;\">" +
			  "<IMG ID=" + layername + "_acc6 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=21;\">" +
			  "<IMG ID=" + layername + "_acc7 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=22;\">" +
			  "<IMG ID=" + layername + "_acc8 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=23;\">" +
			  "<IMG ID=" + layername + "_acc9 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=24;\">" +
			  "<IMG ID=" + layername + "_acc10 SRC='" + AVT_NULLIMG + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=25;\">" + 
			  // hide imageurl or hide drag avatar
			  "<DIV ID=" + layername + "_null STYLE=\"top:-22; left:-16; position:absolute; z-index=99\"><IMG SRC='" + AVT_NULLIMG + "' WIDTH=128 HEIGHT=150 BORDER=0></DIV>";

	if (ap_setlyrtag) ap_setlyrtag(this.m_layername, str);	else return;

	this.m_imgobj4[0] = eval("document.images." + layername + "_img4");
	this.m_imgobj4[1] = eval("document.images." + layername + "_img4p");
	this.m_imgobj5[0] = eval("document.images." + layername + "_img5");
	this.m_imgobj5[1] = eval("document.images." + layername + "_img5p");
	this.m_imgpang = eval("document.images." + layername + "_imgpang");
	this.m_imgnull = eval("document.images." + layername + "_null");
	
	// accessory
	for (i = 1; i <= 10; i++) eval("this.m_imgacc" + i + " = document.images." + layername + "_acc" + i);

	this.m_self = objname;
	this.m_ciid = "";
	this.m_hiid = "";

	this.chgavatar();
	this.chgaccessory_init();

	this.chghead(this.m_hair);
	return;
}

function av_chghead_init(hairface)
{
	this.m_sfaceimg = "http://md5.enppy.com/face/" + this.m_type + "/" + this.m_gender + "/" + this.m_head + "/" + hairface + "/" + this.m_type + this.m_gender + "_" + this.m_head + "_" + hairface;
	var str = "<IMG NAME=" + this.m_layername_face + "_1 SRC=" + this.m_sfaceimg + "_11_o.gif WIDTH=24 HEIGHT=24 HSPACE=3 VSPACE=5 BORDER=0 ALT=º¸Åë onClick=\"MyAvatar.normal();\" onMouseOver=\"av_doOver(this);\">" +
			  "<IMG NAME=" + this.m_layername_face + "_2 SRC=" + this.m_sfaceimg + "_21_o.gif WIDTH=24 HEIGHT=24 HSPACE=3 VSPACE=5 BORDER=0 ALT=È­³² onClick=\"MyAvatar.angry();\" onMouseOver=\"av_doOver(this);\">" +
			  "<IMG NAME=" + this.m_layername_face + "_3 SRC=" + this.m_sfaceimg + "_31_o.gif WIDTH=24 HEIGHT=24 HSPACE=3 VSPACE=5 BORDER=0 ALT=½½ÇÄ onClick=\"MyAvatar.cry();\" onMouseOver=\"av_doOver(this);\">" +
			  "<IMG NAME=" + this.m_layername_face + "_4 SRC=" + this.m_sfaceimg + "_41_o.gif WIDTH=24 HEIGHT=24 HSPACE=3 VSPACE=5 BORDER=0 ALT=±â»Ý onClick=\"MyAvatar.smile();\" onMouseOver=\"av_doOver(this);\">" +
			  "<IMG NAME=" + this.m_layername_face + "_5 SRC=" + this.m_sfaceimg + "_51_o.gif WIDTH=24 HEIGHT=24 HSPACE=3 VSPACE=5 BORDER=0 ALT=È²´ç onClick=\"MyAvatar.weird();\" onMouseOver=\"av_doOver(this);\">" +
			  "<IMG NAME=" + this.m_layername_face + "_6 SRC=" + this.m_sfaceimg + "_61_o.gif WIDTH=24 HEIGHT=24 HSPACE=3 VSPACE=5 BORDER=0 ALT=½ä·· onClick=\"MyAvatar.chilly();\" onMouseOver=\"av_doOver(this);\">";
	if (ap_setlyrtag) ap_setlyrtag(this.m_layername_face , str);
	
	for (i = 0; i <= 5 ; i++)
		this.m_imgfaceobj[i] = eval("document.images." + this.m_layername_face + "_" + (i+1).toString());
}

function av_chgaccessory_init(){
	if( this.m_accessory != ""){
		var ary = this.m_accessory.split("_");
		for(i=0; i < ary.length; i++){
			var accurl = AVT_ACC_URL + "/" + ary[i].substr(0,2) + "/" + ary[i].substr(2,1) + "/C" + ary[i] + ".gif";
			eval("this.m_imgacc" + ary[i].substr(0,2)*1 + ".src = accurl;");
		}
	}
	else
		return;
}

function av_chghead(hairface)
{
	this.m_sfaceimg = "http://md5.enppy.com/face/" + this.m_type + "/" + this.m_gender + "/" + this.m_head + "/" + hairface + "/" + this.m_type + this.m_gender + "_" + this.m_head + "_" + hairface;
	if(this.m_imgfaceobj[0])
		for (i = 0; i <= 5 ; i++)
			this.m_imgfaceobj[i].src = this.m_sfaceimg + "_" + (i+1).toString() + "1_o.gif";
}

function av_doOut(element){
	element.style.filter = "gray()";
}

function av_doOver(element){
	element.style.filter = "";
	element.style.cursor = "hand";
}

function av_getfilename(){
	var str = "";
	
	if (this.m_type == "" || this.m_gender == "")
		return str;
	if (this.m_style == "new" && this.m_accessory == "")
		str = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hpattern + this.m_hair + "_" + this.m_cpattern + this.m_clothes + "_" + this.m_face + ".png";
	else if (this.m_style == "new" && this.m_accessory != "")
		str = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hpattern + this.m_hair + "_" + this.m_cpattern + this.m_clothes + "_" + this.m_accessory + "_" + this.m_face + ".png";
	else if (this.m_style == "old")
		str = this.m_type + this.m_gender + "_" + this.m_head + "_" + this.m_hair + "_" + this.m_clothes + "_000_" + this.m_face + ".png";
	return str;
}

function av_showimage( obj, enable ){
	if( enable ) {
		obj.style.visibility = "visible";
	} 
	else {
		obj.style.visibility = "hidden";
	}
}

var ACC_ZIDX = [0,1,2,3,4,5,21,22,23,24,25];

// mode 0 : without accessory
// mode 1 : with accessory
// mode 2 : with accessory but no background image
// avtstr : full avatar info string
function makeAvatarTag(mode, avtstr) {

	var str = "<DIV STYLE=\" position:relative;\">";
	if (mode == 0) {
		// without accessory
		str = str + "<IMG SRC='http://md5.entica.com:8080/cgi-bin/avtimg.cgi?" + avtstr + "'>";
	}
	else {
		// with accessory
		str =  str + "<IMG SRC='http://md5.entica.com:8080/cgi-bin/avtimg.cgi?" + avtstr + "' BORDER=0 STYLE=\"top:0; left:0; position:absolute; width:96; height:128; z-index=11;\">";
		
		// accessory view b1_001_A001_A000_41
		var	accessoryAry = avtstr.split("_");
		for (var i=4; i < accessoryAry.length - 1; i++) {
			var accurl = AVT_ACC_URL + "/" + accessoryAry[i].substr(0,2) + "/" + accessoryAry[i].substr(2,1) + "/C" + accessoryAry[i] + ".gif";
			var z_index = accessoryAry[i].substr(0,2) * 1; // z_index
			if ((ACC_ZIDX[z_index] == 1 && mode == 2) == false)
				str = str + "<IMG SRC='" + accurl + "' BORDER=0 STYLE=\"top:-22; left:-16; position:absolute; width:128; height:150; z-index=" + ACC_ZIDX[z_index] + ";\">";
		}
	}

	// hide imageurl or hide drag avatar
	str = str + "<DIV STYLE=\"top:-22; left:-16; position:absolute; z-index=99\"><IMG SRC='" + AVT_NULLIMG + "' WIDTH=128 HEIGHT=150 BORDER=0></DIV>";
	return str + "</DIV>";
}


// This stops the javascript from hiding -->