var SETTINGS = {
	GENERAL : 0,
	FACERECOGNITION : 1,
	VIDEO : 2,
	PRIVACY : 3,
	BLOCKED : 4,
	CALLFORWARDING : 5,
	VOICEMAIL : 6,
	ABOUTSKYPE : 7
};
var SETTINGS_TEXT = [IDWS_MOIP_SKYPE_SETTING_GENERAL_SETTINGS, SID_VOICE_FACE_RECOGNITION, IDWS_MOIP_SKYPE_SETTING_VIDEO_SETTINGS, IDWS_MOIP_SKYPE_SETTING_PRIVACY_SETTINGS, TV_SID_BLOCKED_CONTACTS, IDWS_MOIP_SKYPE_CALL_FORWARDING, IDWS_MOIP_SKYPE_VOICEMAIL, IDWS_MOIP_ABOUT_SKYPE];

function SceneListMainSetting(options) {
	this.options = options;

	this.ListMainSettingView = null;
	this.ListBG = new Array(4);
	this.SettingsBtn = new Array(8);
	this.BtnIdx = 0;

	this.FlagFocus = false;

	this.HelpBarData = null;
	this.destroyFlag = false;
	this.IsShownObj = false;

	this.FR_Enable = true;
}

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

SceneListMainSetting.prototype.handleShow = function() {
	alert("SceneListMainSetting.handleShow()");
	// this function will be called when the scene manager show this scene
	this.IsShownObj = true;
	this.ResetPage();
}

SceneListMainSetting.prototype.handleHide = function() {
	alert("SceneListMainSetting.handleHide()");
	// this function will be called when the scene manager hide this scene
	this.InitFlag = false;
	this.IsShownObj = false;
	this.BtnIdx = 0;
	this.highlight(null);
}

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

	this.FlagFocus = true;
	//
	var currentHighlight = this.ListMainSettingView.getCurrentHighlight();
	if(currentHighlight == null) {
		this.highlight(this.SettingsBtn[this.BtnIdx]);
	} else {
		this.highlight(currentHighlight);
	}
}

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

	this.FlagFocus = false;

	var currentHighlight = this.ListMainSettingView.getCurrentHighlight();
	if(currentHighlight) {
		currentHighlight.blur();
	}
}

SceneListMainSetting.prototype.handleKeyDown = function(keyCode) {
	alert("SceneListMainSetting.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:
			this.processLeftKey();
			break;
		case sf.key.RIGHT:
			break;
		case sf.key.UP:
			this.processUpKey();
			break;
		case sf.key.DOWN:
			this.processDownKey();
			break;

		case sf.key.ENTER:
			this.processEnterKey();
			break;
		case sf.key.RETURN:
			this.processReturnKey();
			sf.key.preventDefault();
			break;
		case sf.key.RED:
			this.processRedKey();
			break;
		/*
		case sf.key.BLUE:
					break;*/
		
		case sf.key.EXIT:
			this.processExitKey();
			sf.key.preventDefault();
			break;

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

		default:
				ProcMgr.processBlockKey(keyCode);
			break;
	}
}

SceneListMainSetting.prototype.processDownKey = function() {
	if(this.BtnIdx >= this.SettingsBtn.length - 1) {
		return;
	}
	alert("SceneListMainSetting.processDownKey() ");

	if(this.FR_Enable == false && this.BtnIdx == SETTINGS.FACERECOGNITION - 1) {++this.BtnIdx;
	}

	this.highlight(this.SettingsBtn[++this.BtnIdx]);
}

SceneListMainSetting.prototype.processUpKey = function() {
	if(this.BtnIdx <= 0) {
		return;
	}
	alert("SceneListMainSetting.processUpKey() ");
	if(this.FR_Enable == false && this.BtnIdx == SETTINGS.FACERECOGNITION + 1) {--this.BtnIdx;
	}
	this.highlight(this.SettingsBtn[--this.BtnIdx]);
}

SceneListMainSetting.prototype.processEnterKey = function() {
	alert("SceneListMainSetting.processEnterKey() ");

	var currentHighlight = this.ListMainSettingView.getCurrentHighlight();
	var IsInCall = ProcMgr.GetIsInCall();

	switch(currentHighlight) {
		case this.SettingsBtn[SETTINGS.GENERAL]:
			this.BtnIdx = SETTINGS.GENERAL;
			StateMgr.Start_SettingsGeneral_State();
			break;

		case this.SettingsBtn[SETTINGS.FACERECOGNITION]:
			this.BtnIdx = SETTINGS.FACERECOGNITION;
			if(IsInCall)
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL);
			else
				StateMgr.Start_SettingsFaceRecognition_State();
			break;
		case this.SettingsBtn[SETTINGS.VIDEO]:
			this.BtnIdx = SETTINGS.VIDEO;
			if(IsInCall)
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL);
			else
				StateMgr.Start_SettingsVideo_State();
			break;
		case this.SettingsBtn[SETTINGS.PRIVACY]:
			this.BtnIdx = SETTINGS.PRIVACY;
			if(IsInCall)
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL);
			else
				StateMgr.Start_SettingsPrivacy_State();
			break;
		case this.SettingsBtn[SETTINGS.BLOCKED]:
			this.BtnIdx = SETTINGS.BLOCKED;
			if(IsInCall)
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL);
			else
				StateMgr.Start_SettingsBlockedContacts_State();
			break;
		case this.SettingsBtn[SETTINGS.CALLFORWARDING]:
			this.BtnIdx = SETTINGS.CALLFORWARDING;
			if(IsInCall)
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL);
			else
				StateMgr.Start_SettingsCallForwarding_State();
			break;
		case this.SettingsBtn[SETTINGS.VOICEMAIL]:
			this.BtnIdx = SETTINGS.VOICEMAIL;
			if(PluginAPIMgr.GetAccountCapability(ENUM_CONTACT_CAPABILITY.CAPABILITY_VOICEMAIL) != "1") {
				StateMgr.Start_SettingsVoicemail_State();
			} else
				StateMgr.Start_SettingsVoicemailUnable_State();
			break;
		case this.SettingsBtn[SETTINGS.ABOUTSKYPE]:
			this.BtnIdx = SETTINGS.ABOUTSKYPE;
			StateMgr.Start_SettingsAboutSkype_State();
			break;
	}
}
SceneListMainSetting.prototype.ReturnToMain = function() {
    WndMgr.ReturnSubToMain();
}
SceneListMainSetting.prototype.processLeftKey = function() {
	alert("SceneListMainSetting.processLeftKey() ");
	WndMgr.ReturnSubToMain();
}

SceneListMainSetting.prototype.processReturnKey = function() {
	alert("SceneListMainSetting.processReturnKey() ");
	WndMgr.ReturnSubToMainContact();
}

SceneListMainSetting.prototype.processRedKey = function() {
	alert("SceneListMainSetting.processRedKey() ");

	StateMgr.Start_Signout_State();
}

SceneListMainSetting.prototype.processExitKey = function() {
	alert("SceneListMainLiveCall.processExitKey() ");

	StateMgr.Start_Exit_State(false);
}
///////// Processing Click evnet  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneListMainSetting.prototype.processClickEvent = function(obj) {
	alert("SceneListMainSetting.processClickEvent() ");

	
	if(this.FlagFocus == false) {
		sf.scene.get('ListMain').selectOnCurrHighlight();
	}
	var currentHighlight = this.ListMainSettingView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
	
	this.processEnterKey();
}
SceneListMainSetting.prototype.setDestroyFlag = function(destroy_flag) {
	this.destroyFlag = destroy_flag;
}

SceneListMainSetting.prototype.processMouseOver = function(obj) {
	alert("SceneListMainSetting.processMouseOver");
	if(this.FlagFocus == false) {
		sf.scene.get('ListMain').selectOnCurrHighlight();
	}
	var currentHighlight = this.ListMainSettingView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
	currentHighlight = this.ListMainSettingView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.SettingsBtn[SETTINGS.GENERAL]:
			this.BtnIdx = SETTINGS.GENERAL;
			break;
		case this.SettingsBtn[SETTINGS.FACERECOGNITION]:
			this.BtnIdx = SETTINGS.FACERECOGNITION;
			break;
		case this.SettingsBtn[SETTINGS.VIDEO]:
			this.BtnIdx = SETTINGS.VIDEO;
			break;
		case this.SettingsBtn[SETTINGS.PRIVACY]:
			this.BtnIdx = SETTINGS.PRIVACY;
			break;
		case this.SettingsBtn[SETTINGS.BLOCKED]:
			this.BtnIdx = SETTINGS.BLOCKED;
			break;
		case this.SettingsBtn[SETTINGS.CALLFORWARDING]:
			this.BtnIdx = SETTINGS.CALLFORWARDING;
			break;
		case this.SettingsBtn[SETTINGS.VOICEMAIL]:
			this.BtnIdx = SETTINGS.VOICEMAIL;
			break;
		case this.SettingsBtn[SETTINGS.ABOUTSKYPE]:
			this.BtnIdx = SETTINGS.ABOUTSKYPE;
			break;
	}
}
SceneListMainSetting.prototype.highlight = function(obj) {
	alert("SceneListMainSetting.highlight");
	
	this.ListMainSettingView.setCurrenHighlight(obj);
}
SceneListMainSetting.prototype.ResetPage = function() {
	alert("SceneListMainSetting.ResetPage()");
	// check facerocognition & camera
	var camState = PluginAPIMgr.GetCameraState();
	if(camState == ENUM_CAM_STATE.CAM_STATE_READY || camState == ENUM_CAM_STATE.CAM_STATE_PLAYING) {
		if(PluginAPIMgr.RecognitionPluginAvailable == false ) {
			this.FR_Enable = false;
		} else {
			if(ProcMgr.IsDualViewMode()==true){
				this.FR_Enable = false;
			}else{
				this.FR_Enable = true;
			}
		}
	} else {
		this.FR_Enable = false;
	}
	if(this.FR_Enable == false ) {
		$("#list_main_setting_item" + SETTINGS.FACERECOGNITION).css("visibility", "hidden");

		for(var i = 2; i < this.SettingsBtn.length; i++)
		$("#list_main_setting_item" + i).css("top", 154 + 62 * (i - 1) + 'px');
	} else {
		$("#list_main_setting_item" + SETTINGS.FACERECOGNITION).css("visibility", "visible");
		for(var i = 2; i < this.SettingsBtn.length; i++) {
			$("#list_main_setting_item" + i).css("top", 154 + 62 * i + 'px');
		}
	}
	if(this.FlagFocus == true) {
		if(this.BtnIdx == 1)
			this.BtnIdx++;
		this.highlight(this.SettingsBtn[this.BtnIdx]);
	}

}
SceneListMainSetting.prototype.create = function() {
	alert("SceneListMainSetting.create()");
	this.ListMainSettingView = new View("ListMainSetting");

	var this_ = sf.scene.get('ListMainSetting');
	var clickCF = function(obj) {
		this_.processClickEvent(obj);
	};
	for(var i = 0; i < this.ListBG.length; i++) {
		this.ListBG[i] = new ImageLayer("list_main_setting_list_bg" + i);
		this.ListBG[i].SetBgImage(g_Image.IMAGE_LIST_MAIN_SETTING_LIST_BG);
	}
	for(var i = 0; i < this.SettingsBtn.length; i++) {
		this.SettingsBtn[i] = new Button();
		this.SettingsBtn[i].SetImageObjId("list_main_setting_item" + i, 30);
		this.SettingsBtn[i].SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_LIST_MAIN_SETTING_BTN_FOCUS);
		this.SettingsBtn[i].SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_LIST_MAIN_SETTING_BTN_DIM);
		this.SettingsBtn[i].SetIconObjId("list_main_setting_item" + i + "_icon");

		this.SettingsBtn[i].SetTextObjId("list_main_setting_item" + i + "_text");
		this.SettingsBtn[i].SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "list_main_setting_btn_text_nor_style");
		this.SettingsBtn[i].SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "list_main_setting_btn_text_sel_style");
		this.SettingsBtn[i].SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "list_main_setting_btn_text_dim_style");
		this.SettingsBtn[i].SetText(SETTINGS_TEXT[i]);
		this.SettingsBtn[i].SetOnClickCallbackFunc(clickCF);
		this.SettingsBtn[i].SetOnMouseOverCallbackFunc(function(obj) {
			this_.processMouseOver(obj);
		});
	}
	this.SettingsBtn[SETTINGS.GENERAL].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_GENERALSETTING_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.GENERAL].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_GENERALSETTING_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.GENERAL].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_GENERALSETTING_ICON_DIM);
	this.SettingsBtn[SETTINGS.FACERECOGNITION].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_FACERECOGNITION_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.FACERECOGNITION].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_FACERECOGNITION_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.FACERECOGNITION].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_FACERECOGNITION_ICON_DIM);
	this.SettingsBtn[SETTINGS.VIDEO].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_VIDEOSETTING_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.VIDEO].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_VIDEOSETTING_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.VIDEO].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_VIDEOSETTING_ICON_DIM);
	this.SettingsBtn[SETTINGS.PRIVACY].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_PRIVACYSETTING_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.PRIVACY].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_PRIVACYSETTING_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.PRIVACY].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_PRIVACYSETTING_ICON_DIM);
	this.SettingsBtn[SETTINGS.BLOCKED].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_BLOCKEDCONTACTS_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.BLOCKED].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_BLOCKEDCONTACTS_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.BLOCKED].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_BLOCKEDCONTACTS_ICON_DIM);
	this.SettingsBtn[SETTINGS.CALLFORWARDING].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_CALLFORWARDING_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.CALLFORWARDING].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_CALLFORWARDING_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.CALLFORWARDING].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_CALLFORWARDING_ICON_DIM);
	this.SettingsBtn[SETTINGS.VOICEMAIL].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_VOICEMAIL_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.VOICEMAIL].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_VOICEMAIL_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.VOICEMAIL].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_VOICEMAIL_ICON_DIM);
	this.SettingsBtn[SETTINGS.ABOUTSKYPE].SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_ABOUTSKYPE_ICON_NORMAL);
	this.SettingsBtn[SETTINGS.ABOUTSKYPE].SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_ABOUTSKYPE_ICON_FOCUS);
	this.SettingsBtn[SETTINGS.ABOUTSKYPE].SetBgIcon(BtnIconIndex.BTN_DIM_ICON, g_Image.IMAGE_LIST_MAIN_SETTING_ABOUTSKYPE_ICON_DIM);

	this.HelpBarData = {
		'red' : IDWS_MOIP_POPUP_EXIT_SIGN_OUT,
		'return' : SID_RETURN
	}
	HelpBar.changeHelpBarItems(this.HelpBarData);

}