var Check_Flag = {
	NORMAL : 0,
	FOCUS : 1,
	DIM : 2,
};
function SceneSettingsFaceRecognition(options) {
	this.options = options;

	this.SettingsFaceRecognitionView = null;
	this.SettingsFaceRecognitionDim = null;
	this.SettingsFaceRecognitionBG = null;

	this.FacePhotoBox = null;
	this.CheckBox = null;
	this.isChecked = false;
	this.AccountLabel = null;
	////add
	this.PasswordLabel = null;

	this.RecognitionBtn = null;
	this.RecognitionDelBtn = null;
	this.CloseBtn = null;
//	this.SaveBtn = null;

	this.InitFlag == true;
}

SceneSettingsFaceRecognition.prototype.initialize = function() {
	alert("SceneSettingsFaceRecognition.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();
}

SceneSettingsFaceRecognition.prototype.handleShow = function() {
	alert("SceneSettingsFaceRecognition.handleShow()");
	// this function will be called when the scene manager show this scene

	WndMgr.startPopupHideTimer(60000);
	this.UpdateCheckBox();
	this.GetMyPhoto();
	// this.ChangeCheckBoxBg(Check_Flag.NORMAL);
	//modify by minseok :  temporary exception handling
	if(this.CheckCameraFaceRecognition()== false){
		alert("no facerecognition!!");
		this.RecognitionBtn.SetFlagDim(true);
	}
	else
	{
		this.RecognitionBtn.SetFlagDim(false);
	}
}

SceneSettingsFaceRecognition.prototype.handleHide = function() {
	alert("SceneSettingsFaceRecognition.handleHide()");
	// this function will be called when the scene manager hide this scene
	this.SettingsFaceRecognitionDim.hide();
	this.highlight(null);
	WndMgr.stopPopupHideTimer();
}

SceneSettingsFaceRecognition.prototype.handleFocus = function() {
	alert("SceneSettingsFaceRecognition.handleFocus()");
	// this function will be called when the scene manager focus this scene
	this.SettingsFaceRecognitionDim.show();
	if(this.RecognitionBtn.GetFlagDim()==true){
		this.highlight(this.CloseBtn);
	}else{
		this.highlight(this.RecognitionBtn);
	}
}

SceneSettingsFaceRecognition.prototype.handleBlur = function() {
	alert("SceneSettingsFaceRecognition.handleBlur()");
	// this.ChangeCheckBoxBg(Check_Flag.DIM);
	// this function will be called when the scene manager move focus to another scene from this scene
}

SceneSettingsFaceRecognition.prototype.handleKeyDown = function(keyCode) {
	alert("SceneSettingsFaceRecognition.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	PluginAPIMgr.PlayAudio(keyCode);
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	switch (keyCode) {
		case sf.key.LEFT:
			WndMgr.resetPopupHideTimer();
			this.processLeftKey();
			break;
		case sf.key.RIGHT:
			WndMgr.resetPopupHideTimer();
			this.processRightKey();
			break;
		case sf.key.UP:
			WndMgr.resetPopupHideTimer();
			this.processUpKey();
			break;
		case sf.key.DOWN:
			WndMgr.resetPopupHideTimer();
			this.processDownKey();
			break;

		case sf.key.ENTER:
			this.processEnterKey();
			break;

		case sf.key.RETURN:
		case sf.key.EXIT:
			this.processReturnKey();
			sf.key.preventDefault();
			break;

		case 147:
		//infolink
		case 261:
		//contents
		case 115:
			//wiselink
			ProcMgr.processInfolinkKey();
			break;
	}
}

SceneSettingsFaceRecognition.prototype.processReturnKey = function() {
	alert("SceneSettingsFaceRecognition.processReturnKey() ");
	StateMgr.Stop_SettingsFaceRecognition_State(true);
}
SceneSettingsFaceRecognition.prototype.processExitKey = function() {
	alert("SceneSettingsFaceRecognition.processExitKey() ");
	StateMgr.Stop_SettingsFaceRecognition_State(true);
}

SceneSettingsFaceRecognition.prototype.processMouseOver = function(obj) {
	var currentHighlight = this.SettingsFaceRecognitionView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
	WndMgr.resetPopupHideTimer();
}
SceneSettingsFaceRecognition.prototype.highlight = function(obj) {
	// if(obj == this.CheckBox) {
		// this.ChangeCheckBoxBg(Check_Flag.FOCUS);
	// } else {
		// this.ChangeCheckBoxBg(Check_Flag.NORMAL);
	// }

	this.SettingsFaceRecognitionView.setCurrenHighlight(obj);

}
SceneSettingsFaceRecognition.prototype.select=function(obj)
{
	alert("SceneSettingsFaceRecognition.select()");
	
     this.SettingsFaceRecognitionView.setCurrentSelect(obj);
}
SceneSettingsFaceRecognition.prototype.processClickEvent = function(obj) {
	alert("SceneSettingsFaceRecognition.processClickEvent() ");

	var currentHighlight = this.SettingsFaceRecognitionView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
	this.processEnterKey();
}
SceneSettingsFaceRecognition.prototype.processUpKey = function() {
	alert("SceneSettingsFaceRecognition.processUpKey()");
	var currentHighlight = this.SettingsFaceRecognitionView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.CheckBox:
			if(this.RecognitionDelBtn.GetFlagDim()== true){
				this.highlight(this.RecognitionBtn);
			}else{
				this.highlight(this.RecognitionDelBtn);
			}
			break;
		case this.RecognitionBtn:
			break;
		case this.RecognitionDelBtn:
			if(this.RecognitionBtn.GetFlagDim()== false){
				this.highlight(this.RecognitionBtn);
			}
			break;
		case this.CloseBtn:
			break;
		/*
		case this.SaveBtn:
					this.highlight(this.CloseBtn);
					break;*/
		

	}
}
SceneSettingsFaceRecognition.prototype.processDownKey = function() {
	alert("SceneSettingsFaceRecognition.processDownKey()");
	var currentHighlight = this.SettingsFaceRecognitionView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.CheckBox:
			break;
		case this.RecognitionBtn:
			if(this.RecognitionDelBtn.GetFlagDim()== true){
				if(this.CheckBox.GetFlagDim()==false){
					this.highlight(this.CheckBox);
				}
			}else{
				this.highlight(this.RecognitionDelBtn);
			}
			break;
		case this.RecognitionDelBtn:
			if(this.CheckBox.GetFlagDim()==false){
					this.highlight(this.CheckBox);
				}
			break;
		/*
		case this.CloseBtn:
					this.highlight(this.SaveBtn);
					break;
		
		case this.SaveBtn:
			break;*/
	}
}
SceneSettingsFaceRecognition.prototype.processLeftKey = function() {
	alert("SceneSettingsFaceRecognition.processLeftKey()");
	var currentHighlight = this.SettingsFaceRecognitionView.getCurrentHighlight();
	switch(currentHighlight) {
		/*case this.CheckBox:
			break;
		case this.RecognitionBtn:
			this.highlight(this.CheckBox);
			break;
		case this.RecognitionDelBtn:
			this.highlight(this.CheckBox);
			break;*/
		case this.CloseBtn:
			//modify by minseok 140124
			if(this.RecognitionBtn.GetFlagDim()== false){
				this.highlight(this.RecognitionBtn);
			}
			break;
		/*
		case this.SaveBtn:
					this.highlight(this.RecognitionDelBtn);
					break;*/
		
		
	}
}

SceneSettingsFaceRecognition.prototype.processRightKey = function() {
	alert("SceneSettingsFaceRecognition.processRightKey()");
	var currentHighlight = this.SettingsFaceRecognitionView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.CheckBox:
			/*if(this.RecognitionBtn.GetFlagDim()== true){
				this.highlight(this.RecognitionDelBtn);
			}else{
				this.highlight(this.RecognitionBtn);
			}*/
			this.highlight(this.CloseBtn);
			break;
		case this.RecognitionBtn:
			this.highlight(this.CloseBtn);
			break;
		case this.RecognitionDelBtn:
			this.highlight(this.CloseBtn);
			break;
		case this.CloseBtn:
			break;
		/*
		case this.SaveBtn:
					break;*/
		
		
	}
}
SceneSettingsFaceRecognition.prototype.processEnterKey = function() {
	alert("SceneSettingsFaceRecognition.processEnterKey()");

	var currentHighlight = this.SettingsFaceRecognitionView.getCurrentHighlight();
	 this.select(currentHighlight);
	switch(currentHighlight) {
		case this.CheckBox:
			// if(this.isChecked == false) {
				// this.CheckBox.SetFgImage("");
				// this.CheckBox.SetBgImage(0, g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_CHECK);
				// this.CheckBox.SetBgImage(1, g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_CHECKED);
				// this.isChecked = true;
			// } else {
				// this.CheckBox.SetBgImage(0, "");
				// this.CheckBox.SetBgImage(1, "");
				// this.CheckBox.SetFgImage(g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_FOCUS);
				// this.isChecked = false;
			// }
			ProcMgr.SetFlagPwdCheck(this.CheckBox.GetFlagSelect());			
			break;
		case this.RecognitionBtn:
			ProcMgr.StartFaceRecogRegistration();
			break;
		case this.RecognitionDelBtn:
			ProcMgr.DeleteFaceRecog();
			break;
	/*
		case this.SaveBtn:
				this.SaveBrithDate();
				break;*/
	
		case this.CloseBtn:
			this.processReturnKey();
			break;
	}
}
SceneSettingsFaceRecognition.prototype.UpdateCheckBox = function(){
	var pwd_check = ProcMgr.GetFlagPwdCheck();
	alert("SceneSettingsFaceRecognition.UpdateCheckBox() : "+pwd_check);
	if(pwd_check==true){
		this.CheckBox.SetFlagSelect(true);
	}else{
		this.CheckBox.SetFlagSelect(false);
	}
	
}
//this.BerforeChk/*
/*
SceneSettingsFaceRecognition.prototype.ChangeCheckBoxBg = function(flag) {
	alert("SceneSettingsFaceRecognition.ChangeCheckBoxBg()");
	if(this.isChecked == true)
		return;
	switch(flag) {
		case Check_Flag.NORMAL:
			this.CheckBox.SetFgImage(g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_NORMAL);
			break;
		case Check_Flag.FOCUS:
			this.CheckBox.SetFgImage(g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_FOCUS);
			break;
		case Check_Flag.DIM:
			this.CheckBox.SetFgImage(g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_DIM);
			break;
	}
}*/
//add by minseok
SceneSettingsFaceRecognition.prototype.GetMyPhoto = function(){
	var ImagePath = ProcMgr.GetMyFaceImagePath();
	alert("SceneSettingsFaceRecognition.GetMyPhoto() : "+ImagePath);
	if(ImagePath!=""){
		this.FacePhotoBox.SetFgImage(ImagePath+g_Data.GetImgSuffixPath());
		this.RecognitionDelBtn.SetFlagDim(false);
		this.CheckBox.SetFlagDim(false);
	}else{
		this.FacePhotoBox.SetFgImage(g_Image.IMAGE_SETTINGS_FACERECOGNITION_PHOTO_DEFAULT);
		this.RecognitionDelBtn.SetFlagDim(true);
		this.CheckBox.SetFlagDim(true);
	}
}
SceneSettingsFaceRecognition.prototype.CheckCameraFaceRecognition = function(){
	var FaceEnable = true;
	
	var camState = PluginAPIMgr.GetCameraState();
	if(camState ==  ENUM_CAM_STATE.CAM_STATE_READY || camState == ENUM_CAM_STATE.CAM_STATE_PLAYING)
	{
		if(PluginAPIMgr.RecognitionPluginAvailable== false)
		{
			FaceEnable = false;
		}
		else
		{
			FaceEnable = true;
		}
	}
	else
	{
		FaceEnable = false;
	}
	return FaceEnable;
}
SceneSettingsFaceRecognition.prototype.create = function() {
	alert("SceneSettingsFaceRecognition.create()");
	this.SettingsFaceRecognitionView = new View("SettingsFaceRecognition");
	this.SettingsFaceRecognitionBG = new View("SettingsFaceRecognitionBG");
	this.SettingsFaceRecognitionBG.CreatePopupBG(0, "SettingsFaceRecognition_popup_BG");
	this.SettingsFaceRecognitionBG.CreateInnerBox("SettingsFaceRecognition_popup_innerbox");
	this.SettingsFaceRecognitionBG.SetTitleTextofPopupBG(SID_VOICE_FACE_RECOGNITION);
	this.SettingsFaceRecognitionDim = new DimBg("SettingsFaceRecognitionDim", "SettingsFaceRecognitionBG");

	var this_ = sf.scene.get("SettingsFaceRecognition");
	var clickCF = function(obj) {
		this_.processClickEvent(obj);
	};

	this.FacePhotoBox = new Label("settingsfacerecognition_photo_box");
	this.FacePhotoBox.AppendFgImage("face_phoho_box", "0px", "0px", "110px", "110px");
	this.FacePhotoBox.SetFgImage(g_Image.IMAGE_SETTINGS_FACERECOGNITION_PHOTO_DEFAULT);

	/*this.CheckBox = new Button();
	this.CheckBox.SetImageObjId("settingsfacerecognition_password_check_box");
	this.CheckBox.AppendFgImage("settingsfacerecognition_password_check_box_bg", "3.5px", "3.5px", "29px", "29px");
*/
	 this.CheckBox=new CheckBox();
    this.CheckBox.SetImageObjId("settingsfacerecognition_password_check_box");
    this.CheckBox.SetBgImage(CBoxImgIndex.CB_NORMAL_IMG,  g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_NORMAL);
    this.CheckBox.SetBgImage(CBoxImgIndex.CB_NORMAL_FOCUS_IMG,  g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_FOCUS);
    this.CheckBox.SetBgImage(CBoxImgIndex.CB_DIM_IMG,  g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_DIM);
    this.CheckBox.SetTextObjId("settingsfacerecognition_password_label");
    this.CheckBox.SetText(TV_I_WANT_TO_ENTER_PASSWORD_AS_WELL_FOR_INCREASED_SECURITY_MSG);
    this.CheckBox.SetTextStyle("settingsfacerecognition_label_style");
    this.CheckBox.SetTextDimStyle("settingsfacerecognition_dim_style");
    this.CheckBox.AppendFgImage("settingsfacerecognition_password_check_box_bg","0px","0px","29px","29px");
    this.CheckBox.SetFgImage(g_Image.IMAGE_SETTINGS_FACERECOGNITION_CHECKBOX_CHECK); 
	this.CheckBox.SetOnClickCallbackFunc(clickCF);

	// this.PasswordLabel = new TextLayer("settingsfacerecognition_password_label");
	// this.PasswordLabel.SetTextStyle("settingsfacerecognition_label_style");
	// this.PasswordLabel.SetText(TV_I_WANT_TO_ENTER_PASSWORD_AS_WELL_FOR_INCREASED_SECURITY_MSG);

	this.RecognitionBtn = new Button();
	this.RecognitionBtn.SetImageObjId("settingsfacerecognition_recognition_btn", 20);
	this.RecognitionBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.RecognitionBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.RecognitionBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
	this.RecognitionBtn.SetTextObjId("settingsfacerecognition_recognition_btn_text");
	this.RecognitionBtn.SetText(TV_REGISTER_FACE_BTTN);
	this.RecognitionBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.RecognitionBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.RecognitionBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.RecognitionBtn.SetOnClickCallbackFunc(clickCF);

	this.RecognitionDelBtn = new Button();
	this.RecognitionDelBtn.SetImageObjId("settingsfacerecognition_recognition_del_btn", 20);
	this.RecognitionDelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.RecognitionDelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.RecognitionDelBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
	this.RecognitionDelBtn.SetTextObjId("settingsfacerecognition_recognition_del_btn_text");
	this.RecognitionDelBtn.SetText(SID_DELETE);
	this.RecognitionDelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.RecognitionDelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.RecognitionDelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.RecognitionDelBtn.SetOnClickCallbackFunc(clickCF);

	var btn_size = this.RecognitionBtn.text_layer.GetMaxWidthTextArray(TV_REGISTER_FACE_BTTN,SID_DELETE);
	this.RecognitionBtn.ResizeButton("L",btn_size);
	this.RecognitionDelBtn.ResizeButton("L",btn_size);
/*
	this.SaveBtn = new Button();
	this.SaveBtn.SetImageObjId("settingsfacerecognition_save_btn", 20);
	this.SaveBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.SaveBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.SaveBtn.SetTextObjId("settingsfacerecognition_save_btn_text");
	this.SaveBtn.SetText(SID_SAVE);
	this.SaveBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.SaveBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.SaveBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.SaveBtn.SetOnClickCallbackFunc(clickCF);*/


	this.CloseBtn = new Button();
	this.CloseBtn.SetImageObjId("settingsfacerecognition_close_btn", 20);
	this.CloseBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.CloseBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);

	this.CloseBtn.SetTextObjId("settingsfacerecognition_close_btn_text");
	this.CloseBtn.SetText(SID_CLOSE);
	this.CloseBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.CloseBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.CloseBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.CloseBtn.SetOnClickCallbackFunc(clickCF);
	
	this.CheckBox.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.RecognitionBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.RecognitionDelBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.CloseBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
}