
function ChatHistoryItem () {
            
	//For Layer		
	this.BoxLayerIndex			= -1;		
	this.AvatarLayerIndex		= -1;						
	this.NameLayerIndex         = -1;
	this.TimeLayerIndex			= -1;
	this.OnlieStatusLayerIndex  = -1;
	this.MsgBallonLayerIndex	= -1;
	this.MsgNumberLayerIndex	= -1;
	this.SummaryLayerIndex		= -1;
		
    this.BoxStyle		= new Array(ITEM_STATE.MAX);   
    this.AvatarStyle	= new Array(ITEM_STATE.MAX);
	this.NameStyle		= new Array(ITEM_STATE.MAX);
    this.TimeStyle		= new Array(ITEM_STATE.MAX);
	this.OnlineStyle	= new Array(ITEM_STATE.MAX);	
	this.SummaryStyle	= new Array(ITEM_STATE.MAX);
	this.MsgBallonStyle	= new Array(ITEM_STATE.MAX);
	
	this.NameMarqueeStyle = null;
	this.NameMarqueeCheckerDiv = null;

	//For Data	
	this.ChatName			= null;
	this.ParticipantName	= null;	
	this.HostIdentyName		= null;
	this.HostDisplayName	= null;
	this.AvatarType			= null;
	this.IsMultiChat		= false;
	this.DisplayName		= null;
	//this.NewChatNum			= 0;
	
    ListItem.call(this);
}

ChatHistoryItem.prototype = new ListItem(); 


ChatHistoryItem.prototype.Create = function(eName) {
    
    alert("ChatHistoryItem.Create()");
	
    this.CreateBG(eName);
	this.CreateName(eName);	
    this.CreateTime(eName);	
    this.CreateBox(eName);	
    this.CreateAvatar(eName);    
	this.CreateOnlineStatus(eName);
	//this.CreateSummary(eName);	
	this.CreateMsgBallon(eName);
	this.CreateMsgNumber(eName);

    if(this.ItemID % 2 == 1){
        this.SetBgImage(ITEM_STATE.NORMAL,g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_NORMAL_BG_1);            		
    }
    else {        
        this.SetBgImage(ITEM_STATE.NORMAL,g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_NORMAL_BG_2);
    } 
	 	
	this.SetBgImage(ITEM_STATE.HIGHLIGHT,g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_HIGHLIGHT_BG);	
		
	this.SetBgStyle(ITEM_STATE.NORMAL_UP, eName + "NormalUp");
	this.SetBgStyle(ITEM_STATE.NORMAL_DOWN, eName + "NormalDown");
	this.SetBgStyle(ITEM_STATE.HIGHLIGHT, eName + "Highlight");
	
	this.SetBoxStyle(ITEM_STATE.NORMAL, "cItem_Box_Normal");
	this.SetBoxStyle(ITEM_STATE.HIGHLIGHT, "cItem_Box_Highlight");	
	
	this.SetAvatarStyle(ITEM_STATE.NORMAL, "cItem_Avatar_Normal");
	this.SetAvatarStyle(ITEM_STATE.HIGHLIGHT, "cItem_Avatar_Highlight");	

	this.SetOnlineStyle(ITEM_STATE.NORMAL, "cItem_Online_Normal");
	this.SetOnlineStyle(ITEM_STATE.HIGHLIGHT, "cItem_Online_Highlight");
	
	this.SetNameStyle(ITEM_STATE.NORMAL, "cChatItem_Name_Normal");
	this.SetNameStyle(ITEM_STATE.HIGHLIGHT, "cChatItem_Name_Highlight");
	
	this.NameMarqueeStyle = "cChatItem_Name_Highlight_Marquee";
	this.NameMarqueeCheckerDiv = "chatTextLengthChecker";

		
	this.SetTimeStyle(ITEM_STATE.NORMAL, "cChatItem_Time_Normal");
	this.SetTimeStyle(ITEM_STATE.HIGHLIGHT, "cChatItem_Time_Highlight");
						
														
	//this.SetSummaryStyle(ITEM_STATE.NORMAL, "cChatItem_Summary_Normal");
	//this.SetSummaryStyle(ITEM_STATE.HIGHLIGHT, "cChatItem_Summary_Highlight");
	
	this.SetMsgBallonStyle(ITEM_STATE.NORMAL, "cChatItem_MsgBallon_Normal");
	this.SetMsgBallonStyle(ITEM_STATE.HIGHLIGHT, "cChatItem_MsgBallon_Highlight");
			
}

ChatHistoryItem.prototype.CreateName = function(eRootName) {

    var ElementStr = eRootName + "Name";
    
    this.NameLayerIndex = this.LayerArray.length; 
    this.AddTextLayer(ElementStr);
    this.LayerArray[this.NameLayerIndex].SetReverseDisable(true); 
             
}

ChatHistoryItem.prototype.CreateTime = function(eRootName) {

    var ElementStr = eRootName + "Time";

    this.TimeLayerIndex = this.LayerArray.length;    
    this.AddTextLayer(ElementStr);    
  
}

ChatHistoryItem.prototype.CreateBox = function(eRootName) {

    var ElementStr = eRootName + "Box";

    this.BoxLayerIndex = this.LayerArray.length;    
    this.AddJPGImageLayer(ElementStr);	                
}

ChatHistoryItem.prototype.CreateAvatar = function(eRootName) {

    var ElementStr = eRootName + "Avatar";

    this.AvatarLayerIndex = this.LayerArray.length;    
    this.AddJPGImageLayer(ElementStr);    
             
}

ChatHistoryItem.prototype.CreateOnlineStatus = function(eRootName) {

    var ElementStr = eRootName + "Online";

    this.OnlieStatusLayerIndex = this.LayerArray.length;    
    this.AddImageLayer(ElementStr);    
             
}

ChatHistoryItem.prototype.CreateSummary = function(eRootName) {

    var ElementStr = eRootName + "Summary";

    this.SummaryLayerIndex = this.LayerArray.length;    
    this.AddTextLayer(ElementStr); 
             
}

ChatHistoryItem.prototype.CreateMsgBallon = function(eRootName) {

    var ElementStr = eRootName + "MsgBallon";
    this.MsgBallonLayerIndex = this.LayerArray.length;    
    this.AddImageLayer(ElementStr); 
	this.LayerArray[this.MsgBallonLayerIndex].SetImage(g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_MSG_BALLON );
        
}

ChatHistoryItem.prototype.CreateMsgNumber = function(eRootName) {

    var ElementStr = eRootName + "MsgNumber";
    this.MsgNumberLayerIndex = this.LayerArray.length;    
    this.AddTextLayer(ElementStr); 
             
}


ChatHistoryItem.prototype.SetOnlineStyle = function(ItemStateIndex, Style){
    	
	this.OnlineStyle[ItemStateIndex] = Style;
    
}

ChatHistoryItem.prototype.SetBoxStyle = function(ItemStateIndex, Style){
    	
	this.BoxStyle[ItemStateIndex] = Style;
    
}	

ChatHistoryItem.prototype.SetAvatarStyle = function(ItemStateIndex, Style){
    	
	this.AvatarStyle[ItemStateIndex] = Style;
    
}

ChatHistoryItem.prototype.SetTimeStyle = function(ItemStateIndex, Style){
    	
	this.TimeStyle[ItemStateIndex] = Style;
    
}

ChatHistoryItem.prototype.SetNameStyle = function(ItemStateIndex, Style){
    	
	this.NameStyle[ItemStateIndex] = Style;
    
}

ChatHistoryItem.prototype.SetSummaryStyle = function(ItemStateIndex, Style){
    	
	this.SummaryStyle[ItemStateIndex] = Style;    
}

ChatHistoryItem.prototype.SetMsgBallonStyle = function(ItemStateIndex, Style){
    	
	this.MsgBallonStyle[ItemStateIndex] = Style;
    
}


ChatHistoryItem.prototype.UpNormal = function() {
	alert("ChatHistoryItem.UpNormal()");
    this.State = ITEM_STATE.NORMAL_UP;
	this.ChangeBG();
	this.ChangeLayerForNormal();
}

ChatHistoryItem.prototype.DownNormal = function() {
	alert("ChatHistoryItem.DownNormal()");
    this.State = ITEM_STATE.NORMAL_DOWN;
	this.ChangeBG();
	this.ChangeLayerForNormal();
}

ChatHistoryItem.prototype.Highlight = function() {
	alert("ChatHistoryItem.Highlight()");
	this.State = ITEM_STATE.HIGHLIGHT;
	this.ChangeBG();
	this.ChangeLayerForHighlight();
	
}

ChatHistoryItem.prototype.ChangeLayerForHighlight = function() {
	
	alert("ChatHistoryItem.ChangeLayerForHighlight()");

	this.LayerArray[this.BoxLayerIndex].SetStyle(this.BoxStyle[ITEM_STATE.HIGHLIGHT]);
	this.LayerArray[this.BoxLayerIndex].SetImage(g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_HIGHLIGHT_THUMBNALE_BOX);
	this.LayerArray[this.AvatarLayerIndex].SetStyle(this.AvatarStyle[ITEM_STATE.HIGHLIGHT]);		
    this.SetBigAvatar();
	this.LayerArray[this.OnlieStatusLayerIndex].SetStyle(this.OnlineStyle[ITEM_STATE.HIGHLIGHT]);
	this.LayerArray[this.TimeLayerIndex].SetStyle(this.TimeStyle[ITEM_STATE.HIGHLIGHT]);	
    this.LayerArray[this.MsgBallonLayerIndex].SetStyle(this.MsgBallonStyle[ITEM_STATE.HIGHLIGHT]);    	

	if(this.LayerArray[this.NameLayerIndex].CheckTextLength(this.NameMarqueeCheckerDiv, this.DisplayName) > 320)
	{
		this.LayerArray[this.NameLayerIndex].SetTextStyle(this.NameMarqueeStyle);
	}
	else{
		this.LayerArray[this.NameLayerIndex].SetTextStyle(this.NameStyle[ITEM_STATE.HIGHLIGHT]);
	}
	
}

ChatHistoryItem.prototype.ChangeLayerForNormal = function() {

    alert("ChatHistoryItem.ChangeLayerForNormal()");    

	this.LayerArray[this.BoxLayerIndex].SetStyle(this.BoxStyle[ITEM_STATE.NORMAL]);	
	this.LayerArray[this.BoxLayerIndex].SetImage(g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_NORMAL_THUMBNALE_BOX);
	this.LayerArray[this.AvatarLayerIndex].SetStyle(this.AvatarStyle[ITEM_STATE.NORMAL]);
	this.SetSmallAvatar();
    this.LayerArray[this.OnlieStatusLayerIndex].SetStyle(this.OnlineStyle[ITEM_STATE.NORMAL]);	
	this.LayerArray[this.TimeLayerIndex].SetStyle(this.TimeStyle[ITEM_STATE.NORMAL]);		
    this.LayerArray[this.MsgBallonLayerIndex].SetStyle(this.MsgBallonStyle[ITEM_STATE.NORMAL]);    	
	this.LayerArray[this.NameLayerIndex].SetTextStyle(this.NameStyle[ITEM_STATE.NORMAL]);
}

ChatHistoryItem.prototype.SetItem = function(DataObject) {
	
	alert("ChatHistoryItem.SetItem()");

	//1.UserName
	var Name;
	
	//this.IS_Group_Chat = DataObject.IS_MultiChat;
	
	if(DataObject.IS_MultiChat){
		
		this.IsMultiChat = true;
		Name = DataObject.Participants;
	}
	else {
		
		this.IsMultiChat = false;
		Name = DataObject.UserDisplayName;
	}
	
	alert("UserName = " + Name);
	this.DisplayName = Name;
	this.LayerArray[this.NameLayerIndex].SetText(Name);
	
	//2.Time
	alert("Time = " + DataObject.Time);
	this.LayerArray[this.TimeLayerIndex].SetText(DataObject.Time);
	
	//3,Avatar
	alert("AvatarType = " + DataObject.AvatarType);
	this.AvatarType = DataObject.AvatarType;
	this.LayerArray[this.AvatarLayerIndex].SetImage(DataObject.AvatarPath);
	
	//4.Availablity
	var Online;

	if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.GROUP ) {		
		
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_GROUP;		
	}
	//ONLINE	
	else if(DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.ONLINE || 
		DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.ONLINE_FROM_MOBILE) {
					
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_ONLINE;
	}
	//OFFLINE
	else if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.OFFLINE ||
		DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.NOT_AVAILABLE_FROM_MOBILE) {
			
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_OFFLINE;
	}
	//AWAY 
	else if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.AWAY ||
		DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.AWAY_FROM_MOBILE){
			
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_AWAY;
	}
	//DO_NOT_DISTURB	
	else if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.DO_NOT_DISTURB ||
		DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.DO_NOT_DISTURB_FROM_MOBILE){
			
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_DO_NOT_DISTURB;
	}
	//CALL_FORWARDING or VOICEMAIL ABLE
	else if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.OFFLINE_BUT_CF_ABLE ||
		DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.OFFLINE_BUT_VM_ABLE) {
			
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_AVAILABLE;
	}
	//UNKNOWN	
	else if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.PENDINGAUTH ||
		DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.UNKNOWN) {
			
		//IMAGE_MOIP_CONTACT_WND_UNKNOWN_STATUS			
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_OFFLINE;

	}
	//BLOCKED & BLOCKED_SKYPEOUT
	else if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.BLOCKED ||
		DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.BLOCKED_SKYPEOUT) {
			
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_BLOCKED;
	}
	//SKYPE_ME
	else if (DataObject.Availablity == ENUM_CONTACT_AVAILABILITY.SKYPE_ME ) {		
		//Check ????	
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_AVAILABLE;
		
	}	
	else{		
		alert("HistoryDataObject.Availablity is null");
		Online = g_Image.IMAGE_ONLINE_STATUS_PRESENCE_OFFLINE; 
	}	
	
	this.LayerArray[this.OnlieStatusLayerIndex].SetImage(Online);


	//5.New Massage Num
	var NewChatNumber = DataObject.NewChatNum;
	 
	if(NewChatNumber == 0){

		$("#"+ this.LayerArray[this.MsgBallonLayerIndex].Obj).css('display', 'none');		
	}
	else{
		
		$("#"+ this.LayerArray[this.MsgBallonLayerIndex].Obj).css('display', 'block');
		
		if(NewChatNumber > 999){
		
			NewChatNumber = 999;			
		}
		
		this.LayerArray[this.MsgNumberLayerIndex].SetText(NewChatNumber);
	}
		
	this.ChatName			= DataObject.ChatName;
	this.ParticipantName	= DataObject.Participants;
	this.HostIdentyName		= DataObject.UserName;
	this.HostDisplayName	= DataObject.UserName;;
				
	this.ExistData = true;
}


ChatHistoryItem.prototype.GetChatName = function() {
	
	return this.ChatName;
	
}

ChatHistoryItem.prototype.GetParticipantName = function() {
	
	return this.ParticipantName;
	
}

ChatHistoryItem.prototype.GetIsMultiChat = function() {
	
	return this.IsMultiChat;
	
}

ChatHistoryItem.prototype.GetIdentity = function(){

    return this.ChatName;
}

ChatHistoryItem.prototype.GetIdentityName = function(){

    return this.HostIdentyName;
}

ChatHistoryItem.prototype.GetDisplayName = function(){

    return this.HostDisplayName;
}

ChatHistoryItem.prototype.SetSmallAvatar = function() {
	
	
	if(this.AvatarType == ENUM_CHAT_HISTORY_AVATAR_TYPE.ONES_IMAGE){
		alert("AvatarType is ONES_IMAGE");
		return;
	}
	
	var Avatar;
	
	switch(this.AvatarType) {

		case ENUM_CHAT_HISTORY_AVATAR_TYPE.NO_IMAGE:
			Avatar = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_MYSELF;	
			break;
		
		case ENUM_CHAT_HISTORY_AVATAR_TYPE.GROUP:
			Avatar = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_GROUP;	
			break;
		
		default :
			Avatar = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_NO_GENDER_BIG;	
			break;	
			
	}
	
	this.LayerArray[this.AvatarLayerIndex].SetImage(Avatar);
	
}

ChatHistoryItem.prototype.SetBigAvatar = function() {
	
	if(this.AvatarType == ENUM_CONTACT_AVATA_TYPE.ONES_IMAGE){
		alert("AvatarType is ONES_IMAGE");
		return;
	}
	
	var Avatar;
	
	switch(this.AvatarType) {

		case ENUM_CHAT_HISTORY_AVATAR_TYPE.NO_IMAGE:
			Avatar = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_MYSELF_BIG;	
			break;
		
		case ENUM_CHAT_HISTORY_AVATAR_TYPE.GROUP:
			Avatar = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_GROUP_BIG;	
			break;

		default :
			Avatar = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_NO_GENDER_BIG;	
			break;	
			
	}
	
	this.LayerArray[this.AvatarLayerIndex].SetImage(Avatar);
	
}
