
var NEW_ITEM_STATE = { 
 	
 	UNDATA			:   0,			//Hide & not move 
    NORMAL			:   1,
	NORMAL_UP		:	2,
	NORMAL_DOWN		:	2,	
    HIGHLIGHT		:   3,
    SELECT			:   4,
    DIM				:   5,
    DIM_UP			:   6,
    DIM_DOWN		:   7,
	MAX				:	8
}



/*
 * 
 * InputTextData[1].text
 * InputTextData[1].styleArray[NEW_ITEM_STATE.MAX]
 * 
 * 
 * InputImageData[1].ImageUrl
 * InputImageData[1].styleArray[NEW_ITEM_STATE.MAX]
 * 
 */


function NewListItem() {
    
    //flag
    this.State		= ITEM_STATE.UNDATA;  
	this.ExistData	= false;
	    
    this.InputTextData	= new Array();
    this.InputImageData	= new Array();

	//Style
	this.BGUrl = new Array();	
	this.BGStyle = new Array();	


    //ITEM
    this.ItemID				= -1; 
    this.TotalImageLayer	= 0;
    this.TotalTextLayer		= 0;
    this.StartIndexOfText	= -1;
    this.StartIndexOfImage	= -1;
	    

    CompBase.call(this);
}


NewListItem.prototype = new CompBase(); 

NewListItem.prototype.Create = function(eName,ItemIndex,TextLayerNum,ImageLayerNum)
{    
	//SceneDiv
    alert("ListItem.Create()");

    this.CreateBG(eName);
    
	this.ItemID = ItemIndex;
    
    this.TotalImageLayer	= ImageLayerNum;
    this.TotalTextLayer		= TextLayerNum;
        
    this.CreateTextLayer(TextLayerNum);
    this.CreateImageLayer(ImageLayerNum);
	
}


NewListItem.prototype.CreateTextLayer = function(LayerNum)
{  
	//Set start Index
	this.StartIndexOfImage = this.LayerArray.length; 
	
	var ElementStr;	
	for (var i=0; i < LayerNum; i++) 
	{
		ElementStr = this.BGLayerObj + "Text" + i;
		
		this.CreateDiv(ElementStr);
		this.AddTextLayer(ElementStr);
		//create new array
		this.ItemStyle[i] = new Array(ITEM_STATE.MAX);		
	}

}

NewListItem.prototype.CreateImageLayer = function(LayerNum)
{  
	//Set start Index
	this.StartIndexOfImage = this.LayerArray.length; 
	
	var ElementStr;	
	for (var i=0; i < LayerNum; i++) 
	{
		ElementStr = this.BGLayerObj + "Text" + i;

		this.CreateDiv(ElementStr);
		this.AddImageLayer(ElementStr);
		//create new array
		this.ItemStyle[i] = new Array(ITEM_STATE.MAX);		
	}

}

NewListItem.prototype.CreateDiv = function(DivName)
{
	var ItemHTML = "<div id = '" + DivName + "'>" + "</div>";
	    
    $("#"+this.BGLayerObj).append(ItemHTML);
    
    alert("Create Div tag --> " + DivName);
}

NewListItem.prototype.SetItemID = function(nID) {

    this.ItemID = nID;
}

NewListItem.prototype.GetItemID = function() {

    return this.ItemID;
}


NewListItem.prototype.SetBgImage = function(ItemState, BgUrl){
     
	if (BgUrl) {
		this.BGUrl[ItemState] = BgUrl;
				
		if(ItemState == ITEM_STATE.NORMAL) {	
			this.LayerArray[this.BGLayerIndex].SetImage(BgUrl);	
		}
		
	}

}

NewListItem.prototype.SetBgStyle = function(ItemStateIndex, BgStyle){
    	
	this.BGStyle[ItemStateIndex] = BgStyle;
	
	if(ItemStateIndex == ITEM_STATE.NORMAL) {	
		this.LayerArray[this.BGLayerIndex].SetStyle(BgStyle);	
	}
    
}

NewListItem.prototype.SetTextLayerStyle = function(TextIndex, ItemState,LayerStyle){
    	
    	
	if(this.InputTextData[TextIndex] == null)
	{
		alert("create InputTextData[" + TextIndex + "]");
		this.InputTextData[TextIndex] = new Object;	
		this.InputTextData[TextIndex].styleArray = new Array(NEW_ITEM_STATE.MAX);		
	}    	

	this.InputTextData[TextIndex].styleArray[ItemState] = LayerStyle;
	
	if(ItemStateIndex == ITEM_STATE.NORMAL) {	
		this.LayerArray[StartIndexOfText + TextIndex].SetStyle(Style);	
	}
    
}

NewListItem.prototype.SetImageLayerStyle = function(ImageIndex, ItemState,LayerStyle){
    	
    	
	if(this.InputImageData[ImageIndex] == null)
	{
		alert("create InputTextData[" + ImageIndex + "]");
		this.InputImageData[ImageIndex] = new Object;	
		this.InputImageData[ImageIndex].styleArray = new Array(NEW_ITEM_STATE.MAX);		
	}    	

	this.InputImageData[ImageIndex].styleArray[ItemState] = LayerStyle;
	
	if(ItemStateIndex == ITEM_STATE.NORMAL) {	
		this.LayerArray[StartIndexOfText + TextIndex].SetStyle(Style);	
	}
    
}


NewListItem.prototype.SetTextLayerItem = function(TextIndex,TextStr){
	
	if(this.InputTextData[TextIndex] == null)
	{
		alert("create InputTextData[" + TextIndex + "]");
		this.InputImageData[TextIndex] = new Object;		
	}	
						
	this.InputTextData[TextIndex].text = TextStr;
	
	this.LayerArray[StartIndexOfText + TextIndex].SetText(CTextStr);	
		
}

NewListItem.prototype.SetImageLayerItem = function(ImageIndex,ImageUrl){
	
	if(this.InputImageData[ImageIndex] == null)
	{
		alert("create InputImageData[" + ImageIndex + "]");
		this.InputImageData[ImageIndex] = new Object;	
		
	}	
							
	this.InputImageData[ImageIndex].ImageUrl = ImageUrl;
	
	this.LayerArray[StartIndexOfImage + TextIndex].SetImage(ImageUrl);	
		
}


NewListItem.prototype.SetDataType = function(nDataType){
    	
	this.ItemDataType = nDataType;
    
}

NewListItem.prototype.GetState = function() {

    return this.State;
    
}

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

NewListItem.prototype.UpNormal = function() {
	
    this.State = ITEM_STATE.NORMAL_UP;
	this.ChangeBG();
	this.ChangeItem();
}

NewListItem.prototype.DownNormal = function() {
	
    this.State = ITEM_STATE.NORMAL_DOWN;
	this.ChangeBG();
	this.ChangeItem();
}

NewListItem.prototype.Highlight = function() {
	
	this.State = ITEM_STATE.HIGHLIGHT;
	this.ChangeBG();
	this.ChangeItem();
}

NewListItem.prototype.Select = function() {
    
	this.State = ITEM_STATE.SELECT;
	this.ChangeBG();
	this.ChangeItem();
}


NewListItem.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])
			{
				this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[ITEM_STATE.NORMAL]);
			}			 
			break;
			
		case ITEM_STATE.NORMAL_UP:
			
			if(this.BGStyle[ITEM_STATE.NORMAL_UP])
			{
				alert("-- SetStyle()" );
				this.LayerArray[this.BGLayerIndex].SetStyle(this.BGStyle[ITEM_STATE.NORMAL_UP]);
			}
			if(this.BGUrl[ITEM_STATE.NORMAL])
			{
				alert("-- SetImage()" );
				this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[ITEM_STATE.NORMAL]);
			}	
						
			break;
			
		case ITEM_STATE.NORMAL_DOWN:
		
			if(this.BGStyle[ITEM_STATE.NORMAL_DOWN])
			{
				this.LayerArray[this.BGLayerIndex].SetStyle(this.BGStyle[ITEM_STATE.NORMAL_DOWN]);
			}
			if(this.BGUrl[ITEM_STATE.NORMAL])
			{
				this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[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])
			{
				this.LayerArray[this.BGLayerIndex].SetImage(this.BGUrl[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]);
			}						
			break;			
	}	
}

NewListItem.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]);
			}			
			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]);
			}				
						
			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]);
			}	
			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]);
			}				
			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]);
			}
			break;			
	}	
}



NewListItem.prototype.DisableReverse = function(){
	
	this.LayerArray[this.TextLayerIndex].SetReverseDisable(true);
}

