

var LIST_NAVI_STYLE = { 
    STYLE_ROTAION               :   0 , 
    STYLE_PAGE_SCROLL           :   1 ,
    STYLE_FIXED_HIGHLIGHT		:   2                                          
};
var LIST_SHAPE_STYLE = { 
    HORIZONTAL		: 0,
	VERTICAL		: 1
};

function List() {

    this.NaviStyle          = LIST_NAVI_STYLE.STYLE_ROTAION;	
	this.ShapeStyle			= LIST_SHAPE_STYLE.VERTICAL;					
	
	this.ItemSizeStyle		= ITEM_SIZE_STYLE.FIXED_SIZE;	
	this.ItemDataType		= ITEM_DATA_TYPE.CUSTOM;
	
	this.ItemBGUrl			= new Array(ITEM_STATE.MAX);
	this.ItemBGStyle		= new Array(ITEM_STATE.MAX);
	this.ItemFGUrl 			= new Array(ITEM_STATE.MAX);
	this.ItemFGStyle 		= new Array(ITEM_STATE.MAX);
	this.ItemTextStyle		= new Array(ITEM_STATE.MAX);
	this.ItemImageStyle		= new Array(ITEM_STATE.MAX);	
	
	this.ItemClass			= ListItem;
	
	this.ElimentName		= null;
	this.Eliment_bottom_Name		= null;

    this.BGLayer_top            = null;
    this.BGLayer            = null;
    this.BGLayer_bottom            = null;
   	
	//Item Management
	this.NumOfVisibleItem			= 0;		//sometimes changed
	this.MaxNumOfItem				= 0;		//always fixed	
	this.NumOfCreatedItem			= 0;		//almost fixed.
	this.CurrentItemIndex			= -1; 
	this.PrevItemIndex				= -1; 	
   
	
	//Data Management
	this.MaxNumOfData		= 0;
    this.CurrentDataIndex	= -1;  
	this.StartDataIndex		= -1;
    

    this.ShowState		= false;	
	this.Flag_Focus		= false;
	this.Flag_ClickEvent	= false;
	this.Flag_RightClick	= false;
	    
    //array
    this.DataArray = [];
    this.ItemArray = [];  
    this.OnClickFunc = [];     
    //2013 add by minseok : for mouseover/out func
    this.OnMouseOverFunc = [];
    this.OnMouseOutFunc = [];

	this.ItemPressedCallbackFunc = null;	    
	this.onReturnFunc	= null;
	this.onUpFunc		= null;
	this.onDownFunc		= null;
	this.onLeftFunc		= null;
	this.onRightFunc	= null;
	this.onExitFunc	= null;  
    
     this.helpBar = null;
     
    this.Flag_RTL = true;
    //2013 add by minseok
    this.divideBG_flag = false;
    this.divide_flag = false;
}

///2013 modify by minseok
List.prototype.CreateBG = function(Ename, flag) {

    alert("List.CreateBG(" + Ename + ")");
    if(Ename == null) {
        //alert("CListBase.CreateBG()  >>>   Param is null !!  ");
        return false;
    }
    if(flag){
    	this.divideBG_flag = flag;
    	if(this.divideBG_flag==true){
    		this.BGLayer_top = new ImageLayer(Ename+"_Top");
    		this.BGLayer_bottom	= new ImageLayer(Ename+"_Bottom");
    		this.Eliment_bottom_Name = Ename+"_Bottom";
    	}else if(flag=="divide"){
    		this.divideBG_flag = false;
    		this.divide_flag = true;
    	}
    	
    	
    }
	this.ElimentName = Ename;
	
    this.BGLayer = new ImageLayer(Ename);
	        
}

///2013 modify by minseok
List.prototype.SetBGImage = function(ImageUrl) {

    alert("List.SetBGImage()--> imageurl : "+ImageUrl);

	this.BGLayer.SetImage(ImageUrl);
	if(this.divideBG_flag==true){
		var result = ImageUrl.indexOf("_center");
		var Url = ImageUrl.substring(0,result);
		alert("List.SetBGImage()--> url : "+Url);	
    	this.BGLayer_top.SetImage(Url+'_top.png');
    	this.BGLayer_bottom.SetImage(Url+'_bottom.png');
    }
}

List.prototype.SetItemBgImage = function(ItemState,ImageUrl) {

    alert("List.SetItemBgImage()");
	this.ItemBGUrl[ItemState] = ImageUrl;
}

List.prototype.SetItemBgStyle = function(ItemState,Style) {

    alert("List.SetItemBgStyle()");
	this.ItemBGStyle[ItemState]	= Style;
}

List.prototype.SetItemFgImage = function(ItemState,ImageUrl) {

    alert("List.SetItemFgImage()");
	this.ItemFGUrl[ItemState] = ImageUrl;
}

List.prototype.SetItemFgStyle = function(ItemState,Style) {

    alert("List.SetItemFgStyle()");
	this.ItemFGStyle[ItemState]	= Style;
}

List.prototype.SetDataType = function(nItemDataType) {

    alert("List.SetDataType()");
	this.ItemDataType = nItemDataType;
}

List.prototype.SetItemDefualtTextStyle = function(ItemState,Style) {

    alert("List.SetItemDefualtTextStyle()");
	this.ItemTextStyle[ItemState]	= Style;
}

List.prototype.SetItemDefualtImageStyle = function(ItemState,Style) {

    alert("List.SetItemDefualtImageStyle()");
	this.ItemImageStyle[ItemState]	= Style;
}


List.prototype.SetItemClass = function(cItemClass) {

 	alert("List.SetItemClass()");
	this.ItemClass = cItemClass;

}

List.prototype.SetItemSizeStyle = function(nFlag) {

	this.ItemSizeStyle = nFlag;

}
List.prototype.GetElimentName = function(){
	return this.ElimentName; 
}
List.prototype.GetElimentBottomName = function(){
	return this.Eliment_bottom_Name;
}

	
List.prototype.GetBGLayer = function() {

	return this.BGLayer;

}

List.prototype.SetStartDataIndex = function(nIndex) {

	this.StartDataIndex = nIndex;
	this.CurrentDataIndex = nIndex;
}

List.prototype.SetCurrDataIndex = function(nIndex) {

	this.CurrentDataIndex = nIndex;
}

List.prototype.GetMaxNumOfData = function(){

	return this.MaxNumOfData;
}

//TESTCODE:
List.prototype.SetMaxNumOfData = function(NumOfData){

	this.MaxNumOfData = NumOfData;
}

List.prototype.SetClickEventAvailable = function(bFlag , rightClick){

	this.Flag_ClickEvent = bFlag;
	
	if(rightClick)
	{
		this.Flag_RightClick = rightClick
	}
}

List.prototype.DisableReverse = function(){

	this.Flag_RTL = false;
}


//click  option 
List.prototype.ShowItem = function(){
	//if(this.Flag_Init == false) {
	
	alert("List.ShowItem()");

		
 	for (var i=0; i < this.MaxNumOfItem; i++) {	
	
		//alert("ItemArray[" + i +"].GetFlagForExistData = " +this.ItemArray[i].GetFlagForExistData() );
		//alert("ItemArray[" + i +"].GetShowState = " + this.ItemArray[i].GetShowState() );
		
		if(this.ItemArray[i] == null){
			break;			
		}
		
		if(this.ItemArray[i].GetFlagForExistData() == true && this.ItemArray[i].GetShowState() == false) {
			alert("ItemArray[" + i + "].Show");
			this.ItemArray[i].Show();	
		}
		else if(this.ItemArray[i].GetFlagForExistData() == false && this.ItemArray[i].GetShowState() == true){
			alert("ItemArray[" + i + "].Hide");
			this.ItemArray[i].Hide();
		}			
		
		//add click event		
		if(this.Flag_ClickEvent == true) {
			alert("Flag_ClickEvent on -- " + i);
			if(this.ItemArray[i].GetShowState() == true) {
				this.SetClickEvent(i);
			}
			//remove click event
			else {
				this.ResetClickEvent(i);
			}			
		}
		//add mouseover/out event
		this.SetMouseOverEvent(i);
		this.SetMouseOutEvent(i);
		//remove RTL
		if(this.Flag_RTL == false) {
			alert("Flag_RTL on -- " + i);
			this.ItemArray[i].DisableReverse();
		}
	}	
}
//not completed function... need more process 
List.prototype.HideItem = function(){
	alert("List.HideItem()");
	for (var i=0; i < this.MaxNumOfItem; i++) {	
	
		//alert("ItemArray[" + i +"].GetFlagForExistData = " +this.ItemArray[i].GetFlagForExistData() );
		//alert("ItemArray[" + i +"].GetShowState = " + this.ItemArray[i].GetShowState() );
		
		if(this.ItemArray[i] == null){
			break;			
		}
		if(this.ItemArray[i].GetShowState() == true){
			alert("ItemArray[" + i + "].Hide");
			this.ItemArray[i].Hide();
		}
		
	}
}
List.prototype.Show = function() {

	alert("List.Show()");
	
	if(this.ShowState == false){

		$("#"+ this.BGLayer.Obj).css('display', 'block');		
		this.ShowState = true;				
	}

}

List.prototype.Hide = function() {

	alert("List.Hide()");

	if(this.ShowState == true){
		
		$("#"+ this.BGLayer.Obj).css('display', 'none');
		this.ShowState = false;	
	}	
}



List.prototype.GetShowState = function() {
		 
     return this.ShowState;

}


List.prototype.SetNumOfVisibleItem = function(NumOfItems) {

    alert("List.SetNumOfVisibleItem()");
	this.MaxNumOfItem = NumOfItems;
			
}

List.prototype.SetShapeStyle = function(ShapeStyle) {

    alert("List.SetShapeStyle()");
	this.ShapeStyle = ShapeStyle;	
}
//9.27 added
List.prototype.CurrentItemInit = function() {
	alert("List.CurrentItemInit");
    	for (var i=0; i < this.NumOfVisibleItem; i++) {
				this.ItemArray[i].DownNormal();
	}
}
List.prototype.SetCurrentItem = function(ItemIndex) {
	
	alert(" >>>>>>>>>>>>  List.SetCurrentItem( from " + this.CurrentItemIndex + " to "  + ItemIndex + ")");

	//exception....

	if(ItemIndex != -1 && this.ItemArray[ItemIndex] == null) {
		alert(" ItemArray["+ ItemIndex  + "] is null !!");
		return; 		
	}

	if (this.ItemSizeStyle == ITEM_SIZE_STYLE.REMOVE_SIZE) {
	
		if(this.CurrentItemIndex == -1){
			alert("if(this.CurrentItemIndex == -1)");
			alert(" init state >> " + this.NumOfCreatedItem + "Items initialize");
			
			
			for (var i=0; i < ItemIndex; i++) {
				this.ItemArray[i].UpNormal();
			}
			for (var i=ItemIndex; i < this.NumOfCreatedItem; i++) {
				this.ItemArray[i].DownNormal();
			}	
		}
		else {

			if (this.CurrentItemIndex <= ItemIndex) {
				alert("CurrentItemIndex <= ItemIndex");
				alert(" this.CurrentItemIndex = "+ this.CurrentItemIndex+"/ItemIndex = "+ItemIndex);
				for (var i=0; i < ItemIndex; i++) {
					this.ItemArray[i].UpNormal();
				}
				for (var i=ItemIndex; i < this.NumOfVisibleItem; i++) {
					this.ItemArray[i].DownNormal();
				}
				
			}
			else if (this.CurrentItemIndex > ItemIndex) {
					alert("CurrentItemIndex > ItemIndex");
					if(ItemIndex==-1){		//initialize
						for (var i=0; i < this.NumOfVisibleItem; i++) {
							this.ItemArray[i].UpNormal();
						}
						return;
					}
					for (var i = 0; i < ItemIndex; i++) {
						this.ItemArray[i].UpNormal();
					}
					for (var i=ItemIndex; i < this.NumOfCreatedItem; i++) {
						this.ItemArray[i].DownNormal();
					}
				}
		}	
			
	}
	else {
		
		if(this.CurrentItemIndex == -1){
			alert(" =>>>>>>>>>>>>>>>init state .................................");
			for (var i=0; i < this.NumOfVisibleItem; i++) {
				this.ItemArray[i].Normal();
			}
		}		
		//NumOfVisibleItem >>  createdItem
		else if(this.CurrentItemIndex > -1 && this.CurrentItemIndex < this.NumOfCreatedItem)
		{
			alert(" ItemArray["+ ItemIndex  + "] is normal");
			this.ItemArray[this.CurrentItemIndex].Normal();
		}
		
	}
		
	this.CurrentItemIndex = ItemIndex;
	//case -1 : initialization
	if(ItemIndex > -1 &&this.Flag_Focus){
		
		this.ItemArray[ItemIndex].Highlight();	
	}

}

//use
List.prototype.SetCurrentDataIndex = function(index) {
	
	//alert("List.GetCurrentDataIndex() = " + this.CurrentDataIndex);
    this.CurrentDataIndex = index;
}
List.prototype.GetCurrentDataIndex = function() {
	
	//alert("List.GetCurrentDataIndex() = " + this.CurrentDataIndex);
    return this.CurrentDataIndex;
}

List.prototype.GetCurrentInputData = function() {
	
	if(this.ItemDataType == ITEM_DATA_TYPE.TEXT_ONLY){
		
		return this.ItemArray[this.CurrentItemIndex].GetDataText();
	}
	else if(this.ItemDataType == ITEM_DATA_TYPE.IMAGE_ONLY){
		
		return this.ItemArray[this.CurrentItemIndex].GetDataImage();
	}
	else{
		return this.ItemArray[this.CurrentItemIndex].GetData();
	}
    
}



List.prototype.GetCurrentItem = function() {

    return this.CurrentItemIndex;
}

List.prototype.GetStartDataIndex = function() {

    return this.StartDataIndex;
}

List.prototype.GetNumOfCreatedItem = function() {

    return this.NumOfCreatedItem;
}

List.prototype.ChangeData = function(DataIndex,DataObject) {

	this.DataArray[DataIndex] = DataObject;    
	
	if(DataIndex >= this.StartDataIndex && DataIndex < this.StartDataIndex + this.NumOfVisibleItem ){
				
		this.ItemArray[DataIndex - this.StartDataIndex].SetItem(DataObject);
	}
	
}

 
List.prototype.DeleteData = function(DataIndex) {
    
    //DataArray[ItemIndex].Delete();
	this.DataArray.splice(this.DataIndex,1);
	this.MaxNumOfData--;
	
}

List.prototype.DeleteDataAll = function() {

	alert("List.DeleteDataAll ");
	
	if(this.MaxNumOfData == 0){
		alert("can't delete data because no data!!! ");
		return;
	}
	
	
	this.DataArray.splice(0,this.MaxNumOfData);

	this.MaxNumOfData		= 0;
    this.CurrentDataIndex	= -1;  
	this.StartDataIndex		= -1;
	
	for (var i=0; i < this.NumOfCreatedItem; i++) {
	
		this.ItemArray[i].SetFlagForExistData(false); 	
	}
	
	this.NumOfVisibleItem = 0;


}

List.prototype.AddData = function(DataObject){

	alert("List.AddData");
	this.DataArray.push(DataObject);
	this.MaxNumOfData++;
	//if divide List, adjust BG size and axis
	if(this.divideBG_flag==true){
		var bottom_top = $("#"+this.Eliment_bottom_Name).css('top').replace(/[^-\d\.]/g, '');
		var center_height = $("#"+this.ElimentName).css('height').replace(/[^-\d\.]/g, '');
		alert("current top is : "+bottom_top);
		alert("current height is : "+center_height);
		var top = parseInt(bottom_top)+48;
		var height = parseInt(center_height)+48;
		$("#"+this.Eliment_bottom_Name).css('top',top);
		$("#"+this.ElimentName).css('height',height);
		
	}
	
	if(this.MaxNumOfData <= this.NumOfCreatedItem ){
		
		//Added Data's Index
		var CurItemIndex = this.MaxNumOfData - 1;
		this.ItemArray[CurItemIndex].SetItem(DataObject);
		this.NumOfVisibleItem++;
	}
	//Case 2: Create Item
	else if (this.NumOfCreatedItem < this.MaxNumOfItem ) {
		
		
		var CurItemIndex = this.NumOfCreatedItem;	
		var ItemEname = this.ElimentName + "Item";

		alert("ItemArray["+ CurItemIndex +"] create");
		var cItem = this.ItemClass;
		this.ItemArray[CurItemIndex] = new cItem();	
		this.ItemArray[CurItemIndex].SetDataType(this.ItemDataType);

		this.ItemArray[CurItemIndex].SetItemID(CurItemIndex);	
		if(this.divide_flag==true){
			this.ItemArray[CurItemIndex].Create(ItemEname + (CurItemIndex + 1),30);	
		}else{
			this.ItemArray[CurItemIndex].Create(ItemEname + (CurItemIndex + 1));
		}
			
	
		
		//init style when layer is default layer style...
		if(this.ItemDataType != ITEM_DATA_TYPE.CUSTOM){
			for (var i=0; i < ITEM_STATE.MAX; i++) {
				
				if(this.ItemBGUrl[i]){
					
					this.ItemArray[CurItemIndex].SetBgImage(i,this.ItemBGUrl[i]);
				}	
				if(this.ItemBGStyle[i]){
					this.ItemArray[CurItemIndex].SetBgStyle(i,this.ItemBGStyle[i]);
				}

				if(this.ItemFGUrl[i]){
					this.ItemArray[CurItemIndex].SetFgImage(i,this.ItemFGUrl[i]);
				}	
				if(this.ItemFGStyle[i]){
					this.ItemArray[CurItemIndex].SetFgStyle(i,this.ItemFGStyle[i]);
				}

				if(this.ItemTextStyle[i])	
				{
					alert("ItemTextStyle >> ItemTextStyle [" + i + "]");
					this.ItemArray[CurItemIndex].SetTextStyle(i,this.ItemTextStyle[i]);
				}
				
				if(this.ItemImageStyle[i])	
				{
					alert("ItemTextStyle >> ItemImageStyle [" + i + "]");
					this.ItemArray[CurItemIndex].SetImageStyle(i,this.ItemImageStyle[i]);
				}				
					
			}
				
		}
			

		this.ItemArray[CurItemIndex].SetItem(DataObject);
		this.NumOfCreatedItem++;
		this.NumOfVisibleItem++;

	}
		
	
}

List.prototype.ResetData = function(nDataIndex,DataObject){
	
	this.DataArray[nDataIndex] = DataObject;	
}
 
List.prototype.KeyProcess = function (keyCode, f_simplex) {
  
	alert("List.KeyProcess");
	PluginAPIMgr.PlayAudio(keyCode);
	
	switch(keyCode){
		case sf.key.UP:
			if(this.ShapeStyle == LIST_SHAPE_STYLE.VERTICAL){
				this.Previous(f_simplex);				
			}
			else if(this.ShapeStyle == LIST_SHAPE_STYLE.HORIZONTAL && this.onUpFunc){					
				this.onUpFunc();					
			}			         
			break;    
			
		case sf.key.LEFT:
			if(this.ShapeStyle == LIST_SHAPE_STYLE.HORIZONTAL){
				this.Previous(f_simplex);
			}
			else if(this.ShapeStyle == LIST_SHAPE_STYLE.VERTICAL && 
				this.onLeftFunc){					
				this.onLeftFunc();					
			}
			break;  
			
		case sf.key.DOWN:
			if(this.ShapeStyle == LIST_SHAPE_STYLE.VERTICAL){
				this.Next(f_simplex);
			}
			else if(this.ShapeStyle == LIST_SHAPE_STYLE.HORIZONTAL && 
				this.onDownFunc){					
				this.onDownFunc();					
			}				
			break;
			
		case sf.key.RIGHT:
			if(this.ShapeStyle == LIST_SHAPE_STYLE.HORIZONTAL){
				this.Next(f_simplex);
			}
			else if(this.ShapeStyle == LIST_SHAPE_STYLE.VERTICAL && this.onRightFunc){					
				this.onRightFunc();					
			}				                     
			break;                            

		case sf.key.ENTER:
			alert("KEY_ENTER");
			if(this.ItemPressedCallbackFunc){
				this.ItemPressedCallbackFunc();
			}			
			break;			
                   
		case sf.key.RETURN:
			alert("KEY_RETURN");
			if(this.onReturnFunc){
				this.onReturnFunc();
			}
			//2013 modify by minseok
            sf.key.preventDefault();
			break;	
			
		case sf.key.EXIT:
			alert("KEY_EXIT");
			if(this.onExitFunc){
				this.onExitFunc();
			}
			//2013 modify by minseok
            sf.key.preventDefault();
			break;
			
		default:
			//2013 modify by minseok
            sf.key.preventDefault();
			break;
    }

} 
 

List.prototype.Next = function(){
	alert("List.Next()");
	
	if(this.MaxNumOfData < 2){
		alert(" this.MaxNumOfData < 2 ");
		return;
	}
	
	var CurItemIndex = 	this.CurrentItemIndex + 1;

	this.CurrentDataIndex++;
	
	//to next page	
	if(CurItemIndex == this.NumOfVisibleItem ) {
		
		alert("move to top");
		CurItemIndex = 0;		
			
		//case: Multi Page 
		if(this.MaxNumOfItem <  this.MaxNumOfData ) 
		{
			alert("Page scroll ");
			this.StartDataIndex += this.MaxNumOfItem;
			
			//from last page to 1st page 
			if(this.StartDataIndex > this.MaxNumOfData -1 ) {
		
				this.StartDataIndex = 0;
				this.CurrentDataIndex = 0;
			}
			
			this.UpdatePage();			
		}
		else
		{
			this.CurrentDataIndex = 0;
		}		
	}

	alert("CurrentDataIndex = " + this.CurrentDataIndex);
	this.SetCurrentItem(CurItemIndex);	
}

List.prototype.Previous = function(){
	alert("List.Previous()");
	
	if(this.MaxNumOfData < 2){
		alert(" this.MaxNumOfData < 2 ");
		return;
	}	
	
	var CurItemIndex = 	this.CurrentItemIndex - 1;
	//set data index
	this.CurrentDataIndex--;
			
	if(CurItemIndex == -1 ) {				
		alert("Page scroll");
				
		//case1 : Multi Page 
		if (this.MaxNumOfItem < this.MaxNumOfData) {
						
			this.StartDataIndex -= this.MaxNumOfItem;
			
			//from 1st page to last page
			if(this.StartDataIndex < 0 ) {
			
				var NumOfDataInLastPage = this.MaxNumOfData % this.MaxNumOfItem;
				
				if(NumOfDataInLastPage > 0) {
					
					this.StartDataIndex = this.MaxNumOfData - NumOfDataInLastPage;
				}
				else {
					
					this.StartDataIndex = this.MaxNumOfData - this.MaxNumOfItem;
				}
												
				this.CurrentDataIndex = this.MaxNumOfData - 1;
			}		
			
			//Set NumOfVisibleItem
			this.UpdatePage();
			CurItemIndex = this.NumOfVisibleItem - 1;	
		}
		//case2 : Single page
		else{
			
			CurItemIndex = this.NumOfVisibleItem - 1;
			this.CurrentDataIndex = CurItemIndex;
		}
		//set Data Index whatever single or multi page
						
	}
	
	alert("CurrentDataIndex = " + this.CurrentDataIndex);
	this.SetCurrentItem(CurItemIndex);		
}

//for mouse
List.prototype.MoveItem = function(ItemIndex)
{
	alert("List.MoveItem()");

	alert("ItemIndex = " + ItemIndex);
	alert("CurrentDataIndex = " + this.CurrentDataIndex);
	alert("CurrentItemIndex = " + this.CurrentItemIndex);
		
	if(this.Flag_Focus == false)
	{
		//CurrentItemIndex == -1
		if(this.CurrentDataIndex < 0)
		{	
			this.CurrentDataIndex = ItemIndex;
		}
		// in multi page.. ex) flag list
		else
		{
			this.CurrentDataIndex = this.CurrentDataIndex + ItemIndex;
		}

		//temp
	    if(this.helpBar)
	    {
	        this.helpBar.visibleObj();
	    }
	    
		this.Flag_Focus = true;	    
		
	}
	else{		
		// highlight 
		this.CurrentDataIndex = this.CurrentDataIndex - this.CurrentItemIndex + ItemIndex;
	}

	alert("CurrentDataIndex = " + this.CurrentDataIndex);
	
	this.SetCurrentItem(ItemIndex);		



}
List.prototype.SetFlagFocus = function(flag){
	alert("List.SetFlagFocus()");
	if(flag!=this.Flag_Focus)
		this.Flag_Focus = flag;
}

List.prototype.SetItemPressedEventCallback = function(CallbackFunc){
	alert("List.SetItemPressedEventCallback()");
	this.ItemPressedCallbackFunc = CallbackFunc;
}

List.prototype.SetEventOnReturnFunc = function(Func){
	this.onReturnFunc = Func;
}

List.prototype.SetEventOnExitFunc = function(Func){
	this.onExitFunc = Func;
}

List.prototype.SetEventOnUpFunc = function(Func){
	this.onUpFunc = Func;
}

List.prototype.SetEventOnDownFunc = function(Func){
	this.onDownFunc = Func;
}

List.prototype.SetEventOnLeftFunc = function(Func){
	this.onLeftFunc = Func;
}

List.prototype.SetEventOnRightFunc = function(Func){
	this.onRightFunc = Func;
}

List.prototype.SetHighlightForDataIndex = function(DataIndex) {

	alert("List.SetHighlightForDataIndex");
	this.Flag_Focus	= true;

	var CurPage = parseInt(DataIndex / this.MaxNumOfItem);
	var rest = parseInt(DataIndex % this.MaxNumOfItem);
		
	this.StartDataIndex = CurPage * this.MaxNumOfItem;	
	this.CurrentDataIndex = DataIndex;
	//this.CurrentItemIndex = rest;
	
	this.UpdatePage();
	this.SetCurrentItem(rest);
	
}


List.prototype.ResetHighlight = function(){

	if(this.Flag_Focus == false)
	{
		this.StartDataIndex = 0;	
		this.CurrentDataIndex = 0;
		this.PrevItemIndex = 0;

		this.UpdatePage();
	}
	
}

List.prototype.highlight = function(){
	
	alert("List.highlight");
	this.Flag_Focus	= true;

	var ItemIndex = this.PrevItemIndex;
	
	if(this.NumOfVisibleItem == 0){
		alert("No Visible Item!!!!");
		return -1;
	}
	else if(ItemIndex == -1){
		alert("Prevous Item Index is -1");	
		ItemIndex = 0;
	}
	else if(ItemIndex > this.NumOfVisibleItem - 1){
		ItemIndex = this.NumOfVisibleItem - 1 ;
	}

	this.SetCurrentItem(ItemIndex);

    if( this.helpBar)
    {
         this.helpBar.visibleObj();
    }
    
}

List.prototype.blur = function(){

	alert("List.blur >>> curIndex : " + this.CurrentItemIndex);	
	this.Flag_Focus	= false;
	
	this.PrevItemIndex = this.CurrentItemIndex;	
    
	this.SetCurrentItem(-1);
    
    if( this.helpBar)
    {
         this.helpBar.hiddenObj();
    }

}

List.prototype.select = function(){
    
   alert("List.select()");
}

List.prototype.SetPrevItemIndex = function(nIndex){
    
   this.PrevItemIndex = nIndex;
}




//only update page.. inner function
List.prototype.UpdatePage = function(){
	
	alert("List.UpdatePage(" + this.StartDataIndex + ")");

	var temp;
	var DataSetCount = 0;
	
	//MaxNumOfItem
	for (var i=0; i < this.NumOfCreatedItem; i++) {
	
		temp = this.StartDataIndex + i;
		
		if(temp > (this.MaxNumOfData - 1) ){					
			this.ItemArray[i].SetFlagForExistData(false);	
		}
		else 
		{					
			this.ItemArray[i].SetItem( this.DataArray[temp] );	
			DataSetCount++; 
		}					
	}	
		
	this.NumOfVisibleItem = DataSetCount;
	
	this.ShowItem();

}

List.prototype.PrintListInfo = function(){
	
	alert("######################################");
	alert("Print Information of Item");
	alert("######################################");
	alert("NumOfVisibleItem = " + this.NumOfVisibleItem);	
	alert("MaxNumOfItem = " + this.MaxNumOfItem);
	alert("NumOfCreatedItem = " + this.NumOfCreatedItem);
	alert("CurrentItemIndex = " + this.CurrentItemIndex);
	alert("PrevItemIndex = " + this.PrevItemIndex);
	
	alert("######################################");
	alert("Print Information of Data");
	alert("######################################");
	alert("MaxNumOfData = " + this.MaxNumOfData);
	alert("CurrentDataIndex = " + this.CurrentDataIndex);
	alert("StartDataIndex = " + this.StartDataIndex);						
}


List.prototype.InitializeListInfo = function(){
	
	alert("List.InitListInfo");
	
//	this.NumOfVisibleItem	= 0;	
//	this.CurrentItemIndex	= -1;
//	this.CurrentDataIndex	= -1;
//	this.StartDataIndex		= -1;	
						
}

List.prototype.GetNumOfVisibleItem = function(){
	
	return this.NumOfVisibleItem;
}

List.prototype.registHelpBar= function(obj){
    if(obj)
    {
           this.helpBar = obj;
    }
}

List.prototype.changeHelpBar= function(obj){

    if(this.helpBar == obj)
    {
        return;
    }
    
    if(this.helpBar != null)
    {
           this.helpBar.hiddenObj();
    }
    
     if(obj)
    {
           this.helpBar = obj;
           if(this.flag_highlight ==true)
           {
                this.helpBar.visibleObj();
           }
    } 
}



/***************************** Mouse Event ****************************/
List.prototype.SetOnClickCallbackFunc = function(Index,func)
{
	this.OnClickFunc[Index] = func;
}


List.prototype.SetClickEvent = function(Index)
{	
	if(this.ItemArray[Index] != null && this.OnClickFunc[Index] != null)
	{
		alert("List.SetClickEvent[" + Index + "]");
		this.ItemArray[Index].SetOnClickCallbackFunc(this.OnClickFunc[Index],this.Flag_RightClick);		
	}
	else
	{
		alert("SetOnClickCallbackFunc -- OnClickFunc is not exist!!");
	}	
}

List.prototype.ResetClickEvent = function(Index)
{
	
	if(this.ItemArray[Index] != null)
	{
		alert("List.ResetClickEvent");
		this.ItemArray[Index].ResetOnClickCallbackFunc();
	}
}

List.prototype.SetOnMouseOverCallbackFunc = function(Index, func){
	this.OnMouseOverFunc[Index] = func;
}

List.prototype.SetMouseOverEvent = function(Index){
	if(this.ItemArray[Index] != null && this.OnMouseOverFunc[Index] != null)
	{
		alert("List.SetMouseOverEvent[" + Index + "]");
		this.ItemArray[Index].SetOnMouseOverCallbackFunc(this.OnMouseOverFunc[Index],this.Flag_RightClick);		
	}
	else
	{
		alert("SetOnClickCallbackFunc -- OnClickFunc is not exist!!");
	}
}

List.prototype.SetOnMouseOutCallbackFunc = function(Index, func){
	this.OnMouseOutFunc[Index] = func;
}

List.prototype.SetMouseOutEvent = function(Index){
	if(this.ItemArray[Index] != null && this.OnMouseOutFunc[Index] != null)
	{
		alert("List.SetMouseOutEvent[" + Index + "]");
		this.ItemArray[Index].SetOnMouseOutCallbackFunc(this.OnMouseOutFunc[Index],this.Flag_RightClick);		
	}
	else
	{
		alert("SetOnClickCallbackFunc -- OnClickFunc is not exist!!");
	}
}

