
var MaxNumOfFaceRecogItem = 5;

function FaceRecogList() {
	this.SceneId 			= null;
	this.ListDivId			= null;
	
	this.UpArrow			= null;
	this.DownArrow			= null;
	this.TotalPageNum 		= 0;
	this.RecogResult		= null;
	this.AccountResult		= null;
								
	this.NumOfItem = 0;
								
    ScrollList.call(this);
}

FaceRecogList.prototype = new ScrollList(); 

FaceRecogList.prototype.Create = function(sceneId, listDiv) {

    alert("FaceRecogList.Create");
	this.SceneId = sceneId;
	this.ListDivId = listDiv;


	//Set List 
	this.CreateBG(this.ListDivId);	//List.CreateBG    
	this.SetNumOfVisibleItem(MaxNumOfFaceRecogItem);	//List.SetNumOfVisibleItem
	this.SetItemSizeStyle(ITEM_SIZE_STYLE.REMOVE_SIZE);		//flexible?? list
	this.SetItemClass(FaceRecogItem);				//List.SetItemClass
	this.CreateScrBar(this.ListDivId+"_scroll_bar");
	this.SetStartDataIndex(0);
	//no circulation
	this.SetCirculation(false);
	
		
	// this.InitData();	
	
	// this.SetScrBarPosition(400,0,10);
	// this.SetScrollBarImage(g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_TOP,
		// g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_CENTER,
		// g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_BOTTOM);
	// this.SetScrBGImage(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);	
	
	// this.ResetScrollBar();
	var Scene = sf.scene.get(this.SceneId);
	var This_ = Scene.list;
	
	
	// Arrow Lable
	this.UpArrow = new CompBase(); 
	this.UpArrow.CreateBG(this.ListDivId+"_up_arrow");
	//this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP); 
	this.UpArrow.SetOnClickCallbackFunc(function(){This_.Previous();});	
	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.ListDivId + "_down_arrow");
	//this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN); 
	this.DownArrow.SetOnClickCallbackFunc(function(){This_.Next();});	
	this.DownArrow.SetOnMouseOverCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.DOWN_SEL);});
	this.DownArrow.SetOnMouseOutCallbackFunc(function(){This_.ChangeArrow(ARROW_TYPE.ARROW_HIDE);});

}

/*

CountryList.prototype.GetCurSkypeName = function(){

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

*/

FaceRecogList.prototype.InitRecogResultData = function(){
	alert("FaceRecogList.InitRecogResultData ");	
	this.RecogResult = null;
   	this.RecogResult = g_Data.GetFaceRecogResult();
   	alert("RecongResult is : "+this.RecogResult)
   	if(this.RecogResult==null){
   		alert("there is no data");
		
		return false;
   	}
	this.NumOfItem = this.RecogResult.length;
	if(this.NumOfItem == 0){
		alert("there is no data");
		
		return false;
	}
	var tempData = new Array(this.NumOfItem);
	
	for(var i=0; i<this.NumOfItem;i++){
		tempData[i] = new FaceRecogData();
		tempData[i].SetData(this.RecogResult[i].id,this.RecogResult[i].face+g_Data.GetImgSuffixPath());
		this.AddData(tempData[i]);
	}
	return true;
}
FaceRecogList.prototype.SortAccountData = function(AccountArray){
	var SortedData = new Array(AccountArray.length);
	var i=0;
	for(var j=0;j<AccountArray.length;j++){
		if(AccountArray[j].face=="none"){
			SortedData[i] = AccountArray[j];
			i++;
		}
	}
	alert("number of not registered account : "+i);
	for(var j=0;j<AccountArray.length;j++){
		if(AccountArray[j].face!="none"){
			SortedData[i] = AccountArray[j];
			i++;
		}
	}
	return SortedData;
}
FaceRecogList.prototype.InitChooseAccountData = function(){
	alert("FaceRecogList.InitChooseAccountData ");	
	this.AccountResult = null;
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	if(saved_info){
		alert("***** FaceRecogList.InitChooseAccountData() --> saved_info : "+saved_info);
		this.AccountResult = JSON.parse(saved_info);
		this.NumOfItem = this.AccountResult.SkypeAccount.length;
		this.NumOfItem++;
		var tempData = new Array(this.NumOfItem);
		tempData[0] = new FaceAccountData();
			tempData[0].SetData(
				TV_SID_ENTER_SKYPE_INFO_MSG,
				"none",
				false
				);
			this.AddData(tempData[0]);
		var SortedData = this.SortAccountData(this.AccountResult.SkypeAccount)
		
	
		for(var i=1; i<this.NumOfItem;i++){
			tempData[i] = new FaceAccountData();
			tempData[i].SetData(
				SortedData[i-1].id,
				SortedData[i-1].face+g_Data.GetImgSuffixPath(),
				SortedData[i-1].pwd,
				SortedData[i-1].face_id,
				SortedData[i-1].pwd_check
				);
			this.AddData(tempData[i]);
		}
		return true;
	}else{
		alert("there is no data");
		var tempData = new FaceAccountData();
			tempData.SetData(
				TV_SID_ENTER_SKYPE_INFO_MSG,
				"none",
				false
				);
			this.AddData(tempData);
		return true;
	}
			
}
FaceRecogList.prototype.InitData = function(){

	alert("FaceRecogList.InitData ");	
	this.DeleteDataAll();						//init Data
	this.SetStartDataIndex(0);
	var result = false;
	if(this.SceneId=="FaceRecogResult"){
		result = this.InitRecogResultData();
	}else if(this.SceneId=="FaceRecogChooseAccount"){
		result = this.InitChooseAccountData();
	}
	if(result==false){
		alert("FaceRecogList.InitData : there is no data!!")
		var Scene = sf.scene.get(this.SceneId);
		Scene.flagNoData = true;
		return;		//no data!!!
	}

	////////////////////////////for testing on sdk////////////////////////////////////
	//var NumOfFaceRecogList =8;
	//var tempData = new Array(NumOfFaceRecogList);  
	//for (var i=0; i < NumOfFaceRecogList; i++) {
	//	tempData[i] = new FaceRecogData();
	//	if(i%2==1){
	//		tempData[i].SetData("Qoodang",g_Image.IMAGE_FACE_RECOG_RESULT_PHOTO_NORMAL);
	//	}else{
	//		tempData[i].SetData(null,g_Image.IMAGE_FACE_RECOG_RESULT_PHOTO_NORMAL);		
	//	}
	//	this.AddData(tempData[i]);					
//	}		
////////////////////////////for testing on sdk////////////////////////////////////
	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);
// 	
	for(var i=0;i<5;i++){
		// this.SetOnMouseOverCallbackFunc(i,this.onMouseOverFunc);
		this.SetOnMouseOutCallbackFunc(i,this.onMouseOutFunc);
	}		
	
	this.TotalPageNum = parseInt(this.NumOfItem / MaxNumOfFaceRecogItem);
	if((this.NumOfItem % MaxNumOfFaceRecogItem) > 0){
		this.TotalPageNum++;	
	}
	
	this.ShowItem();
	if(this.TotalPageNum>1){
		this.CurPage=1;				//init
		this.SetScrBarPosition(400,0,10);
		this.SetScrollBarImage(g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_TOP,
			g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_CENTER,
			g_Image.IMAGE_LIST_MAIN_PROFILE_SCROLL_BOTTOM);
		this.SetScrBGImage(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);	
	}
	
	// this.SetScrBarPosition(210,0,5);

}
FaceRecogList.prototype.KeyProcess = function(keyCode, f_simplex){
	alert("FaceRecogList.KeyProcess");
	if(keyCode==sf.key.ENTER){
		alert("KEY_ENTER!! Data index is "+ this.GetCurrentDataIndex() );
		alert("KEY_ENTER!! Item index is "+ this.CurrentItemIndex );
		if(this.SceneId=="FaceRecogResult"){
		this.processItemSelect(this.GetCurrentDataIndex());
		}else if(this.SceneId=="FaceRecogChooseAccount"){
			this.processAccountSelect(this.GetCurrentDataIndex())
		}
	}else{
		List.prototype.KeyProcess.call(this, keyCode, f_simplex);	//call super class
	}
}
FaceRecogList.prototype.processItemSelect = function(index){
	var selectedObj = this.GetCurrentInputData();
	g_Data.SetFaceRecogSelectedItem(selectedObj);
	ProcMgr.ProcessSelectedRecogResult(index);
}
FaceRecogList.prototype.processAccountSelect = function(index){
	var selectedObj = this.GetCurrentInputData();
	if(index==0){		//link account
		ProcMgr.LinkAccount();
	}else{
		g_Data.SetFaceRecogSelectedAccount(selectedObj);
		var accountIndex = this.getAccountIndex(selectedObj.Name); 
		// g_Data.SetFaceRecogSelectedIndex(accountIndex);
		WndMgr.StartCheckPwd();
	}
}
FaceRecogList.prototype.getAccountIndex = function(name){
	alert("FaceRecogList.getAccountIndex : "+name); 
	var accountArray = this.AccountResult.SkypeAccount;
	for(var i=0;i<accountArray.length;i++){
		if(accountArray[i].id==name){
			alert("return!! "+i);
			return i;
		}
	}
}
FaceRecogList.prototype.blur = function(){
	alert("FaceRecogList.blur >>> curIndex : " + this.CurrentItemIndex);	
	this.Flag_Focus	= false;
	this.PrevItemIndex = -1;	
    alert("FaceRecogList.blur!! index is "+ this.GetCurrentDataIndex() );
    if(this.CurrentItemIndex != -1){
	this.SetCurrentItem(-1);
}
}
FaceRecogList.prototype.highlight = function(){
	alert("FaceRecogList.highlight >>> curIndex : " + this.CurrentItemIndex);	
	this.SetCurrentDataIndex(0);
	List.prototype.highlight.call(this);	//call super class
}

FaceRecogList.prototype.onClickEventFunc1 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.processClick(0);
}

FaceRecogList.prototype.onClickEventFunc2 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.processClick(1);
}

FaceRecogList.prototype.onClickEventFunc3 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.processClick(2);
}

FaceRecogList.prototype.onClickEventFunc4 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.processClick(3);
}
FaceRecogList.prototype.onClickEventFunc5 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.processClick(4);
}
FaceRecogList.prototype.onMouseOverEventFunc1 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.list.ChangeArrow(ARROW_TYPE.ARROW_SHOW);
	Scene.processMouseOver(0);
}
FaceRecogList.prototype.onMouseOverEventFunc2 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.list.ChangeArrow(ARROW_TYPE.ARROW_SHOW);
	Scene.processMouseOver(1);
}
FaceRecogList.prototype.onMouseOverEventFunc3 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.list.ChangeArrow(ARROW_TYPE.ARROW_SHOW);
	Scene.processMouseOver(2);
}
FaceRecogList.prototype.onMouseOverEventFunc4 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.list.ChangeArrow(ARROW_TYPE.ARROW_SHOW);
	Scene.processMouseOver(3);
}
FaceRecogList.prototype.onMouseOverEventFunc5 = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.list.ChangeArrow(ARROW_TYPE.ARROW_SHOW);
	Scene.processMouseOver(4);
}
FaceRecogList.prototype.onMouseOutFunc = function()
{
	var Scene = null;
	alert("this step is "+WndMgr.FaceRecogSigninStep);
	if(WndMgr.FaceRecogSigninStep=="Result"){
		Scene = sf.scene.get('FaceRecogResult');
	}else if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
		Scene = sf.scene.get('FaceRecogChooseAccount');
	}
	Scene.list.ChangeArrow(ARROW_TYPE.ARROW_HIDE);
}
FaceRecogList.prototype.ChangeArrow = function(Type)
{
	alert("FaceRecogList.ChangeArrow");

	switch(Type)
	{
		case ARROW_TYPE.UP_NOR:
			break;
		case ARROW_TYPE.UP_SEL:
			this.DownArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_DOWN);
			this.UpArrow.SetBGImage(g_Image.IMAGE_LIST_MAIN_PROFILE_ARROW_UP_FOCUS);
			break;
		case ARROW_TYPE.DOWN_NOR:
			break;
		case ARROW_TYPE.DOWN_SEL:
			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:
			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.DownArrow.SetBGImage(" ");
			this.UpArrow.SetBGImage(" ");
			break;
	}
}
