
var ITEM_DATA_TYPE = {
	CUSTOM : 0,
	TEXT_ONLY : 1,
	IMAGE_ONLY : 2,
	IMAGE_TEXT 	: 3, 
	FG_ONLY : 4,
	FG_TEXT 	: 5, 
	FG_BG_TEXT 	: 7 
};
var ITEM_SIZE_STYLE = {

	FIXED_SIZE : 0, 
	REMOVE_SIZE : 1,			
};
var ITEM_STATE = {
	NORMAL : 0,
	NORMAL_UP : 1,
	NORMAL_DOWN : 2,
	HIGHLIGHT : 3,
	SELECT : 4,
	MAX : 5
};

function ListItem() {

	this.ItemID = -1;

	this.State = ITEM_STATE.NORMAL;

	this.ItemDataType = ITEM_DATA_TYPE.CUSTOM;
	this.ImageLayerIndex = -1;
	this.FgImgLayerIndex = -1;
	this.TextLayerIndex = -1;

	this.BGUrl = new Array(ITEM_STATE.MAX);
	this.BGStyle = new Array(ITEM_STATE.MAX);

	this.FGUrl = new Array(ITEM_STATE.MAX);
	this.FGStyle = new Array(ITEM_STATE.MAX);

	//ItemStyle
	this.TextStyle = new Array(ITEM_STATE.MAX);
	this.ImageStyle = new Array(ITEM_STATE.MAX);
	this.FgImgStyle = new Array(ITEM_STATE.MAX);

	this.InputData = null;

	this.ExistData = false;
	//2013 add by minseok
	this.divide_flag = false;

	CompBase.call(this);
}

ListItem.prototype = new CompBase();

ListItem.prototype.Create = function(eName, flag) {

	alert("ListItem.Create()");

	this.CreateBG(eName, flag);
	if(flag) {
		this.divide_flag = true;
	}
	var ElementStr;

	if(this.ItemDataType & ITEM_DATA_TYPE.TEXT_ONLY) {
		ElementStr = eName + "Text";
		this.TextLayerIndex = this.LayerArray.length;
		this.AddTextLayer(ElementStr);
		alert("AddTextLayer(" + ElementStr + ")");
	}
	if(this.ItemDataType & ITEM_DATA_TYPE.IMAGE_ONLY) {
		alert("ListItem.Create()");
		ElementStr = eName + "Image";
		this.ImageLayerIndex = this.LayerArray.length;
		this.AddImageLayer(ElementStr);
		alert("AddImageLayer(" + ElementStr + ")");
	}
	if(this.ItemDataType & ITEM_DATA_TYPE.FG_ONLY) {
		alert("ListItem.Create()_FG_ONLY");
		ElementStr = eName + "Icon";
		this.FgImgLayerIndex = this.LayerArray.length;
		this.AddImageLayer(ElementStr);
		alert("AddImageLayer(" + ElementStr + ")");
	}
	this.Showstate = false;
}

ListItem.prototype.SetItemID = function(nID) {
	//alert("ListItem.SetItemID()");
	this.ItemID = nID;
}

ListItem.prototype.GetItemID = function() {

	return this.ItemID;
}

ListItem.prototype.SetFlagForExistData = function(flag) {

	this.ExistData = flag;
}

ListItem.prototype.GetFlagForExistData = function() {

	return this.ExistData;
}

ListItem.prototype.GetData = function() {
	return this.InputData;
}

ListItem.prototype.GetDataText = function() {

	if(this.ItemDataType & ITEM_DATA_TYPE.TEXT_ONLY) {
		return this.InputData[0];
	}
}

ListItem.prototype.GetDataImage = function() {

	if(this.ItemDataType & ITEM_DATA_TYPE.IMAGE_ONLY) {
		return this.InputData[1];
	}

}
ListItem.prototype.SetDivideBgImage = function(BgUrl) {
	alert("bgImage : " + BgUrl);
	if(BgUrl != null) {
		var result = BgUrl.indexOf('_center');
		var Url;
		if(result != -1) {
			Url = BgUrl.substring(0, result);

			alert("Url : " + Url);
		}
		this.BGLayer_center.SetImage(Url + "_center.png");
		this.BGLayer_left.SetImage(Url + "_left.png");
		this.BGLayer_right.SetImage(Url + "_right.png");
	}
}
ListItem.prototype.SetBgImage = function(ItemStateIndex, BgUrl) {

	this.BGUrl[ItemStateIndex] = BgUrl;

	if(ItemStateIndex == ITEM_STATE.NORMAL) {
		if(this.divide_flag) {
			this.SetDivideBgImage(BgUrl);
		} else {
			this.LayerArray[this.BGLayerIndex].SetImage(BgUrl);
		}

	}
}

ListItem.prototype.SetFgImage = function(ItemStateIndex, FgUrl) {

	this.FGUrl[ItemStateIndex] = FgUrl;

	if(ItemStateIndex == ITEM_STATE.NORMAL) {
		this.LayerArray[this.FgImgLayerIndex].SetImage(FgUrl);
	}

}

ListItem.prototype.SetBgStyle = function(ItemStateIndex, BgStyle) {

	this.BGStyle[ItemStateIndex] = BgStyle;

	if(ItemStateIndex == ITEM_STATE.NORMAL) {
		this.LayerArray[this.BGLayerIndex].SetStyle(BgStyle);
	}

}

ListItem.prototype.SetTextStyle = function(ItemStateIndex, Style) {

	this.TextStyle[ItemStateIndex] = Style;

	if(ItemStateIndex == ITEM_STATE.NORMAL) {
		this.LayerArray[this.TextLayerIndex].SetStyle(Style);
	}

}

ListItem.prototype.SetImageStyle = function(ItemStateIndex, Style) {

	this.ImageStyle[ItemStateIndex] = Style;

	if(ItemStateIndex == ITEM_STATE.NORMAL) {
		this.LayerArray[this.ImageLayerIndex].SetStyle(Style);
	}

}

ListItem.prototype.SetFgStyle = function(ItemStateIndex, Style) {

	this.FGStyle[ItemStateIndex] = Style;

	if(ItemStateIndex == ITEM_STATE.NORMAL) {
		this.LayerArray[this.FgImgLayerIndex].SetStyle(Style);
	}
}

ListItem.prototype.SetDataType = function(nDataType) {

	this.ItemDataType = nDataType;

}

ListItem.prototype.GetState = function() {

	return this.State;

}

ListItem.prototype.Normal = function() {

	alert("ListItem.Normal()");
	this.State = ITEM_STATE.NORMAL;
	this.ChangeBG();
	this.ChangeItem();
}

ListItem.prototype.UpNormal = function() {

	this.State = ITEM_STATE.NORMAL_UP;
	this.ChangeBG();
	this.ChangeItem();
}

ListItem.prototype.DownNormal = function() {

	this.State = ITEM_STATE.NORMAL_DOWN;
	this.ChangeBG();
	this.ChangeItem();
}

ListItem.prototype.Highlight = function() {

	this.State = ITEM_STATE.HIGHLIGHT;
	var index = this.BGLayerObj.indexOf("previousPhoneNumberList");
	if(index!=-1){
		this.ChangeBG();
		if(this.CheckMarquee()>19){
			this.LayerArray[this.TextLayerIndex].SetStyle("cPreviousPhoneNumberList_Text_Highlight_Marquee");
		}else{
			this.ChangeItem();
		}
	}else{
		this.ChangeBG();
		this.ChangeItem();
	}
}
ListItem.prototype.CheckMarquee = function(){
	var ObjId = this.LayerArray[this.TextLayerIndex].textObj;
	var str = $("#"+ObjId).text();
	return str.length;
	
}
ListItem.prototype.Select = function() {

	this.State = ITEM_STATE.SELECT;
	this.ChangeBG();
	this.ChangeItem();
}

ListItem.prototype.ChangeBG = function() {

	//alert("ListItem.ChangeBG()");

	switch(this.State) {

		case ITEM_STATE.NORMAL:
			if(this.BGStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.BGLayerIndex].SetStyle(this.BGStyle[ITEM_STATE.NORMAL]);
			}
			if(this.BGUrl[ITEM_STATE.NORMAL]) {
				//2013 modify by minseok
				if(this.divide_flag) {
					this.SetDivideBgImage(this.BGUrl[ITEM_STATE.NORMAL]);
				} else {
					this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[ITEM_STATE.NORMAL]);
				}
			}

			if(this.FGStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FGStyle[ITEM_STATE.NORMAL]);
			}
			if(this.FGUrl[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.FgImgLayerIndex].SetImage(this.FGUrl[ITEM_STATE.NORMAL]);
			}

			break;

		case ITEM_STATE.NORMAL_UP:

			if(this.BGStyle[ITEM_STATE.NORMAL_UP]) {

				if(this.BGStyle[ITEM_STATE.NORMAL_UP] != this.LayerArray[this.BGLayerIndex].GetStyle()) {
					//alert("================== SetStyle() NORMAL_UP /" + this.LayerArray[this.BGLayerIndex].GetStyle() + "/" + this.BGStyle[ITEM_STATE.NORMAL_UP]);
				this.LayerArray[this.BGLayerIndex].SetStyle(this.BGStyle[ITEM_STATE.NORMAL_UP]);
			}

			}
			if(this.BGUrl[ITEM_STATE.NORMAL]) {
				//alert("-- SetImage() NORMAL");
				//2013 modify by minseok
				if(this.divide_flag) {
					this.SetDivideBgImage(this.BGUrl[ITEM_STATE.NORMAL]);
				} else {
				this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[ITEM_STATE.NORMAL]);
			}
			}

			if(this.FGStyle[ITEM_STATE.NORMAL_UP]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FGStyle[ITEM_STATE.NORMAL_UP]);
			}
			if(this.FGUrl[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.FgImgLayerIndex].SetImage(this.FGUrl[ITEM_STATE.NORMAL]);
			}

			break;

		case ITEM_STATE.NORMAL_DOWN:

			if(this.BGStyle[ITEM_STATE.NORMAL_DOWN]) {
				if(this.BGStyle[ITEM_STATE.NORMAL_DOWN] != this.LayerArray[this.BGLayerIndex].GetStyle()) {
					//alert("================== SetStyle() NORMAL_DOWN /" + this.BGStyle[ITEM_STATE.NORMAL_DOWN] + "/" + this.LayerArray[this.BGLayerIndex].GetStyle());
				this.LayerArray[this.BGLayerIndex].SetStyle(this.BGStyle[ITEM_STATE.NORMAL_DOWN]);
			}
			}
			if(this.BGUrl[ITEM_STATE.NORMAL]) {
				//2013 modify by minseok
				if(this.divide_flag) {
					this.SetDivideBgImage(this.BGUrl[ITEM_STATE.NORMAL]);
				} else {
				this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[ITEM_STATE.NORMAL]);
			}
			}

			if(this.FGStyle[ITEM_STATE.NORMAL_DOWN]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FGStyle[ITEM_STATE.NORMAL_DOWN]);
			}
			if(this.FGUrl[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.FgImgLayerIndex].SetImage(this.FGUrl[ITEM_STATE.NORMAL]);
			}

			break;

		case ITEM_STATE.HIGHLIGHT:

			if(this.BGStyle[ITEM_STATE.HIGHLIGHT]) {
				this.LayerArray[this.BGLayerIndex].SetStyle(this.BGStyle[ITEM_STATE.HIGHLIGHT]);
			}
			if(this.BGUrl[ITEM_STATE.HIGHLIGHT]) {
				if(this.divide_flag) {
					this.SetDivideBgImage(this.BGUrl[ITEM_STATE.HIGHLIGHT]);
				} else {
					this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[ITEM_STATE.HIGHLIGHT]);
				}

			}

			if(this.FGStyle[ITEM_STATE.HIGHLIGHT]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FGStyle[ITEM_STATE.HIGHLIGHT]);
			}
			if(this.FGUrl[ITEM_STATE.HIGHLIGHT]) {
				this.LayerArray[this.FgImgLayerIndex].SetImage(this.FGUrl[ITEM_STATE.HIGHLIGHT]);
			}

			break;

		case ITEM_STATE.SELECT:

			if(this.BGStyle[ITEM_STATE.SELECT]) {
				this.LayerArray[this.BGLayerIndex].SetStyle(this.BGStyle[ITEM_STATE.SELECT]);
			}
			if(this.BGUrl[ITEM_STATE.SELECT]) {
				this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[ITEM_STATE.SELECT]);
			}

			if(this.FGStyle[ITEM_STATE.SELECT]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FGStyle[ITEM_STATE.SELECT]);
			}
			if(this.FGUrl[ITEM_STATE.SELECT]) {
				this.LayerArray[this.FgImgLayerIndex].SetImage(this.FGUrl[ITEM_STATE.SELECT]);
			}

			break;
	}
}

ListItem.prototype.ChangeItem = function() {

	alert("ListItem.ChangeItem()");

	switch(this.State) {

		case ITEM_STATE.NORMAL:
			if(this.TextStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.TextLayerIndex].SetStyle(this.TextStyle[ITEM_STATE.NORMAL]);
			}
			if(this.ImageStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.ImageLayerIndex].SetStyle(this.ImageStyle[ITEM_STATE.NORMAL]);
			}
			if(this.FgImgStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FgImgStyle[ITEM_STATE.NORMAL]);
			}
			break;

		case ITEM_STATE.NORMAL_UP:

			if(this.TextStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.TextLayerIndex].SetStyle(this.TextStyle[ITEM_STATE.NORMAL]);
			}
			if(this.ImageStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.ImageLayerIndex].SetStyle(this.ImageStyle[ITEM_STATE.NORMAL]);
			}
			if(this.FgImgStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FgImgStyle[ITEM_STATE.NORMAL]);
			}
			break;

		case ITEM_STATE.NORMAL_DOWN:

			if(this.TextStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.TextLayerIndex].SetStyle(this.TextStyle[ITEM_STATE.NORMAL]);
			}
			if(this.ImageStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.ImageLayerIndex].SetStyle(this.ImageStyle[ITEM_STATE.NORMAL]);
			}
			if(this.FgImgStyle[ITEM_STATE.NORMAL]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FgImgStyle[ITEM_STATE.NORMAL]);
			}
			break;

		case ITEM_STATE.HIGHLIGHT:

			if(this.TextStyle[ITEM_STATE.HIGHLIGHT]) {
				this.LayerArray[this.TextLayerIndex].SetStyle(this.TextStyle[ITEM_STATE.HIGHLIGHT]);
			}
			if(this.ImageStyle[ITEM_STATE.HIGHLIGHT]) {
				this.LayerArray[this.ImageLayerIndex].SetStyle(this.ImageStyle[ITEM_STATE.HIGHLIGHT]);
			}
			if(this.FgImgStyle[ITEM_STATE.HIGHLIGHT]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FgImgStyle[ITEM_STATE.HIGHLIGHT]);
			}
			break;

		case ITEM_STATE.SELECT:

			if(this.TextStyle[ITEM_STATE.SELECT]) {
				this.LayerArray[this.TextLayerIndex].SetStyle(this.TextStyle[ITEM_STATE.SELECT]);
			}
			if(this.ImageStyle[ITEM_STATE.SELECT]) {
				this.LayerArray[this.ImageLayerIndex].SetStyle(this.ImageStyle[ITEM_STATE.SELECT]);
			}
			if(this.FgImgStyle[ITEM_STATE.SELECT]) {
				this.LayerArray[this.FgImgLayerIndex].SetStyle(this.FgImgStyle[ITEM_STATE.SELECT]);
			}
			break;
	}
}

ListItem.prototype.SetItem = function(ContentsArray) {

	if(this.ItemDataType & ITEM_DATA_TYPE.TEXT_ONLY) {
		//alert("SetText(" + ContentsArray[0] + ")");
		this.LayerArray[this.TextLayerIndex].SetText(ContentsArray[0]);
	}

	if(this.ItemDataType & ITEM_DATA_TYPE.IMAGE_ONLY) {
		this.LayerArray[this.ImageLayerIndex].SetImage(ContentsArray[1]);
	}

	if(this.ItemDataType & ITEM_DATA_TYPE.FG_ONLY) {
		this.LayerArray[this.FgImgLayerIndex].SetImage(ContentsArray[2]);
	}

	this.InputData = ContentsArray;

	if(ContentsArray[0] == null && ContentsArray[1] == null && ContentsArray[2] == null) {
		this.ExistData = false;
	} else {
		this.ExistData = true;
	}

}

ListItem.prototype.DisableReverse = function() {

	this.LayerArray[this.TextLayerIndex].SetReverseDisable(true);
}