// StrBCView ( Baram Character View )

_BCView_Item	 	= [ "Body", "Head", "Weapon", "Shield", "Hair", "Helmet", "Acc", "HairAcc", "Mantle", "Coat", "Shoes", "Necklace" ];
_BCView_Color		= [ "BodyColor", "HeadColor", "WeaponColor", "ShieldColor", "HairColor", "HelmetColor", "AccColor", "HairAccColor", "MantleColor", "CoatColor", "ShoesColor", "NecklaceColor" ];
_BCView_Riding		= [ "UseRiding", "RidingIndex", "RidingColor" ];
_BCView_Action		= [ "Direction", "Emotion" ];

function BCView_Write( strBCView )
{
	var strRet = "";
	
	if ( strBCView == null || strBCView == "" )
	{
		return "";
	}
	
	var strBody = strBCView.split( "|" );
	if ( strBody.length != 4 )
		return "";
		
	/*
	strBody[ 0 ] : Header		
	strBody[ 1 ] : Item
	strBody[ 2 ] : Riding
	strBody[ 3 ] : Action
	*/

	// Parse Header
	if ( strBody[ 0 ] != "strBCView" )
		return "";

	// Parse Item		
	var strItem = strBody[ 1 ].split( ";" );
	var strItemProp;
	
	if ( strItem.length != _BCView_Item.length )
		return "";
		
	for ( var i in strItem )
	{
		strItemProp = strItem[ i ].split( ":" );
		
		this[ _BCView_Item[ i ] ] = strItemProp[ 0 ];
		this[ _BCView_Color[ i ] ] = strItemProp[ 1 ];
		
		if (_BCView_Item[ i ] == "Helmet" )
		{
			this[ "HelmetType" ] = strItemProp[ 2 ];	
		}
	}	
	
	// Parse Riding
	var strRiding = strBody[ 2 ].split( ";" );
	if ( strRiding.length != _BCView_Riding.length )
		return "";

	for ( var i in strRiding )
	{
		this[ _BCView_Riding[ i ] ] = strRiding[ i ];
	}
	
	// Parse Action
	var strAction = strBody[ 3 ].split( ";" );
	if ( strAction.length != _BCView_Action.length )
		return;
		
	for ( var i in strAction )
	{
		this[ _BCView_Action[ i ] ] = strAction[ i ];
	}
	
	// Set Character Image
	
	// BodyÀÇ °æ¿ì¿¡ WeaponÀÌ ÀÖ´ÂÁö ¾ø´ÂÁö¿¡ µû¶ó¼­ ´Ù¸¥ ÀÌ¹ÌÁö¸¦ »ç¿ëÇÔ
	var	strWeapon = "";
	var nWeapon = Number( this.Weapon );
	if ( nWeapon == 255 )
	{
		// No Weapon
		strWeapon = "";
	}
	else
	{
		strWeapon = "w";
	}
	
	// New Head TypeÀÇ °æ¿ì¿¡¸¸ Hair, Helmet, Acc »ç¿ë
	var bNewHeadType = 0;
	var nHead = Number( this.Head );
	if ( 200 <= nHead && nHead <=899 )
	{
		bNewHeadType = 1;
	}
	

	var strImgTag;
	if ( this.UseRiding == "00" )
	{
		// Å»°ÍÀÌ ¾øÀ½
		if ( this.Coat == "00255" )
		{
			strImgTag = _BCharViewCore_GetImgTag_Body( this.Body, this.Direction, this.BodyColor, this.Emotion, strWeapon );
			strRet += _BCharViewCore_GetLayerStr( "Body", 2, strImgTag );
		}
		else
		{
			strImgTag = _BCharViewCore_GetImgTag_Coat( this.Coat, this.Direction, this.CoatColor, this.Emotion, strWeapon );
			strRet += _BCharViewCore_GetLayerStr( "Coat", 2, strImgTag );

			strImgTag = _BCharViewCore_GetImgTag_Shoes( this.Shoes, this.Direction, this.ShoesColor, this.Emotion );
			strRet += _BCharViewCore_GetLayerStr( "Shoes", 1, strImgTag );
		}
		
		strImgTag = _BCharViewCore_GetImgTag_Head( this.Head, this.Direction, this.HeadColor, this.Emotion );
		strRet += _BCharViewCore_GetLayerStr( "Head", 3, strImgTag );

		if ( this.Emotion == "00" )
		{
			// Emotion 00ÀÏ ¶§¸¸, ¹«±â º¸¿©ÁÖ±â, ¹æÆÐ º¸¿©ÁÖ±â
			strImgTag = _BCharViewCore_GetImgTag_Weapon( this.Weapon, this.Direction, this.WeaponColor );
			strRet += _BCharViewCore_GetLayerStr( "Weapon", 11, strImgTag );
		
			strImgTag = _BCharViewCore_GetImgTag_Shield( this.Shield, this.Direction, this.ShieldColor );
			// È­»ìÅëÀÇ °æ¿ì
			if (this.Shield >= 10000)
			{
				strRet += _BCharViewCore_GetLayerStr( "Shield", 1, strImgTag );
			} else {
				strRet += _BCharViewCore_GetLayerStr( "Shield", 10, strImgTag );
			}
		}
		
		strImgTag = _BCharViewCore_GetImgTag_Mantle( this.Mantle, this.Direction, this.MantleColor, this.Emotion );
		strRet += _BCharViewCore_GetLayerStr( "Mantle", 0, strImgTag );

		strImgTag = _BCharViewCore_GetImgTag_Necklace( this.Necklace, this.Direction, this.NecklaceColor, this.Emotion );
		strRet += _BCharViewCore_GetLayerStr( "Necklace", 3, strImgTag );
	}
	else
	{
		// Å»°ÍÀÌ ÀÖÀ½ : ¹«±â X, ¹æÆÐ X, Å»°Í O, Eomtion 22
		if ( this.Coat == "00255" )
		{
			strImgTag = _BCharViewCore_GetImgTag_Body( this.Body, this.Direction, this.BodyColor, "22", strWeapon );
			strRet += _BCharViewCore_GetLayerStr( "Body", 2, strImgTag );
		}
		else
		{
			strImgTag = _BCharViewCore_GetImgTag_Coat( this.Coat, this.Direction, this.CoatColor, "22", strWeapon );
			strRet += _BCharViewCore_GetLayerStr( "Coat", 2, strImgTag );

			strImgTag = _BCharViewCore_GetImgTag_Shoes( this.Shoes, this.Direction, this.ShoesColor, "22" );
			strRet += _BCharViewCore_GetLayerStr( "Shoes", 1, strImgTag );
		}		
		strImgTag = _BCharViewCore_GetImgTag_Head( this.Head, this.Direction, this.HeadColor, "22" );
		strRet += _BCharViewCore_GetLayerStr( "Head", 3, strImgTag );
		
		strImgTag = _BCharViewCore_GetImgTag_Riding( this.RidingIndex, this.Direction, this.RidingColor );
		strRet += _BCharViewCore_GetLayerStr( "Riding", 12, strImgTag );

		strImgTag = _BCharViewCore_GetImgTag_Mantle( this.Mantle, this.Direction, this.MantleColor, "22" );
		strRet += _BCharViewCore_GetLayerStr( "Mantle", 0, strImgTag );

		strImgTag = _BCharViewCore_GetImgTag_Necklace( this.Necklace, this.Direction, this.NecklaceColor, "22" );
		strRet += _BCharViewCore_GetLayerStr( "Necklace", 3, strImgTag );
	}
	
	if ( bNewHeadType == 1 )
	{
		// New Head TypeÀÇ °æ¿ì¿¡¸¸ Hair, Helmet, Acc »ç¿ë
		
		var strEmotion;
		
		if ( this.UseRiding == "00" )
		{
			strEmotion = this.Emotion;	
		}
		else
		{
			strEmotion = "22";
		}
		
		if ( this.HairAcc != "00255" )
		{
			strImgTag = _BCharViewCore_GetImgTag_HairAcc( this.HairAcc , this.Direction, this.HairAccColor, strEmotion );
			strRet += _BCharViewCore_GetLayerStr( "HairAcc", 8, strImgTag );
			
			strImgTag = _BCharViewCore_GetImgTag_Hair( this.Hair, this.Direction, this.HairColor, strEmotion );
			strRet += _BCharViewCore_GetLayerStr( "Hair", 7, strImgTag );
		}
		else
		{
			var bViewHair = 1;
			var bViewHelmet = 1;
			
			switch ( Number( this.HelmetType ) )
			{
				case 0:
				{
					bViewHair = 1;
					bViewHelmet = 0;
				}	break;
				case 1:
				{
					bViewHair = 0;
					bViewHelmet = 1;
				}	break;
			}
		
			if ( bViewHair == 1 )
			{
				strImgTag = _BCharViewCore_GetImgTag_Hair( this.Hair, this.Direction, this.HairColor, strEmotion );
				strRet += _BCharViewCore_GetLayerStr( "Hair", 7, strImgTag );
			}
		
			if ( bViewHelmet == 1 )
			{
				strImgTag = _BCharViewCore_GetImgTag_Helmet( this.Helmet, this.Direction, this.HelmetColor, strEmotion );
				strRet += _BCharViewCore_GetLayerStr( "Helmet", 8, strImgTag );
			}	
		}
				
		var nAccLayer;
		var nAcc = Number( this.Acc );
		
		// Acc´Â µÎ°¡Áö typeÀ¸·Î ³ª´©¾îÁö¸ç, ±×¸®´Â Layer°¡ ´Ù¸£´Ù.
		if ( 0 <= nAcc && nAcc <= 9999 )
		{
			strImgTag = _BCharViewCore_GetImgTag_Acc( this.Acc, this.Direction, this.AccColor, strEmotion );
			strRet += _BCharViewCore_GetLayerStr( "Acc", 6, strImgTag );
		}
		else
		{
			var Acc = this.Acc - 10000;
			Acc = ( "00000" + Acc );
			Acc = Acc.substr( Acc.length-5 );
			strImgTag = _BCharViewCore_GetImgTag_HairAcc( Acc, this.Direction, this.AccColor, strEmotion );
			strRet += _BCharViewCore_GetLayerStr( "HairAcc", 8, strImgTag );
		}
	}

	return strRet;
}

// CharView Core Function

if ( typeof( g_strImgPath ) == "undefined" ) 
{
	g_strImgPath = "./image";
}

function _BCharViewCore_GetImgTag_Body( strIndex, strDirection, strColorset, strEmotion, strWeapon )
{
	if ( strEmotion == "00" && strWeapon != "" )
	{
		// EmotionÀÌ StandÀÌ°í WeaponÀ» »ç¿ëÇÏ´Â °æ¿ì¿¡´Â ´Ù¸¥ ÀÌ¹ÌÁö¸¦ »ç¿ëÇÏ°Ô µÈ´Ù.
		strWeapon = "_" + strWeapon;
	}
	else
	{
		strWeapon = "";	
	}
	
	return "<img src='" + g_strImgPath + "/body/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion + strWeapon +"_0.gif'>";
}

function _BCharViewCore_GetImgTag_Coat( strIndex, strDirection, strColorset, strEmotion, strWeapon )
{
	if ( strIndex == "00255" )
		return "";

	if ( strEmotion == "00" && strWeapon != "" )
	{
		// EmotionÀÌ StandÀÌ°í WeaponÀ» »ç¿ëÇÏ´Â °æ¿ì¿¡´Â ´Ù¸¥ ÀÌ¹ÌÁö¸¦ »ç¿ëÇÏ°Ô µÈ´Ù.
		strWeapon = "_" + strWeapon;
	}
	else
	{
		strWeapon = "";	
	}
	
	return "<img src='" + g_strImgPath + "/coat/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion + strWeapon +"_0.gif'>";
}

function _BCharViewCore_GetImgTag_Shoes( strIndex, strDirection, strColorset, strEmotion )
{
	if ( strIndex == "00255" )
	{
		// No Helmet
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/shoes/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Mantle( strIndex, strDirection, strColorset, strEmotion )
{
	if ( strIndex == "00255" )
	{
		// No Helmet
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/mantle/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Necklace( strIndex, strDirection, strColorset, strEmotion )
{
	if ( strIndex == "00255" )
	{
		// No Helmet
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/necklace/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Head( strIndex, strDirection, strColorset, strEmotion )
{
	return "<img src='" + g_strImgPath + "/head/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
}

function _BCharViewCore_GetImgTag_Weapon( strIndex, strDirection, strColorset )
{
	if ( strIndex == "00255" )
	{
		// No Weapon
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/weapon/" + strIndex + "/" + strDirection + "_" + strColorset + "_00_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Shield( strIndex, strDirection, strColorset )
{
	if ( strIndex == "00255" )
	{
		// No Shield
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/shield/" + strIndex + "/" + strDirection + "_" + strColorset + "_00_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Hair( strIndex, strDirection, strColorset, strEmotion )
{
	if ( strIndex == "00255" )
	{
		// No Hair
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/hair/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Helmet( strIndex, strDirection, strColorset, strEmotion )
{
	if ( strIndex == "00255" )
	{
		// No Helmet
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/helmet/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_HairAcc( strIndex, strDirection, strColorset, strEmotion )
{

	if ( strIndex == "00255" )
	{
		// No Helmet
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/acc2/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Acc( strIndex, strDirection, strColorset, strEmotion )
{
	if ( strIndex == "00255" )
	{
		// No Acc
		return "";
	}
	else
	{
		return "<img src='" + g_strImgPath + "/acc1/" + strIndex + "/" + strDirection + "_" + strColorset + "_" + strEmotion +"_0.gif'>";
	}
}

function _BCharViewCore_GetImgTag_Riding( strIndex, strDirecton, strColorset )
{
	return "<img src='" + g_strImgPath + "/riding/" + strIndex + "/" + strDirecton + "_" + strColorset + "_22_0.gif'>";
}

function _BCharViewCore_GetLayerStr( strId, nLayer, strImgTag )
{
	if ( strImgTag != "" )
	{
		return "<div id=" + strId + " style='position:absolute; z-index:" + nLayer + "'>" + strImgTag + "</div>";
	}
	else
	{
		return "";
	}
}

function GetDrawItemIconStr(strEquipView, topAdjust, leftAdjust)
{
	var strEquips = strEquipView.split(';');
	var strReturnValue = '';

	for (var equipIdx=0; equipIdx<strEquips.length; equipIdx++ )
	{
		var strEquip = strEquips[equipIdx].split(':');
		
		if (strEquip[0] == 1)
			strReturnValue = strReturnValue + "<div id=rightHandIcon style='position:absolute; top:" + (85+topAdjust) + "; left:" + (20+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 2)
			strReturnValue = strReturnValue + "<div id=bodyIcon style='position:absolute; top:" + (85+topAdjust) + "; left:" + (75+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 3)
			strReturnValue = strReturnValue + "<div id=leftHandIcon style='position:absolute; top:" + (85+topAdjust) + "; left:" + (133+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 4)
			strReturnValue = strReturnValue + "<div id=headIcon style='position:absolute; top:" + (28+topAdjust) + "; left:" + (75+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 7)
			strReturnValue = strReturnValue + "<div id=mainAcc1 style='position:absolute; top:" + (138+topAdjust) + "; left:" + (35+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 8)
			strReturnValue = strReturnValue + "<div id=mainAcc2 style='position:absolute; top:" + (138+topAdjust) + "; left:" + (115+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 20)
			strReturnValue = strReturnValue + "<div id=subAcc1 style='position:absolute; top:" + (192+topAdjust) + "; left:" + (35+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 21)
			strReturnValue = strReturnValue + "<div id=subAcc2 style='position:absolute; top:" + (192+topAdjust) + "; left:" + (115+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
		else if (strEquip[0] == 22)
			strReturnValue = strReturnValue + "<div id=rightHandIcon style='position:absolute; top:" + (28+topAdjust) + "; left:" + (20+leftAdjust) + "'><img src='http://s.nx.com/s2/game/baram/baram/static/game/nexon/newbaram/itemImage/item"+strEquip[1].substring(0,3)+"/"+strEquip[1]+"_"+strEquip[2]+".gif' width=43 heigth=43 alt="+strEquip[3]+"></div>";
	}
	return strReturnValue;
}
