var CALLER_ID = {
	ALLOW_CALL : "settingsprivacy_allow_call_btn",
	VIDEO_FROM : "settingsvideo_video_from_btn",
	VIDEO_TO : "settingsvideo_video_to_btn"
}
var SUBLIST_ITEMS = {
	"settingsprivacy_allow_call_btn" : [IDWS_MOIP_SETTING_ANYONE, TV_SID_PEOPLE_IN_MY_CONTACT_LIST_ONLY],
	"settingsvideo_video_from_btn" : [IDWS_MOIP_SETTING_ANYONE, TV_SID_PEOPLE_IN_MY_CONTACT_LIST_ONLY, IDWS_MOIP_SETTING_NONE],
	"settingsvideo_video_to_btn" : [TV_SID_PEOPLE_IN_MY_CONTACT_LIST_ONLY, IDWS_MOIP_SETTING_NONE]
}
function SceneSettingsSubList(options) {
	this.options = options;
	this.callerObj = null;
	this.cbFunc = null;
	this.curValue = "";

	this.SettingsSubListView = null;
	this.SubList = null;
	this.Btn1 = null;
	this.Btn2 = null;
	this.Btn3 = null;
	this.BgItemNum = 0;
}

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

SceneSettingsSubList.prototype.handleShow = function() {
	alert("SceneSettingsSubList.handleShow()");
	// this function will be called when the scene manager show this scene
	this.callerObj = null;
	this.cbFunc = null;
	this.curValue = null;
}

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

SceneSettingsSubList.prototype.handleFocus = function() {
	alert("SceneSettingsSubList.handleFocus()");
	// this function will be called when the scene manager focus this scene
	var obj = this.SettingsSubListView.getCurrentHighlight();
	if(obj != null)
	{
		this.highlight(obj);
	}
}

SceneSettingsSubList.prototype.handleBlur = function() {
	alert("SceneSettingsSubList.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
	var obj = this.SettingsSubListView.getCurrentHighlight();
	if(obj != null)
	{
		obj.blur();	
	}
}

SceneSettingsSubList.prototype.handleKeyDown = function(keyCode) {
	alert("SceneSettingsSubList.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:
		case sf.key.RIGHT:
			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;
	}
}

SceneSettingsSubList.prototype.processReturnKey = function() {

	alert("SceneSettingsSubList.ProcessKeyReturn()");
	WndMgr.StopSettingsSubList();
}

SceneSettingsSubList.prototype.processMouseOver = function(obj) {
	var currentHighlight = this.SettingsSubListView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
}

SceneSettingsSubList.prototype.highlight = function(obj) {
	this.SettingsSubListView.setCurrenHighlight(obj);
}

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

	var currentHighlight = this.SettingsSubListView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
	this.processEnterKey();
}
SceneSettingsSubList.prototype.processUpKey = function() {
	alert("SceneSettingsSubList.processUpKey()");
	var currentHighlight = this.SettingsSubListView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.Btn1:
			if(this.BgItemNum==3)
				this.highlight(this.Btn3);
			else
				this.highlight(this.Btn2);
			break;
		case this.Btn2:
			this.highlight(this.Btn1);
			break;
		case this.Btn3:
			this.highlight(this.Btn2);
			break;
	}
}
SceneSettingsSubList.prototype.processDownKey = function() {
	alert("SceneSettingsSubList.processDownKey()");
	var currentHighlight = this.SettingsSubListView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.Btn1:
			this.highlight(this.Btn2);
			break;
		case this.Btn2:
			if(this.BgItemNum==3)
				this.highlight(this.Btn3);
			else
				this.highlight(this.Btn1);
			break;
		case this.Btn3:
			this.highlight(this.Btn1);
			break;
	}
}
SceneSettingsSubList.prototype.processEnterKey = function() {
	alert("SceneSettingsSubList.processEnterKey()");
	var currentHighlight = this.SettingsSubListView.getCurrentHighlight();
	this.curValue = currentHighlight.GetText();
	this.callerObj.SetText(this.curValue);
	WndMgr.StopSettingsSubList();



}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
SceneSettingsSubList.prototype.create = function() {
	alert("SceneSettingsSubList.create() ");
	this.SettingsSubListView = new View("SettingsSubList");
	this.SubList = new View("SubList");
	this.SubList.CreatePopupBG(2, "SubList3_BG");
	this.BgItemNum = 3;
	var this_ = sf.scene.get("SettingsSubList");

	this.Btn1 = new Button();
	this.Btn1.SetImageObjId("sublist_btn1", 30);
	this.Btn1.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_LIST_SELECTION_HIGH);
	this.Btn1.SetTextObjId("sublist_btn1_text");
	this.Btn1.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "sublist_btn_text_normal_style");
	this.Btn1.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "sublist_btn_text_focus_style");
	this.Btn1.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "sublist_btn_text_dim_style");
	this.Btn1.SetOnClickCallbackFunc(function(obj) {
		this_.processClickEvent(obj);
	});
	this.Btn2 = new Button();
	this.Btn2.SetImageObjId("sublist_btn2", 30);
	this.Btn2.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_LIST_SELECTION_HIGH);
	this.Btn2.SetTextObjId("sublist_btn2_text");
	this.Btn2.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "sublist_btn_text_normal_style");
	this.Btn2.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "sublist_btn_text_focus_style");
	this.Btn2.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "sublist_btn_text_dim_style");
	this.Btn2.SetOnClickCallbackFunc(function(obj) {
		this_.processClickEvent(obj);
	});

	this.Btn3 = new Button();
	this.Btn3.SetImageObjId("sublist_btn3", 30);
	this.Btn3.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_LIST_SELECTION_HIGH);
	this.Btn3.SetTextObjId("sublist_btn3_text");
	this.Btn3.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "sublist_btn_text_normal_style");
	this.Btn3.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "sublist_btn_text_focus_style");
	this.Btn3.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "sublist_btn_text_dim_style");
	this.Btn3.SetOnClickCallbackFunc(function(obj) {
		this_.processClickEvent(obj);
	});
	
	this.Btn1.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.Btn2.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.Btn3.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
}

SceneSettingsSubList.prototype.start = function(callerObj, sceneObj, cbFunc, curValue) {
	alert("SceneSettingsSubList.start() " + callerObj.GetObjId());
	var item1, item2, item3;
	var oneHeight = 61;
	var posTop = parseInt($("#" + callerObj.GetObjId()).css('top').replace(/[^-\d\.]/g, '')) + 1;
	var posHeight = parseInt($("#" + callerObj.GetObjId()).css('height').replace(/[^-\d\.]/g, '')) - 15;
	var posLeft = parseInt($("#" + callerObj.GetObjId()).css('left').replace(/[^-\d\.]/g, '')) + 15;
	
	var sceneTop = parseInt($("#" + sceneObj.GetObjId()).css('top').replace(/[^-\d\.]/g, '')) + 1;
	var sceneLeft = parseInt($("#" + sceneObj.GetObjId()).css('left').replace(/[^-\d\.]/g, '')) + 1;
	var sceneWidth = parseInt($("#" + sceneObj.GetObjId()).css('width').replace(/[^-\d\.]/g, '')) + 1;
	var sceneHeight = parseInt($("#" + sceneObj.GetObjId()).css('height').replace(/[^-\d\.]/g, '')) + 1;
	//Adjust position
    var this_ = this;
	$("#SettingsSubList").css("top", sceneTop + "px");
	$("#SettingsSubList").css("left", sceneLeft + "px");
	$("#SettingsSubList").css("height", sceneHeight + "px");
	$("#SettingsSubList").css("width", sceneWidth + "px");
	$("#SettingsSubList").bind("click", this_.processReturnKey);
	$("#SubList").css("top", posTop + posHeight  + "px");
	$("#SubList").css("left", posLeft  + "px");
	switch(callerObj.GetObjId()) {
		case CALLER_ID.ALLOW_CALL:
			item1 = eval('SUBLIST_ITEMS.' + CALLER_ID.ALLOW_CALL + '[0]');
			item2 = eval('SUBLIST_ITEMS.' + CALLER_ID.ALLOW_CALL + '[1]');
			this.Btn3.hiddenObj();
			if(this.BgItemNum !=2){
				this.SubList.ChangePopupBGSize("SubList2_BG");
				this.BgItemNum=2;
			}
			switch(curValue){
				case item1:
					this.highlight(this.Btn1);
					break;
				case item2:
					this.highlight(this.Btn2);
					break;
				case item3:
					this.highlight(this.Btn3);
					break;
			}
			$("#SubList").css("height", oneHeight * 3 + "px");
			break;
		case CALLER_ID.VIDEO_FROM:
			item1 = eval('SUBLIST_ITEMS.' + CALLER_ID.VIDEO_FROM + '[0]');
			item2 = eval('SUBLIST_ITEMS.' + CALLER_ID.VIDEO_FROM + '[1]');
			item3 = eval('SUBLIST_ITEMS.' + CALLER_ID.VIDEO_FROM + '[2]');
			this.Btn3.SetText(item3);
			this.Btn3.visibleObj();
			if(this.BgItemNum !=3){
				this.SubList.ChangePopupBGSize("SubList3_BG");
				this.BgItemNum=3;
			}
			alert("curval="+curValue +" item="+item1+"/"+item2+"/"+item3);
			switch(curValue){
				case item1:
					this.highlight(this.Btn1);
					break;
				case item2:
					this.highlight(this.Btn2);
					break;
				case item3:
					this.highlight(this.Btn3);
					break;
			}
			$("#SubList").css("height", oneHeight * 2 + "px");
			break;
		case CALLER_ID.VIDEO_TO:
			item1 = eval('SUBLIST_ITEMS.' + CALLER_ID.VIDEO_TO + '[0]');
			item2 = eval('SUBLIST_ITEMS.' + CALLER_ID.VIDEO_TO + '[1]');
			if(this.BgItemNum !=2){
				this.SubList.ChangePopupBGSize("SubList2_BG");
				this.BgItemNum=2;
			}
			this.Btn3.hiddenObj();
			switch(curValue){
				case item1:
					this.highlight(this.Btn1);
					break;
				case item2:
					this.highlight(this.Btn2);
					break;
			}
	
			break;
		default:
			break;
	}
	this.Btn1.SetText(item1);
	this.Btn2.SetText(item2);

	this.callerObj = callerObj;
	this.cbFunc = cbFunc;
	this.curValue = curValue;
	
}