
var MaxNumOfSearchItem = 5;
var SearchListPropNum = 4;

function SearchList() {
										
    ScrollList.call(this);
}

SearchList.prototype = new ScrollList(); 

SearchList.prototype.Create = function() {

    alert("SearchList.Create");

	//Set List 
	this.CreateBG("searchList","divide");    
    this.ElimentName = "search";	
	this.SetNumOfVisibleItem(MaxNumOfSearchItem);
	this.SetItemClass(SearchItem);
	// this.SetItemSizeStyle(ITEM_SIZE_STYLE.REMOVE_SIZE);
	this.CreateScrBar("searchListScrollBar");
	//no circulation
	this.SetCirculation(false);
	this.SetScrBarPosition(210,0,4);
	this.SetScrollBarImage(g_Image.IMAGE_BLOCK_SCROLLBAR_TOP,
		g_Image.IMAGE_BLOCK_SCROLLBAR_CENTER,
		g_Image.IMAGE_BLOCK_SCROLLBAR_BOTTOM);	
	this.SetScrBGImage(g_Image.IMAGE_SIGNUP_COUNTRY_LIST_SCROLLBAR_BG_TOP,
		g_Image.IMAGE_SIGNUP_COUNTRY_LIST_SCROLLBAR_BG_CENTER,
		g_Image.IMAGE_SIGNUP_COUNTRY_LIST_SCROLLBAR_BG_BOTTOM);	
		
	this.ItemPressedCallbackFunc = function(){
				
		var Name = this.GetCurSkypeName();
		ProcMgr.SearchContactProfile(Name);
	};

	this.onReturnFunc = function(){
		
		//2013 modify by minseok
			sf.key.preventDefault();
			//sf.key.block(event);
		WndMgr.BackStepAddContact();
	};	

	this.onExitFunc = function(){
		
		//2013 modify by minseok
			sf.key.preventDefault();
			//sf.key.block(event);
		StateMgr.Stop_Add_Contact_State(true);
	};	
	
	//this.InitData();	
	//this.ShowItem();
	
	this.SetOnClickCallbackFunc(0,this.onClickEventFunc1);
	this.SetOnClickCallbackFunc(1,this.onClickEventFunc2);
	this.SetOnClickCallbackFunc(2,this.onClickEventFunc3);
	this.SetOnClickCallbackFunc(3,this.onClickEventFunc4);
	this.SetOnClickCallbackFunc(4,this.onClickEventFunc5);
	this.SetOnMouseOverCallbackFunc(0,this.onMouseOverEventFunc1);
	this.SetOnMouseOverCallbackFunc(1,this.onMouseOverEventFunc2);
	this.SetOnMouseOverCallbackFunc(2,this.onMouseOverEventFunc3);
	this.SetOnMouseOverCallbackFunc(3,this.onMouseOverEventFunc4);
	this.SetOnMouseOverCallbackFunc(4,this.onMouseOverEventFunc5);
	this.SetClickEventAvailable(WndMgr.MouseClickEnable);
		
	var Scene = sf.scene.get("AddContactSearchResult");
	
	for(var i=0;i<5;i++){
		// this.SetOnMouseOverCallbackFunc(i,Scene.onMouseOverFunc);
		this.SetOnMouseOutCallbackFunc(i,Scene.onMouseOutFunc);
	}	
	

	this.Show();				
}


SearchList.prototype.GetCurSkypeName = function(){

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


SearchList.prototype.InitData = function(){

	alert("SearchList.InitData ");	
	
	if(this.MaxNumOfData > 0){
		this.DeleteDataAll();
	}
		
	var strSearchList = PluginAPIMgr.GetSearchList();
	alert("strSearchList = " + strSearchList );	
							
	if(strSearchList)
	{			
			
		var STX = String.fromCharCode(2);
		var ETX = String.fromCharCode(3);
		var splitter = ETX + STX;
	
		var Result = strSearchList.split(splitter);	
		
		var NumOfSearch = parseInt(Result.length / SearchListPropNum );
		//alert("NumOfSearch = " + NumOfSearch );			
		
		var TokenNum = 0;

		var SkypeName;
		var FullName;
		var Country;
		var City;
		
		var tempData = new Array(NumOfSearch);  
		
		//Set Data 			
		for (var i=0; i < NumOfSearch ; i++) {
					
			TokenNum = i*SearchListPropNum;						
			
			SkypeName = Result[TokenNum];	
			FullName = Result[TokenNum+1];
			Country = Result[TokenNum+2];							
			City = Result[TokenNum+3];
			
			//alert("SkypeName[" + i +"] = " + SkypeName );	
			//alert("FullName[" + i +"] = " + FullName );				
			//alert("Country[" + i +"] = " + Country );						
			//alert("City[" + i +"] = " + City );				
			
			tempData[i] = new SearchData();
			tempData[i].SetData(SkypeName,FullName,Country,City);
			
			this.AddData(tempData[i]);		
			
		}
		//Set Page Info
		this.TotalPage = parseInt(this.MaxNumOfData / this.MaxNumOfItem);
		if((this.MaxNumOfData % this.MaxNumOfItem) > 0)
		{
			this.TotalPage++;
		}
		
		
	}
//	else {
//		
//		this.TotalPage = 0;
//		this.CurPage = 0;
//	}
	
}

SearchList.prototype.Reset = function(){
	
	this.InitData();

	if(this.MaxNumOfData == 0){		
		this.ShowItem();
		this.ScrollBar.SetCurrentNum(this.CurPage);
		this.ScrollBar.ResetScrollBar();		
	}
	else {
		this.StartDataIndex = 0;
		this.CurPage = 1;
	}

	this.UpdatePage();

}

SearchList.prototype.onClickEventFunc1 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessClick(0);	
}

SearchList.prototype.onClickEventFunc2 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessClick(1);	
}

SearchList.prototype.onClickEventFunc3 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessClick(2);	
}

SearchList.prototype.onClickEventFunc4 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessClick(3);	
}

SearchList.prototype.onClickEventFunc5 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessClick(4);	
}
SearchList.prototype.onMouseOverEventFunc1 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessMouseOver(0);	
}

SearchList.prototype.onMouseOverEventFunc2 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessMouseOver(1);	
}

SearchList.prototype.onMouseOverEventFunc3 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessMouseOver(2);	
}

SearchList.prototype.onMouseOverEventFunc4 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessMouseOver(3);	
}

SearchList.prototype.onMouseOverEventFunc5 = function()
{
	var OriginalScene = sf.scene.get("AddContactSearchResult");	
	OriginalScene.ProcessMouseOver(4);	
}
