
var CAMERA_SETTING = {  
 	NOTHING						: 0,
 	LIGHT_ADJUSTMENT_BTN		: 1,
	CONTROL_ZOOM_BTN			: 2
}

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

    this.PopupView		= null;
    this.FaceSublistView = null;
     
    this.flag_shown_sublist = false;
	this.flag_focus = false;

	this.flag_shown_cam_adjustment_btn		= false;
	this.flag_shown_zoom_btn				= false;
	this.flag_disable_zoom_btn 				= false;
	this.flag_dim_light_adjust				= false;
        
	this.UpArrow	= null;
	this.DownArrow	= null;
	
	this.line_top = null;
	this.line_center = null;
	this.line_bottom = null;
	
	this.tip_text = null;
	
	this.lightValue = 0;
   
	this.current_highlight = CAMERA_SETTING.NOTHING;
   
}

SceneCallSettingPopup.prototype.initialize = function () {
	alert("SceneCallSettingPopup.initialize()");

   this.create();
}

SceneCallSettingPopup.prototype.handleShow = function () {
	alert("SceneCallSettingPopup.handleShow()");

    this.update();
	WndMgr.startPopupHideTimer(30000);
}

SceneCallSettingPopup.prototype.handleHide = function () {
	alert("SceneCallSettingPopup.handleHide()");
				
	WndMgr.stopPopupHideTimer();
}

SceneCallSettingPopup.prototype.handleFocus = function () {
	alert("SceneCallSettingPopup.handleFocus()");
	
	if(this.current_highlight == CAMERA_SETTING.NOTHING)
	{		
		if(this.flag_shown_cam_adjustment_btn == true && this.flag_dim_light_adjust == false)
		{
			this.highlight(CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN);			
		}
		else
		{
			this.highlight(CAMERA_SETTING.CONTROL_ZOOM_BTN);
		}
	}
	else
	{
		this.highlight(this.current_highlight);
	}
	this.flag_focus = true;
}

SceneCallSettingPopup.prototype.handleBlur = function () {
	alert("SceneCallSettingPopup.handleBlur()");
	
	this.highlight(CAMERA_SETTING.NOTHING);
	this.flag_focus = false;
}

SceneCallSettingPopup.prototype.handleKeyDown = function (keyCode) {
	alert("SceneCallSettingPopup.handleKeyDown(" + keyCode + ")");
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	switch (keyCode) 
	{
		case sf.key.UP:
			this.processUpKey();
			WndMgr.resetPopupHideTimer(); 
			break;
			
		case sf.key.DOWN:
            this.processDownKey();
			WndMgr.resetPopupHideTimer();             
			break;

		case sf.key.ENTER:
            this.processEnterKey();
			WndMgr.resetPopupHideTimer();             
			break;
            
        case sf.key.RETURN:
        case sf.key.EXIT:
            this.processReturnKey();
            sf.key.preventDefault();
			break;

		case 602:	//INFOLINK
		case 606:	//CONTENTS
		case 608:	//WISELINK
            sf.key.preventDefault();
			break;
	}
}

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

SceneCallSettingPopup.prototype.create = function(){
    alert("CallSettingPopup.create()");
    
    this.PopupView = new View("CallSettingPopup");
    this.PopupView.SetBgImage(g_Image.IMAGE_POPUP_DIM_BG);
 
	var this_ = sf.scene.get("CallSettingPopup");	

		
	//check number of menu to mkae bg size
	var menu_count = 0;
	if(ProcMgr.ProductInfo.model_code != TV_MODEL_CODE.X12)
	{
		this.flag_shown_cam_adjustment_btn = true;
		menu_count++;
	}
	if(ProcMgr.ProductInfo.capability_eptz == true)
	{
		this.flag_shown_zoom_btn = true;
		menu_count++;
	}
	
	this.PopupView.CreatePopupBG(0,'call_setting_popup_style');
	
	//0. set popup title
	this.PopupView.SetTitleTextofPopupBG(TV_SID_VIDEO_CALL_SETTINGS);
	
	//1. camera adjustment 
 	if(this.flag_shown_cam_adjustment_btn == true)
	{		
		$('#call_setting_popup_message').sfLabel({text:TV_CAMERA_LIGHT_ADJUSTMENT});

		$('#call_setting_popup_btn').sfButton({text:[COM_SID_MEDIUM]});
		$('#call_setting_popup_btn').bind('click',function(){this_.processBtnClick();}); 
		$('#call_setting_popup_btn').bind('mouseover',function(){this_.processBtnOver();});
		
		if(menu_count == 2)
		{
			$('#call_setting_popup_message').css('top','55px');
			$('#call_setting_popup_btn').css('top','45px');
		}
		else if(menu_count == 1)
		{
			$('#call_setting_popup_message').css('top','95px');
			$('#call_setting_popup_btn').css('top','85px');
		}
 	}
 	else
 	{
 		$('#call_setting_popup_message').css('display','none');
 		$('#call_setting_popup_btn').css('display','none');
 	}
 	
	if(this.flag_shown_zoom_btn == true)
	{
		$('#call_setting_popup_camera_zoom_btn').sfButton({text:[IDWS_MOIP_SKYPE_CAMERA_ZOOM]});
		$('#call_setting_popup_camera_zoom_btn').bind('click',function(){this_.processZoomBtnClick();});
		$('#call_setting_popup_camera_zoom_btn').bind('mouseover',function(){this_.processZoomBtnOver();});
		
		//first positon - only one
		if(this.flag_shown_cam_adjustment_btn == false)
		{
			$('#call_setting_popup_camera_zoom_btn').css('top','80px');
		}
		//second positon - just two
		else
		{
			$('#call_setting_popup_camera_zoom_btn').css('top','130px');
		}
	}
	else
	{
		$('#call_setting_popup_camera_zoom_btn').css('display','none');
	}

	
	this.line = new CompBase();
	this.line.CreateBG("call_setting_line_bg");
	this.line.AddImageLayer("call_setting_line_top");
	this.line.AddImageLayer("call_setting_line_center");
	this.line.AddImageLayer("call_setting_line_bottom");

	this.line.SetImageLayer(1,g_Image.IMAGE_CALL_VIDEO_SETTING_TOP);		//bg
	this.line.SetImageLayer(2,g_Image.IMAGE_CALL_VIDEO_SETTING_CENTER);		//bg
	this.line.SetImageLayer(3,g_Image.IMAGE_CALL_VIDEO_SETTING_BOTTOM);		//bg
	
	
	this.tip_text = new Label(null,'call_setting_popup_tip_text');
	
}

SceneCallSettingPopup.prototype.update = function(){
    alert("SceneCallSettingPopup.update()");

	if(this.flag_shown_cam_adjustment_btn == true)
	{
		this.lightValue = PluginAPIMgr.GetCameraLightMode();	
		this.changeLightAdjustmentBtnText(this.lightValue);
	}
	
	if(ProcMgr.IsReceivingVideo() == false)
	{
		 this.dimLightAdjustmentBtn(true);
	}
	else
	{
		this.dimLightAdjustmentBtn(false);
	}
	
	if(PluginAPIMgr.GetFaceTracking() == true)
	{
		this.disableCameraZoomBtn(true);
	}
	else
	{
		this.disableCameraZoomBtn(false);
	}
}

SceneCallSettingPopup.prototype.changeLightAdjustmentBtnText = function(value)
{
    alert("SceneCallSettingPopup.changeLightAdjustmentBtnText("+value+")");
    
	var valueText = null;
		
	if(value == 1)
	{
		valueText = SID_LOW_KR_VOL;
	}
	else if(value == 2)
	{
		valueText = COM_SID_MEDIUM;	
	}
	else if(value == 3)
	{
		valueText = SID_HIGH_KR_VOL;
	}
	else
	{
		valueText = SID_OFF_KR_DEACT;
		value = 0;		
	}
	
    $('#call_setting_popup_btn').sfButton('option','text',valueText);
}

SceneCallSettingPopup.prototype.processEnterKey = function()
{
    alert("SceneCallSettingPopup.processEnterKey() ");
	
	if(this.current_highlight == CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN)
	{
		StateMgr.Start_Camera_Adjust_State();
	}
	else if(this.current_highlight == CAMERA_SETTING.CONTROL_ZOOM_BTN)
	{
		StateMgr.Start_Call_Camera_Control_State();
	}
}

SceneCallSettingPopup.prototype.processUpKey = function()
{  
	switch(this.current_highlight)
	{
		case CAMERA_SETTING.CONTROL_ZOOM_BTN:

			if(this.flag_shown_cam_adjustment_btn == true && this.flag_dim_light_adjust == false)
			{
				this.highlight(CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN);
			}
            break;            
	}
    
}

SceneCallSettingPopup.prototype.processDownKey = function()
{  
    switch(this.current_highlight)
	{
		case CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN:
            
			if(this.flag_shown_zoom_btn == true && this.flag_disable_cam_zoom == false)
			{
				this.highlight(CAMERA_SETTING.CONTROL_ZOOM_BTN);
			}		
            break;
	}
}

SceneCallSettingPopup.prototype.processReturnKey = function()
{  
	StateMgr.Stop_Call_Setting_State(true);
}

SceneCallSettingPopup.prototype.blur=function(obj_id)
{
	switch(this.current_highlight)
	{
		case CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN:
			$('#call_setting_popup_btn').sfButton('blur');
			break;
			
        case CAMERA_SETTING.CONTROL_ZOOM_BTN:
             $('#call_setting_popup_camera_zoom_btn').sfButton('blur');
			break;
	}
}

SceneCallSettingPopup.prototype.highlight=function(obj_id)
{
	alert('SceneCallSettingPopup.highlight(' + obj_id + ')');
	
	this.blur(this.current_highlight);
	
	switch(obj_id)
	{
		case CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN:
			$('#call_setting_popup_btn').sfButton('focus');
			this.tip_text.SetText(TV_SID_IMPROVE_VIDEO_QUALITY_ADJUSTING_THE_LIGHTING_MSG);	
			break;

        case CAMERA_SETTING.CONTROL_ZOOM_BTN:
             $('#call_setting_popup_camera_zoom_btn').sfButton('focus');
			 this.tip_text.SetText(TV_SID_MAKE_EASIER_TO_SEE_YOUR_FACE_MSG);	
			break;
		default:
			this.tip_text.SetText(' ');	
			break;				
	}
	
	this.current_highlight = obj_id;
}

SceneCallSettingPopup.prototype.disableCameraZoomBtn = function(disable)
{
	if(this.flag_shown_zoom_btn == true)
	{
		if(disable == true)
		{
			$('#call_setting_popup_camera_zoom_btn .sf-ui-common-ellipsis').css('color','#696969');
			$('#call_setting_popup_camera_zoom_btn .sf-ui-button-l').css('background-image','url(images/720p/common_ui/button/btn_basic_disabled_left.png)');
			$('#call_setting_popup_camera_zoom_btn .sf-ui-button-c').css('background-image','url(images/720p/common_ui/button/btn_disabled_center.png)');
			$('#call_setting_popup_camera_zoom_btn .sf-ui-button-r').css('background-image','url(images/720p/common_ui/button/btn_basic_disabled_right.png)');
			this.flag_disable_cam_zoom = true;
		}
		else
		{
			$('#call_setting_popup_camera_zoom_btn .sf-ui-common-ellipsis').css('color','#FFFFFF');
			$('#call_setting_popup_camera_zoom_btn .sf-ui-button-l').css('background-image','');
			$('#call_setting_popup_camera_zoom_btn .sf-ui-button-c').css('background-image','');
			$('#call_setting_popup_camera_zoom_btn .sf-ui-button-r').css('background-image','');
			this.flag_disable_cam_zoom = false;
		}
	}
}

SceneCallSettingPopup.prototype.processBtnClick = function()
{
	if(this.flag_dim_light_adjust == false)
	{
		StateMgr.Start_Camera_Adjust_State();
	}
}

SceneCallSettingPopup.prototype.processBtnOver = function()
{	
	if(this.current_highlight != CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN && this.flag_dim_light_adjust == false)
	{
		this.highlight(CAMERA_SETTING.LIGHT_ADJUSTMENT_BTN);
	}
}

SceneCallSettingPopup.prototype.processZoomBtnClick = function()
{
	if(this.flag_disable_cam_zoom == false)
	{
		StateMgr.Start_Call_Camera_Control_State();
	}
}

SceneCallSettingPopup.prototype.processZoomBtnOver = function()
{
	if(this.current_highlight != CAMERA_SETTING.CONTROL_ZOOM_BTN && this.flag_disable_cam_zoom == false)
	{
		this.highlight(CAMERA_SETTING.CONTROL_ZOOM_BTN);
	}
}

SceneCallSettingPopup.prototype.dimLightAdjustmentBtn = function(flag_dim)
{
	if(this.flag_shown_cam_adjustment_btn == true)
	{
		if(flag_dim == true)
		{
			$('#call_setting_popup_btn .sf-ui-common-ellipsis').css('color','#696969');
			$('#call_setting_popup_btn .sf-ui-button-l').css('background-image','url(images/720p/common_ui/button/btn_basic_disabled_left.png)');
			$('#call_setting_popup_btn .sf-ui-button-c').css('background-image','url(images/720p/common_ui/button/btn_disabled_center.png)');
			$('#call_setting_popup_btn .sf-ui-button-r').css('background-image','url(images/720p/common_ui/button/btn_basic_disabled_right.png)');
			this.flag_dim_light_adjust = true;
		}
		else
		{
			$('#call_setting_popup_btn .sf-ui-common-ellipsis').css('color','#FFFFFF');
			$('#call_setting_popup_btn .sf-ui-button-l').css('background-image','');
			$('#call_setting_popup_btn .sf-ui-button-c').css('background-image','');
			$('#call_setting_popup_btn .sf-ui-button-r').css('background-image','');
			this.flag_dim_light_adjust = false;
		}
	}
}
