
var MaxNumOfMainItem = 5;
var LiveNumOfContact = 4;

var FUNC_POPUP_PROPERTY_TYPE = { 
 
 	NOTHING		:0,
    INDEX		:1,
	IDENTITY	:2
}

function MainList() {

	this.TotalDataNum			= 0;
	this.TotalPageNum			= 0;     
	this.CurIndex				= -1;
	this.CurPage				= 0;   
	this.PrevIndex				= -1;

	this.FuncPopup				= null;
	this.FuncPopupClass			= null;	
	this.FuncPopupPropertyType	= FUNC_POPUP_PROPERTY_TYPE.INDEX;
	
	//TEMPCODE:
	this.PossibleToUpdatePageWithIdentity = true;
		
	this.PageLabel			= null;
	this.ScrollBar			= null;
	this.UpArrow			= null;
	this.DownArrow			= null;
	this.NotifingLabel		= null;	
	this.flagNoItem		= false;	
	
	this.NoItemString		= null;
	
	this.SceneName			= null;
						
	List.call(this);
}

MainList.prototype = new List(); 


MainList.prototype.Create = function() {

	alert("MainList.Create");
	
	this.Costomizing();
	
	//Set Page
	this.PageLabel = new CompBase(); 
	this.PageLabel.CreateBG(this.ElimentName + "Page");
	this.PageLabel.SetBGImage("");
	this.PageLabel.AddTextLayer(this.ElimentName + "PageText");
	
	//Lable
	this.NotifingLabel = new CompBase(); 
	this.NotifingLabel.CreateBG(this.ElimentName + "Notify");
	this.NotifingLabel.SetBGImage(g_Image.IMAGE_LIST_MAIN_SETTING_BG);
	this.NotifingLabel.AddTextLayer(this.ElimentName + "NotifyText");				
	this.NotifingLabel.SetTextLayer(1,this.NoItemString);
		
	//Set List 
	this.CreateBG(this.ElimentName + "List");    
	this.SetNumOfVisibleItem(MaxNumOfMainItem);		
	this.SetItemSizeStyle(ITEM_SIZE_STYLE.REMOVE_SIZE);
	this.CreateItems();

	var Scene = sf.scene.get(this.SceneName);
	var This_ = Scene.list;
	this.SetOnClickCallbackFunc(0,function(){This_.JumpToItem(0);});
	this.SetOnClickCallbackFunc(1,function(){This_.JumpToItem(1);});
	this.SetOnClickCallbackFunc(2,function(){This_.JumpToItem(2);});
	this.SetOnClickCallbackFunc(3,function(){This_.JumpToItem(3);});
	this.SetOnClickCallbackFunc(4,function(){This_.JumpToItem(4);});
	this.SetOnClickCallbackFunc(5,function(){This_.JumpToItem(5);});

	this.SetOnMouseOverCallbackFunc(0, function(){This_.JumpToItem(0);});
	this.SetOnMouseOverCallbackFunc(1, function(){This_.JumpToItem(1);});
	this.SetOnMouseOverCallbackFunc(2, function(){This_.JumpToItem(2);});
	this.SetOnMouseOverCallbackFunc(3, function(){This_.JumpToItem(3);});
	this.SetOnMouseOverCallbackFunc(4, function(){This_.JumpToItem(4);});
	this.SetOnMouseOverCallbackFunc(5, function(){This_.JumpToItem(5);});
	this.SetClickEventAvailable(WndMgr.MouseClickEnable);
	

	this.FuncPopup = new this.FuncPopupClass();
	this.FuncPopup.Create();	

	this.ScrollBar = new ScrollBar();
	this.ScrollBar.Create(this.ElimentName + "ScrollBar");
	this.ScrollBar.SetShapeStyle(SCROLLBAR_SHAPE_STYLE.VERTICAL);
	this.ScrollBar.SetFirstImage(g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_TOP);
	this.ScrollBar.SetSegmentImage(g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_CENTER);
	this.ScrollBar.SetLastImage(g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_BOTTOM);	
	this.ScrollBar.SetPosition(this.TotalPageNum,440,0,10);
	this.ScrollBar.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_BG_TOP, g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_BG_CENTER, g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_BG_BOTTOM);

	// Imae Lable
	this.UpArrow = new CompBase(); 
	this.UpArrow.CreateBG(this.ElimentName + "UpArrow");
	//this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP); 
	this.UpArrow.SetOnClickCallbackFunc(function(){This_.PageScroll(true);});	
	this.UpArrow.SetOnMouseOverCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.UP_SEL);});
	this.UpArrow.SetOnMouseOutCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.ARROW_HIDE);});		

	this.DownArrow = new CompBase(); 
	this.DownArrow.CreateBG(this.ElimentName + "DownArrow");
	//this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN); 
	this.DownArrow.SetOnClickCallbackFunc(function(){This_.PageScroll(false);});	
	this.DownArrow.SetOnMouseOverCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.DOWN_SEL);});
	this.DownArrow.SetOnMouseOutCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.ARROW_HIDE);});	
	
	this.GetBGLayer().SetOnMouseOverCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.ARROW_SHOW);});
	this.GetBGLayer().SetOnMouseOutCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.ARROW_HIDE);});	
}


MainList.prototype.CreateBG = function(Ename) {

    alert("MainList.CreateBG(" + Ename + ")");
    if(Ename == null) {
        //alert("CListBase.CreateBG()  >>>   Param is null !!  ");
        return false;
    }
    	
    this.BGLayer = new ImageLayer(Ename);
	        
}

/*
delete....

MainList.prototype.GetCurIdentity = function(){

	return this.ItemArray[this.CurrentItemIndex].GetIdentity();	
}
*/

MainList.prototype.GetCurItemIdentity = function(){

	//must check no item.....
	if(this.CurrentItemIndex < 0){
		return null;
	}
	return this.ItemArray[this.CurrentItemIndex].GetIdentity();	
}

MainList.prototype.GetCurIdentityName = function(){

	return this.ItemArray[this.CurrentItemIndex].GetIdentityName();	
}

MainList.prototype.GetCurDisplayName = function(){

	return this.ItemArray[this.CurrentItemIndex].GetDisplayName();	
}

MainList.prototype.GetCurIndex = function(){

	return this.CurIndex;	
}

MainList.prototype.GetTotalDataNum = function(){
	alert("MainList.GetTotalDataNum() --> TotalDataNum = " + this.TotalDataNum);

	if(this.TotalDataNum >= 0 && this.TotalDataNum != null)	{
		return this.TotalDataNum;	
	} else {
		if((this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.IDENTITY) || (this.SceneName == "ListMainContact"))
			return parseInt(PluginAPIMgr.GetNumberOfContacts());	
		else
			return parseInt(PluginAPIMgr.GetNumberOfHistorys());
	}
}

MainList.prototype.GetNoItem = function(){
	alert("MainList.GetNoItem = " + this.flagNoItem); 

	return this.flagNoItem;	
}

MainList.prototype.highlight = function(){

	alert("MainList.highlight"); 
	this.Flag_Focus	= true;

	// modify 9.26
	this.MoveItem(this.CurrentItemIndex);
	this.FuncPopup.Show();
	//		
	
	this.FuncPopup.Highlight();
	
}

MainList.prototype.blur = function(){
	
	alert("MainList.blur"); 
	this.Flag_Focus	= false;
	this.FuncPopup.Blur();	
}

MainList.prototype.KeyProcess = function (keyCode) {

	alert("MainList.KeyProcess : " + keyCode);

//	int iKeyCode = ( 5*10000000 + ridgeEvent.Direction()*100000 + ridgeEvent.Percentage() );

	var ridgeDirection = Math.round((keyCode - (5*10000000)) / 100000);
//    var ridgePercentage = (keyCode - (5*10000000)) - (ridgeDirection * 100000);
	
	if(ridgeDirection == 1) { // Ridge flick : Up
		if(ProcMgr.GetRidgeFlick() == false) {
			this.PageScroll(true);
			ProcMgr.StartRidgeTimer();
		}
	}
	else if(ridgeDirection == 2) { // Ridge flick : Down
		if(ProcMgr.GetRidgeFlick() == false) {
			this.PageScroll(false);
			ProcMgr.StartRidgeTimer();
		}
	}
	else {
		switch(keyCode) {

			case sf.key.UP:
				this.Previous();
				break;

			case sf.key.DOWN:
				this.Next();
				break;
				
			default:
				this.FuncPopup.KeyProcess(keyCode);
		}
	}
} 

MainList.prototype.Next = function(){
	
	alert("MainList.Next"); 
	
	var CurItemIndex = 	this.CurrentItemIndex + 1;
		
	if(CurItemIndex == this.NumOfVisibleItem )
	{
		
		alert("Page scroll ");
		
		//case1 : Multi Page 
		if (this.TotalPageNum > 1) {
			
			//set current page
			if(this.CurPage >= this.TotalPageNum) {
				this.CurPage = this.TotalPageNum;
				CurItemIndex = this.CurrentItemIndex;
			}
			else {
				this.CurPage++;
				this.UpdatePage();
				CurItemIndex = 0;
			}			
		} 
		else {
			CurItemIndex = this.CurrentItemIndex;
		}			
	}

	//Set History Index
	if(this.CurIndex < this.TotalDataNum-1){
		this.CurIndex++;
	} 
	this.MoveItem(CurItemIndex);
	
}

MainList.prototype.Previous = function(){

	alert("MainList.Previous");  

	var CurItemIndex = 	this.CurrentItemIndex - 1;
	
	//page scroll 			
	if(CurItemIndex == -1 ) {		
		alert("Page scroll ");	
		
		//case1 : Multi Page 
		if (this.TotalPageNum > 1) {

			//set current page
			if(this.CurPage <= 1) {
				this.CurPage = 1;
				CurItemIndex = this.CurrentItemIndex;
			}
			else {
				this.CurPage--;
				this.UpdatePage();	
				CurItemIndex = this.NumOfVisibleItem -1;
			}		
			
		}
		else {
			CurItemIndex = this.CurrentItemIndex;
		}
 		
	}

	//Set History Index
 	this.CurIndex--;
 
	if(this.CurIndex < 0){					
		this.CurIndex = 0;
	} 

	this.MoveItem(CurItemIndex);	

}

MainList.prototype.MoveItem = function(nCurItemIndex){

	alert("MainList.MoveItem( " + nCurItemIndex + ")" );
	
	//check exception
	if(nCurItemIndex > this.NumOfVisibleItem - 1 || nCurItemIndex < 0){
		
		alert("Index Error " );
		return;
	}

	this.SetCurrentItem(nCurItemIndex);
		
	this.FuncPopup.SetCurPosition(nCurItemIndex);
	
	if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.INDEX){
		this.FuncPopup.SetCurProperty(this.CurIndex);	
	}
	else if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.IDENTITY){
		var IdentityName = this.GetCurIdentityName();	
		this.FuncPopup.SetCurProperty(IdentityName);	
	}
		
	//must need this code...
	if(this.Flag_Focus){
		this.FuncPopup.Highlight();
	}
			
	this.FuncPopup.Show();
	
}

//update index, page, scrollbar, etc....
MainList.prototype.Refresh = function(){
	
	alert("MainList.Refresh" );
	
	//Reset Data in list
	if(this.Flag_Focus && this.PossibleToUpdatePageWithIdentity){
		this.RefreshForCurIdentity();
	}
	else {
		this.RefreshForCurrentPage();
	}	
}

//function at 1 more Item
MainList.prototype.RefreshForCurIdentity = function(){

	alert("MainList.RefreshFoCurIdentity" );
	
	var ItemIdentity = this.GetCurItemIdentity();
	
	if(ItemIdentity == null){

		alert("=====================================");
		alert("Error!! no result of CurItemIdentity ");
		alert("=====================================");
		
		this.RefreshForCurrentPage();
		
	}
	else{

		var Index = parseInt(this.GetIndexOfData(ItemIdentity));
		alert("Index = " + Index);	
		
		if(Index >= 0 ){
			
			this.InitializeDataOfPage();		
			
			//reset current page
			this.CurPage = parseInt(Index / MaxNumOfMainItem ) + 1;	
			alert("CurPage = " + this.CurPage);
			this.CurIndex = Index;	
			
			//reset page & scorllbar
			this.UpdatePage();
			
			var CurItemIndex = Index  % MaxNumOfMainItem;
			
			this.CurrentItemIndex = -1;		
			this.MoveItem(CurItemIndex);
			
		}
		else{
			
			alert("=====================================");
			alert("Error!! no result of searching index ");
			alert("=====================================");		
			
			this.RefreshForCurrentPage();
			
		}		
	}
	if(this.Flag_Focus){
		this.FuncPopup.Show();
	}else{
		this.FuncPopup.Hide();
	}
}

MainList.prototype.RefreshForCurrentPage = function(){
	
	alert("MainList.RefreshForCurrentPage" );
	
	var PrevTotalDataNum = this.TotalDataNum ;
	
	this.InitializeDataOfPage();
	
	if(this.TotalDataNum > 0){

		this.flagNoItem = false;
		if(PrevTotalDataNum < 1){
			
			this.NotifingLabel.Hide();				
			this.PageLabel.Show();
			this.CurPage = 1;
			this.CurrentItemIndex = 0;
		}

		var IsLastIndex = false;
		
		//Reset index of current page 
		if( this.CurPage > this.TotalPageNum){
			
			this.CurPage = this.TotalPageNum;
			IsLastIndex = true;
		}
		
		//update list 	
		this.UpdatePage();
		
		var prevItemIndex = this.CurrentItemIndex;
					
		if(IsLastIndex == true || prevItemIndex > this.NumOfVisibleItem - 1){		
			prevItemIndex = this.NumOfVisibleItem - 1;		
		}
		
		this.CurIndex = (this.CurPage - 1) * MaxNumOfMainItem + prevItemIndex;
			
		this.FuncPopup.Hide();
		for (var i=0; i < this.NumOfCreatedItem; i++) {
			this.ItemArray[i].DownNormal();
		}	
		this.CurrentItemIndex = prevItemIndex;
	}
	else {
		this.flagNoItem = true;
		this.ShowNoItemPage();
		if(PrevTotalDataNum > 0)
			this.NotifingLabel.Show();
	}
	
		
}

MainList.prototype.RefreshForJumpIndex = function(idex_index){

	alert("MainList.RefreshForJumpIndex - " + idex_index);
	
	this.InitializeDataOfPage();		
	
	//reset current page
	this.CurPage = parseInt(idex_index / MaxNumOfMainItem ) + 1;	
	alert("CurPage = " + this.CurPage);
	this.CurIndex = idex_index;	
	
	//reset page & scorllbar
	this.UpdatePage();
	
	var CurItemIndex = idex_index  % MaxNumOfMainItem;
	
	this.CurrentItemIndex = -1;
	this.MoveItem(CurItemIndex);
		
	if(this.Flag_Focus){
		this.FuncPopup.Show();
	}else{
		this.FuncPopup.Hide();
	}
}

//Set TotalDataNum & TotalPageNum;
MainList.prototype.InitializeDataOfPage = function(){
	
	var CurDataNum = parseInt(this.GetNumberOfDatas());
	
	if(this.TotalDataNum != CurDataNum){
		
		this.TotalDataNum = CurDataNum;		
				
		if( this.TotalDataNum > 0){
			
			this.TotalPageNum = parseInt(this.TotalDataNum / MaxNumOfMainItem);

			if((CurDataNum % MaxNumOfMainItem) > 0){
				this.TotalPageNum++;
			}						
		}
		else {
			this.InitializeListInfo();
		}		
	}
		
}

//Initialize data when login
MainList.prototype.Initialize = function(){

	alert("MainList.Initialize");
	
	var PrevTotalDataNum = this.TotalDataNum ;
	
	this.InitializeDataOfPage();
		
	if(this.TotalDataNum > 0)
	{		
		
		this.flagNoItem = false;
		if(PrevTotalDataNum < 1){

			this.NotifingLabel.Hide();
			this.PageLabel.Show();
		}
		this.FuncPopup.Hide();		
		//update page
		this.SetListInfoToStart();
		this.UpdatePage();	

		
		//set highlight & other style
		this.CurrentItemInit();
		this.CurrentItemIndex = 0;
		this.FuncPopup.ReSetHighlight();
		
		this.FuncPopup.SetCurPosition(this.CurrentItemIndex);
		
		if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.INDEX){		
			
			this.FuncPopup.SetCurProperty(this.CurIndex);
		}
		else if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.IDENTITY){
								
			var IdentityName = this.GetCurIdentityName();	
			this.FuncPopup.SetCurProperty(IdentityName);					
		}		
	}
	//check code  08.30 
	else {
		this.flagNoItem = true;
		this.ShowNoItemPage();			
	}
	
}

//Initialize data when jump
MainList.prototype.InitializeForJump = function(item_index){

	alert("MainList.InitializeForJump - " + item_index);
	
	var PrevTotalDataNum = this.TotalDataNum ;
	
	this.InitializeDataOfPage();
		
	if(PrevTotalDataNum < 1){

		this.NotifingLabel.Hide();
		this.PageLabel.Show();
	}
	this.FuncPopup.Hide();		

	this.SetListInfoToJump(item_index);
	//update page
	this.UpdatePage();	
	
	//set highlight & other style
	this.CurrentItemInit();
	this.FuncPopup.ReSetHighlight();
	
	this.FuncPopup.SetCurPosition(this.CurrentItemIndex);
	
	if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.INDEX){		
		
		this.FuncPopup.SetCurProperty(this.CurIndex);
	}
	else if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.IDENTITY){
							
		var IdentityName = this.GetCurIdentityName();	
		this.FuncPopup.SetCurProperty(IdentityName);					
	}
}


MainList.prototype.CreateItems = function(){

	alert("MainList.CreateItems");
	
	var cItem = this.ItemClass;
	var ItemEname = this.ElimentName + "Item";
	
	for (var i=0; i < MaxNumOfMainItem; i++) {
		
		this.ItemArray[i] = new cItem();	
		this.ItemArray[i].SetItemID(i);	
		this.ItemArray[i].Create(ItemEname + (i + 1));
		
	}
	
	this.NumOfCreatedItem = MaxNumOfMainItem;	
}

//Initialize info to All data 
MainList.prototype.InitializeListInfo = function(){
	
	alert("MainList.InitListInfo");
	
	this.NumOfVisibleItem	= 0;	
	this.CurrentItemIndex	= -1;

	this.TotalDataNum		= 0;
	this.TotalPageNum		= 0;     
	this.CurIndex			= -1;
	this.CurPage			= 0;  
		
}

//Set info to start list
MainList.prototype.SetListInfoToStart = function(){
	
	alert("MainList.InitListInfo");
	
	this.CurrentItemIndex	= -1;		//to update style for all item
	this.CurIndex			= 0;		//starting point
	this.CurPage			= 1;		//starting point  
		
}

//Set info to jump 
MainList.prototype.SetListInfoToJump = function(item_index)
{	
	this.CurIndex			= item_index;	
	this.CurrentItemIndex	= item_index % MaxNumOfMainItem;	
	this.CurPage			= parseInt(item_index / MaxNumOfMainItem) + 1;
	
	alert('CurrentItemIndex = ' + this.CurrentItemIndex + ' CurPage = ' + this.CurPage);		
}

//Reset scrool bar & page label
MainList.prototype.ResetPageUI = function(){
	
	alert("MainList.ResetPageUI : TotalPageNum = " + this.TotalPageNum);
	
	//make function  later.. 
	this.PageLabel.SetTextLayer(1,this.CurPage + "/" + this.TotalPageNum); //  + " " + TV_SID_PAGES

	this.ScrollBar.SetTotalNum(this.TotalPageNum);
	this.ScrollBar.SetCurrentNum(this.CurPage);
	this.ScrollBar.ResetScrollBar();
	
	
	if(this.TotalPageNum > 1)	{
		this.ScrollBar.Show();
		this.UpArrow.Show();
		this.DownArrow.Show();
		
	}	else{
		this.ScrollBar.Hide();
		this.UpArrow.Hide();
		this.DownArrow.Hide();
	}
	
}

MainList.prototype.ShowNoItemPage = function(){
	
	alert("MainList.ShowNoItemPage");
		
	for(var k = 0; k < MaxNumOfMainItem ; k++) {
		
		if(this.ItemArray[k]){
			this.ItemArray[k].SetFlagForExistData(false);
		}		
	}
	this.ShowItem();

	this.FuncPopup.Hide();		
	this.PageLabel.Hide();

	this.ScrollBar.SetTotalNum(this.TotalPageNum);
	this.ScrollBar.SetCurrentNum(this.CurPage);		
	
	
	this.ScrollBar.Hide();
	this.UpArrow.Hide();
	this.DownArrow.Hide();
	
	//TEMPCODE
	if(this.Flag_Focus){
	
		WndMgr.ReturnSubToMain();		
	}

}

MainList.prototype.Hide = function() {

	alert("MainList.Hide()");

	this.FuncPopup.HideSubScene();

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

MainList.prototype.MoveToVideoCallBtn = function(){
	
	this.FuncPopup.MoveToVideoCallBtn();
}

MainList.prototype.MoveToMain = function(){
	
	this.FuncPopup.processReturnKey();
}	

//Check!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MainList.prototype.JumpToItem = function(ItemIndex)
{
	alert("MainList.JumpToItem --" + ItemIndex);
	if(this.PrevIndex == ItemIndex)
		return;
	if(this.Flag_Focus == false) {
		sf.scene.get('ListMain').selectOnCurrHighlight();
	}
	if(ItemIndex < 0 || ItemIndex > MaxNumOfMainItem)
	{
		alert("ItemIndex error.. only  1 ~ 5"); 
		return;
	}
	
	if(this.SceneName == "ListMainHistory" && ProcMgr.isVoiceMailPlaying == true) {
		ProcMgr.StopHistoryVoicemail(this.CurIndex);	
	}

	this.CurIndex = this.CurIndex - this.CurrentItemIndex + ItemIndex ;
	this.PrevIndex = ItemIndex;
	this.MoveItem(ItemIndex);
}

MainList.prototype.PageScroll = function(UpScroll)
{
	alert("MainList.PageScroll : TotalPageNum = " + this.TotalPageNum);
	if (this.TotalPageNum > 1) 
	{
		var newPositionItem = -1;
		var lastPage = false;
		
		if(this.SceneName == "ListMainHistory" && ProcMgr.isVoiceMailPlaying == true) {
			ProcMgr.StopHistoryVoicemail(this.CurIndex);	
		}
		
		if(UpScroll == true)
		{
			//set current page
			if(this.CurPage <= 1) {
				this.CurPage = 1;
				return;
			}
			else {
				this.CurPage--;
			}
		}
		else{
			//set current page
			if(this.CurPage >= this.TotalPageNum) {
				lastPage = true;
				this.CurPage = this.TotalPageNum;
				return;
			}
			else {
				this.CurPage++;
			}			
		}
				
		this.UpdatePage();
		 
		//Check!!! Live call 
		if(UpScroll == true)
		{	
			alert("UpScroll");
		 	this.CurIndex = this.CurIndex - MaxNumOfMainItem;
		 		 	
			if(this.CurIndex < 0)
			{	
				//case 1. 1 page == > last page
				if(this.CurPage == this.TotalPageNum) 
				{
					if(this.CurrentItemIndex > this.NumOfVisibleItem -1)
					{
						//last page				
						this.CurIndex = this.TotalDataNum -1;
						newPositionItem = this.NumOfVisibleItem -1;
						alert("CurIndex = " + this.CurIndex);
						alert("newPositionItem = " + newPositionItem);					
					}
					else
					{
						this.CurIndex = ((this.CurPage - 1) * MaxNumOfMainItem) + this.CurrentItemIndex;
						alert("CurIndex = " + this.CurIndex);
					}					
				}
			}
		}
		else
		{
			alert("DownScroll");
			this.CurIndex = this.CurIndex + MaxNumOfMainItem;
			
			//last
			if(this.CurIndex > this.TotalDataNum - 1){
				
				//case 1. last page == > first page
				if(lastPage == true) {
					this.CurIndex = this.CurrentItemIndex;
					alert("first page >> CurIndex = " + this.CurIndex);	
				}
				//case 2. last - 1 page == > last page
				else {
					//last page	
					if(this.CurrentItemIndex > this.NumOfVisibleItem -1)
					{
						this.CurIndex = this.TotalDataNum -1;
						newPositionItem = this.NumOfVisibleItem -1;
						alert("CurIndex = " + this.CurIndex);
						alert("newPositionItem = " + newPositionItem);					
					}
					else
					{
						this.CurIndex = ((this.CurPage - 1) * MaxNumOfMainItem) + this.CurrentItemIndex;
						alert("CurIndex = " + this.CurIndex);
					}					
				}	
			}
		}
		
		//new case. move item to another position!!!
		if(newPositionItem > -1)
		{
			this.SetCurrentItem(newPositionItem);
			this.FuncPopup.SetCurPosition(newPositionItem);
		}
		
		if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.INDEX){
			this.FuncPopup.SetCurProperty(this.CurIndex);	
		}
		else if(this.FuncPopupPropertyType == FUNC_POPUP_PROPERTY_TYPE.IDENTITY){
			var IdentityName = this.GetCurIdentityName();	
			this.FuncPopup.SetCurProperty(IdentityName);	
		}
		
		if(this.Flag_Focus)
		{
			this.FuncPopup.Highlight();
		}
	}
}

MainList.prototype.ChangeArrow = function(Type)
{
//	alert("MainList.ChangeArrow : Type = "+Type+",    CurPage = "+this.CurPage);

	switch(Type)
	{
		case ARROW_TYPE.UP_NOR:
			break;
			
		case ARROW_TYPE.UP_SEL:
			if(this.CurPage == 1) {
				this.UpArrow.SetBGImage(" ");
				this.DownArrow.SetBGImage(" ");
			} else if(this.CurPage == this.TotalPageNum) {
				this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP_FOCUS);
				this.DownArrow.SetBGImage(" ");
			} else {
				this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP_FOCUS);
				this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN);
			}
			break;

		case ARROW_TYPE.DOWN_NOR:
			break;
			
		case ARROW_TYPE.DOWN_SEL:
			if(this.CurPage == 1) {
				this.UpArrow.SetBGImage(" ");
				this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN_FOCUS);
			} else if(this.CurPage == this.TotalPageNum) {
				this.UpArrow.SetBGImage(" ");
				this.DownArrow.SetBGImage(" ");
			} else {
				this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP);
				this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN_FOCUS);
			}
			break;

		case ARROW_TYPE.ARROW_SHOW:
			if(this.CurPage == 1) {
				this.UpArrow.SetBGImage(" ");
				this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN);
			} else if(this.CurPage == this.TotalPageNum) {
				this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP);
				this.DownArrow.SetBGImage(" ");
			} else {
				this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP);
				this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN);
			}
			break;
			
		case ARROW_TYPE.ARROW_HIDE:
			this.PrevIndex = -1;
			this.UpArrow.SetBGImage(" ");
			this.DownArrow.SetBGImage(" ");
			break;	
	}
}


