
function SceneFaceRecogResult(options) {
	this.options = options;
    
    this.MainView=null;
    
    this.FaceRecogTabBtn = null;
    this.FaceRecogTabSigninLabel = null;
    this.TitleLabel = null;
    this.CalllistLine = null;
    this.ResultMsg = null;
    
    this.FaceRecogMouseBtn = null;
    this.IDPWMouseBtn = null;
    
    this.list = null;
    
    this.NoResultMsg = null;
	
    this.RetryBtn = null;
    this.CancelBtn = null;
    
    this.ScrollBg=null;
    this.ScrollLeft=null;
    this.ScrollMiddle=null;
    this.ScrollRight=null;
    
    this.UpArrow = null;
	this.DownArrow = null; 
    
    this.defaultHighLight = new Array(4); 

    this.DefaultHelpBar =null;

	//flag	
	this.flagWaiting = false;
	this.flagNoData = false;
	this.flagDataUpdate = false;
	this.TempViweIndex =0;
	this.ViewIndex =0;
	
	this.RecogResult = null;
	this.DataIndex = 0;
	
	this.isListFocused = true;
}

SceneFaceRecogResult.prototype.initialize = function () {
	alert("SceneFaceRecogResult.initialize()");
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here 
	// scene HTML and CSS will be loaded before this function is called
   
    this.create();
    
}

SceneFaceRecogResult.prototype.handleShow = function () {
	alert("SceneFaceRecogResult.handleShow()");
	// this function will be called when the scene manager show this scene
	this.flagNoData = false;
	this.updateList(); 
	this.showList();
	// this.initFaceRecogResult();
}

SceneFaceRecogResult.prototype.handleHide = function () {
	alert("SceneFaceRecogResult.handleHide()");
	// this function will be called when the scene manager hide this scene      
	
}

SceneFaceRecogResult.prototype.handleFocus = function () {
	alert("SceneFaceRecogResult.handleFocus()");
	// this function will be called when the scene manager focus this scene

    var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight ==null)
    {
    	if(this.flagNoData==true){
    		this.highlight(this.RetryBtn);
    	}else{
	        this.highlight(this.list);
    	}
    }
    else
    {
    	if(this.flagNoData==true){
    		this.highlight(this.RetryBtn);
    	}
    	else
    	{
    		this.highlight(currentHighlight);	
    	}        
    }
    
    var this_ = sf.scene.get("FaceRecogResult");
  	var returnCF =  function(){this_.processReturnKey();};
    WndMgr.SetReturnIconClickCallback(returnCF);
}

SceneFaceRecogResult.prototype.handleBlur = function () {
	alert("SceneFaceRecogResult.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
	if(currentHighlight !=null)
    {
    	currentHighlight.blur();
	}
	this.highlight(null);
	
	WndMgr.SetReturnIconClickCallback(null);
}
 
SceneFaceRecogResult.prototype.handleKeyDown = function (keyCode) {
	alert("SceneFaceRecogResult.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	PluginAPIMgr.PlayAudio(keyCode);
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	if(this.flagWaiting==true)
	{
		return;	
	}
	 if(this.isListFocused==true){
	 	if(this.list.CurrentItemIndex==0 && keyCode==sf.key.UP){
	 		this.processUpKey(keyCode);
	 	}else{
	 		this.list.KeyProcess(keyCode);
	 	}
		return;
	}  
	switch (keyCode) {
		case sf.key.LEFT:
			this.processLeftKey();
			break;
		case sf.key.RIGHT:
			// this.processRightKey();
			break;
		case sf.key.UP:          
			this.processUpKey(keyCode);
			break;
		case sf.key.DOWN:
			this.processDownKey(keyCode);
			break;

		case sf.key.ENTER:
            this.processEnterKey(keyCode);
			break;
        
		case sf.key.TOOLS:
            
			break; 
            
        case sf.key.RETURN:
            this.processReturnKey();
            //2013 modify by minseok
            sf.key.preventDefault();
			break;
            
        case sf.key.EXIT:
            this.processExitKey();
            //2013 modify by minseok
            sf.key.preventDefault();
			break;
		
        case 147:  //infolink
        case 261:  //contents
        case 115:  //wiselink
            ProcMgr.processInfolinkKey(); 
			break;
			
		default:
            ProcMgr.processBlockKey(keyCode);
            break;

	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneFaceRecogResult.prototype.create = function(){
    alert("SceneFaceRecogResult.create()");
    this.MainView = new View("FaceRecogResult");
    this.MainView.SetBgImage(g_Image.IMAGE_SKYPE_BG);
    
    this.TitleLabel = new Label(null,"face_recog_result_title");
    this.TitleLabel.SetTextStyle("face_recog_result_title_style");
    // this.TitleLabel.SetText(IDWS_MOIP_WELCOM_TO_SKYPE);  
    this.TitleLabel.SetText(IDWS_MOIP_LOGIN);  
    
    this.CalllistLine = new Label("face_recog_result_calllist_line",null);
    this.CalllistLine.SetBgImage(g_Image.IMAGE_FACERECOGNITION_CALLLIST_LINE);
    
    this.ResultMsg = new Label(null,"face_recog_result_msg");
    this.ResultMsg.SetTextStyle("face_recog_result_msg_style");
    this.ResultMsg.SetText(TV_SELECT_YOUR_ACCOUNT + TV_SELECT_RETRY_IF_YOUR_ACCOUNT_ISNT_SHOWN_MSG);
    
    this.FaceRecogTabSigninLabel = new Label(null,"face_recog_result_tab_signin_text");
    this.FaceRecogTabSigninLabel.SetTextStyle("face_recog_result_tab_text_style");
    this.FaceRecogTabSigninLabel.SetText(TV_ID_PASSWORD_MENU);
    
    this.NoResultMsg = new Label(null,"face_recog_result_no_face");
    this.NoResultMsg.SetTextStyle("face_recog_result_no_face_text_style");
    this.NoResultMsg.SetText(TV_THERE_ARE_NO_RECOGNIZED_FACES);
    
    var this_ = sf.scene.get("FaceRecogResult");
	var clickCF =  function(obj){this_.processClickEvent(obj);};
	var overCF =  function(obj){this_.processMouseOverEvent(obj);};
	
	
    this.FaceRecogTabBtn = new Button();
    this.FaceRecogTabBtn.SetImageObjId("face_recog_result_tab_btn");
	this.FaceRecogTabBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_FACERECOGNITION_TAB_BG);
	this.FaceRecogTabBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_FACERECOGNITION_TAB_HIGHLIGHT_BG);
	this.FaceRecogTabBtn.SetTextObjId("face_recog_result_tab_text");
	this.FaceRecogTabBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"face_recog_tab_text_style");
	this.FaceRecogTabBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"face_recog_tab_text_highlight_style");
	this.FaceRecogTabBtn.SetText(SID_VOICE_FACE_RECOGNITION);
    
    
    this.RetryBtn= new Button();
    this.RetryBtn.SetImageObjId("face_recog_result_retry_btn", 30);
    this.RetryBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_SIGNIN_BTN_NORMAL);
    this.RetryBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_SIGNIN_BTN_NORMALFOCUS);
	this.RetryBtn.SetTextObjId("face_recog_result_retry_btn_text");
    this.RetryBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"face_recog_result_btn_normal_style");
	this.RetryBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"face_recog_result_btn_select_style");
	this.RetryBtn.SetText(SID_RETRY_KR_RETRY);
	this.RetryBtn.SetOnClickCallbackFunc(clickCF);
	this.RetryBtn.SetOnMouseOverCallbackFunc(overCF);
	
    this.CancelBtn= new Button();
    this.CancelBtn.SetImageObjId("face_recog_result_cancel_btn", 30);
    this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_SIGNIN_BTN_NORMAL);
    this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_SIGNIN_BTN_NORMALFOCUS);
	this.CancelBtn.SetTextObjId("face_recog_result_cancel_btn_text");
    this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"face_recog_result_btn_normal_style");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"face_recog_result_btn_select_style");
	this.CancelBtn.SetText(SID_CANCEL);
	this.CancelBtn.SetOnClickCallbackFunc(clickCF);
	this.CancelBtn.SetOnMouseOverCallbackFunc(overCF);
    
    this.FaceRecogMouseBtn = new Button();
	this.FaceRecogMouseBtn.SetImageObjId("face_recog_result_dummy_face_recog_btn");
	this.FaceRecogMouseBtn.SetOnClickCallbackFunc(clickCF);
	this.FaceRecogMouseBtn.SetOnMouseOverCallbackFunc(overCF);
	
	this.IDPWMouseBtn = new Button();
	this.IDPWMouseBtn.SetImageObjId("face_recog_result_dummy_id_password_btn");
	this.IDPWMouseBtn.SetOnClickCallbackFunc(clickCF);
	this.IDPWMouseBtn.SetOnMouseOverCallbackFunc(overCF);
    
    
    this.list = new FaceRecogList();
    this.list.Create("FaceRecogResult","recogList");
    
    this.list.SetEventOnRightFunc(this_.leaveList);
    this.list.SetEventOnReturnFunc(this_.processReturnKey);
    this.list.SetEventOnExitFunc(this_.processExitKey);
    this.flagDataUpdate = false;
    
   
}
SceneFaceRecogResult.prototype.updateList = function(){
	alert("SceneFaceRecogResult.updateList : "+this.flagDataUpdate);
	// if(this.flagDataUpdate==true){
		this.list.InitData();
		// this.flagDataUpdate = false;
	// }
}
SceneFaceRecogResult.prototype.showList = function(){
	alert("SceneFaceRecogResult.showList : "+this.flagNoData);
	if(this.flagNoData==true){
		this.list.Hide();
		this.NoResultMsg.visibleObj();
		
	}else{
		this.list.Show();
		this.NoResultMsg.hiddenObj();
	}
} 


SceneFaceRecogResult.prototype.initData = function(){
    alert("SceneFaceRecogResult.initData() ");
    
    this.DataIndex =0;
   
    if(this.ViewIndex==1)
    {		
    	this.ResultBtn1.SetFgImage("");//init
    	this.ResultBtn1.SetFgImage(this.RecogResult[0].face+g_Data.GetImgSuffixPath());
    	
    	if(this.RecogResult[0].registered== true)
    	{
    		this.ResultText1.SetText(this.RecogResult[0].id);
    	}
    	else
    	{	
    		this.ResultText1.SetText(TV_NOT_REGISTERED);   		
    	}
    }
    else if(this.ViewIndex==2)
    {
    	 for(var a=0; a<this.ViewIndex; a++)
    	{
	    	this.ResultBtn2[a].SetFgImage("");//init
	    	this.ResultBtn2[a].SetFgImage(this.RecogResult[a].face+g_Data.GetImgSuffixPath());
	    	
	    	if(this.RecogResult[a].registered== true)
	    	{
	    		this.ResultText2[a].SetText(this.RecogResult[a].id);
	    	}
	    	else
	    	{
	    		this.ResultText2[a].SetText(TV_NOT_REGISTERED);   		
	    	}
    	}
    }
    else
    {    	
		this.updateView3Data();
		
		if(this.RecogResult.length==3)
		{
			this.hiddenScrollBar();
		}
		else
		{
			this.visibleScrollBar();
		}		
    }  
}

SceneFaceRecogResult.prototype.updateView3Data = function(){
	
	for(var a=0; a<this.ViewIndex; a++)
	{
    	this.ResultBtn3[a].SetFgImage("");//init
    	this.ResultBtn3[a].SetFgImage(this.RecogResult[a+this.DataIndex].face+g_Data.GetImgSuffixPath());
    	
    	if(this.RecogResult[a+this.DataIndex].registered== true)
    	{
    		this.ResultText3[a].SetText(this.RecogResult[a+this.DataIndex].id);
    	}
    	else
    	{
    		this.ResultText3[a].SetText(TV_NOT_REGISTERED);   		
    	}
	}
	
	this.updateScrollBar();
	this.toggleArrow();
}

SceneFaceRecogResult.prototype.hiddenScrollBar = function()
{ 
	this.ScrollBg.hiddenObj();
	this.ScrollLeft.hiddenObj();
	this.ScrollMiddle.hiddenObj();
	this.ScrollRight.hiddenObj();
}

SceneFaceRecogResult.prototype.visibleScrollBar = function()
{ 
	this.ScrollBg.visibleObj();
	this.ScrollLeft.visibleObj();
	this.ScrollMiddle.visibleObj();
	this.ScrollRight.visibleObj();
}

SceneFaceRecogResult.prototype.updateScrollBar = function(){  	 
    var total_item = this.RecogResult.length;//2;
    
    if(total_item==3)
    {
    	return
    }
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
    var max_scroll_length = 634;//331;
    var init_scroll_start_position = 163;//87;
    var curr_scroll_start_position = init_scroll_start_position;
    var curr_scroll_length=0;   

    var scroll_rate= Math.floor(max_scroll_length / total_item);

    var left_item = this.DataIndex;
    var extra_length =max_scroll_length - (scroll_rate*total_item)
    
    curr_scroll_start_position =  init_scroll_start_position +(scroll_rate*left_item);
    curr_scroll_length = (scroll_rate*3) + extra_length;
   
    var middle_left = String(curr_scroll_start_position);
    var middle_width = String(curr_scroll_length);
    
    var scroll_left = String(curr_scroll_start_position-5);
    var scroll_right = String(curr_scroll_start_position+curr_scroll_length);

    $("#face_recog_result_scroll_middle").css("left",  middle_left+"px");
    $("#face_recog_result_scroll_middle").width(middle_width+"px");
    
    $("#face_recog_result_scroll_left").css("left",  scroll_left+"px");
    $("#face_recog_result_scroll_right").css("left",  scroll_right+"px");
    
    
   alert("SceneEditProfile.updateScrollBar() left: "+ scroll_left+" length : "+middle_width+" right : " + scroll_right);

}

SceneFaceRecogResult.prototype.hiddenArrow = function()
{
	alert("SceneFaceRecogResult.hiddenArrow() ");

	this.LeftArrow.hiddenObj();
	this.RightArrow.hiddenObj();
}

SceneFaceRecogResult.prototype.toggleArrow = function()
{
	alert("SceneFaceRecogResult.toggleArrow() ");
	
	if(this.RecogResult.length==3)
    {
    	this.LeftArrow.hiddenObj();
		this.RightArrow.hiddenObj();
    }
    else
    {
    	if(this.DataIndex ==0)
    	{
    		this.LeftArrow.hiddenObj();
    	}
    	else
    	{
    		this.LeftArrow.visibleObj();
    	}
    	
    	if(this.DataIndex+2 ==this.RecogResult.length-1)
    	{
    		this.RightArrow.hiddenObj();
    	}
    	else
    	{
    		this.RightArrow.visibleObj();
    	}
    }
}


SceneFaceRecogResult.prototype.moveDataToLeft= function(){
    alert("SceneFaceRecogResult.moveDataToLeft() ");

    if(this.RecogResult.length==3)
    {
    	return false;
    }
    
	if(this.DataIndex >0)
	{
		this.DataIndex--;
		this.updateView3Data();    		
	}
    
    return true;
}

SceneFaceRecogResult.prototype.moveDataToRight = function(){
    alert("SceneFaceRecogResult.moveDataToRight() ");
    
    if(this.RecogResult.length==3)
    {
    	return false;
    }

	if(this.DataIndex+2 <this.RecogResult.length-1)
	{
		this.DataIndex++;
		this.updateView3Data();    		
	}

    return true;
}

SceneFaceRecogResult.prototype.getSelectedDataIndex= function(){ 
    var currentHighlight =  this.MainView.getCurrentHighlight();
    var btnIndex =0;
    
    if(this.ViewIndex==1)
    {
    	btnIndex=0;
    }
    else if(this.ViewIndex==2)
    {
    	for(btnIndex=0; btnIndex<this.ResultBtn2.length; btnIndex++)
	    {
	    	if(currentHighlight==this.ResultBtn2[btnIndex])
	    	{
	    		break;
	    	}
	    }
    }
    else
    {
    	for(btnIndex=0; btnIndex<this.ResultBtn3.length; btnIndex++)
	    {
	    	if(currentHighlight==this.ResultBtn3[btnIndex])
	    	{
	    		break;
	    	}
	    }
    }
    
    var selectedDataIndex =this.DataIndex+btnIndex;
    
    alert("SceneFaceRecogResult.getSelectedData() selectedDataIndex");
	return selectedDataIndex;
}

SceneFaceRecogResult.prototype.highlight=function(obj)
{
	alert("SceneFaceRecogResult.highlight()");
	if(obj == this.list){
		this.isListFocused = true;
	}else{
		this.isListFocused = false;
	}
	
    this.MainView.setCurrenHighlight(obj);	
}

SceneFaceRecogResult.prototype.processLeftKey = function(){
    alert("SceneFaceRecogResult.processLeftKey() ");
        
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
	   switch(currentHighlight)
	   {
	   		case this.FaceRecogTabBtn:
    			StateMgr.Start_Signin_State();
    		break;
	       case this.RetryBtn:
	       case this.CancelBtn:
	       	if(this.flagNoData==true){
    			return;
    		}else{
				this.highlight(this.list);
    		}
	           break;
	       	
	    }
    
}

SceneFaceRecogResult.prototype.processRightKey = function(){
    alert("SceneFaceRecogResult.processRightKey() ");
     
    var currentHighlight =  this.MainView.getCurrentHighlight();
	
    switch(currentHighlight)
    {
    }
}
SceneFaceRecogResult.prototype.processUpKey = function(keyCode){
	alert("SceneFaceRecogResult.processUpKey() ");
	var currentHighlight =  this.MainView.getCurrentHighlight();
   	
    switch(currentHighlight)
    {
    	case this.list:
    		alert("SceneFaceRecogResult First Item!!");
    		this.highlight(this.FaceRecogTabBtn);
	    	this.isListFocused = false;
    		break;
        case this.RetryBtn:
       		this.highlight(this.FaceRecogTabBtn);
        	break;
        case this.CancelBtn:
       		 this.highlight(this.RetryBtn);
            break;
        
    }
}
SceneFaceRecogResult.prototype.processDownKey = function(keyCode){
    alert("SceneFaceRecogResult.processDownKey() ");
    var currentHighlight =  this.MainView.getCurrentHighlight();
   	
    switch(currentHighlight)
    {
    	case this.FaceRecogTabBtn:
    		this.highlight(this.RetryBtn);
    		break;
        case this.RetryBtn:
       		this.highlight(this.CancelBtn);
        	break;
        case this.CancelBtn:
            break;
        
    }
}


SceneFaceRecogResult.prototype.processEnterKey = function(keyCode){
    alert("SceneFaceRecogResult.processEnterKey() ");
    var currentHighlight =  this.MainView.getCurrentHighlight();

    switch(currentHighlight)
    {       
        // case this.PwdModeBtn:
			// StateMgr.Start_Signin_State(); 			
            // break;
//             
         case this.RetryBtn:
			 ProcMgr.RetryFaceRecogSignin();
             break;
             
        case this.CancelBtn:
			StateMgr.Start_Welcome_State();
            break;
//             
    }
}
SceneFaceRecogResult.prototype.leaveList = function(){
	alert("SceneFaceRecogResult.leavlist");
	var this_ = sf.scene.get("FaceRecogResult");	
	this_.isListFocused = false;
	this_.highlight(this_.RetryBtn);
}

SceneFaceRecogResult.prototype.processReturnKey = function(){
    alert("SceneFaceRecogResult.processReturnKey() ");
	
   StateMgr.Start_Welcome_State();
}

SceneFaceRecogResult.prototype.processExitKey = function(){
    alert("SceneFaceRecogResult.processExitKey() ");
	  
   ProcMgr.ExitWithSignIn();
}


SceneFaceRecogResult.prototype.processClickEvent = function(obj){
	alert("SceneFaceRecogResult.processClickEvent() ");
	
	/*if(obj == this.LeftArrow)
	{
		this.moveDataToLeft();
		return;
	}
	
	if(obj == this.LeftArrow)
	{
		this.moveDataToRight();
		return;
	}*/
	
	/*var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }*/
   if(obj==this.FaceRecogMouseBtn || obj==this.IDPWMouseBtn){
		this.highlight(this.FaceRecogTabBtn);
		if(obj==this.IDPWMouseBtn){
			StateMgr.Start_Signin_State();
		}
		return;
	}
	
	this.processEnterKey();
}
SceneFaceRecogResult.prototype.processMouseOverEvent = function(obj){
	alert("SceneFaceRecogResult.processMouseOverEvent() ");
	var currentHighlight =  this.MainView.getCurrentHighlight();
	if(obj==this.FaceRecogMouseBtn){
		this.highlight(this.FaceRecogTabBtn);
		return;
	}else if(obj==this.IDPWMouseBtn){
		var image_layer = this.FaceRecogTabBtn.GetBGLayer();
		if(currentHighlight==this.FaceRecogTabBtn){
			image_layer.SetBgImage(g_Image.IMAGE_FACERECOGNITION_TAB_HIGHLIGHT_OVER_BG);
		}else{
			image_layer.SetBgImage(g_Image.IMAGE_FACERECOGNITION_TAB_OVER_BG);
		}
		return;
	}else{
		this.FaceRecogTabBtn.GetBGLayer().SetBgImage(g_Image.IMAGE_FACERECOGNITION_TAB_BG);
	}
    if(currentHighlight != obj)
    {
    	if(obj == this.RetryBtn || obj == this.CancelBtn){
    		this.isListFocused = false;
    	}
    	this.highlight(obj);
    }
}
SceneFaceRecogResult.prototype.processClick = function(index){
	alert("SceneFaceRecogResult.processClick() index : "+index);
	// this.list.MoveItem(index);
	this.list.KeyProcess(sf.key.ENTER);
}
SceneFaceRecogResult.prototype.processMouseOver = function(index){
	alert("SceneFaceRecogResult.processMouseOver() index : "+index);
	this.highlight(this.list);
	this.list.MoveItem(index);
	// this.list.KeyProcess(sf.key.ENTER);
}
SceneFaceRecogResult.prototype.hideTabOverImage = function(){
	alert("SceneFaceRecogResult.hideTabOverImage() ");
	var currentHighlight =  this.MainView.getCurrentHighlight();
	switch(currentHighlight){
		case this.FaceRecogTabBtn:
			this.highlight(this.FaceRecogTabBtn);
			break;
		default:
   			this.FaceRecogTabBtn.GetBGLayer().SetBgImage(g_Image.IMAGE_FACERECOGNITION_TAB_BG);
			break;
	}
}
