function SceneVoiceCall(options) {
	this.options = options;
    
    this.VoiceCallView =null;
    
    this.CallDurationTextLabel =null;
    this.CallDurationTimeLabel =null;

    this.YourNameLabel=null;
    this.MyNameLabel=null;

    this.YourThumbnailLabel=null;
    this.MyThumbnailLabel=null;

    this.CallEndBtn=null;
    this.VideoCallBtn=null;
    this.MicVolumeBtn=null;
    this.HoldBtn=null;
    
    this.PhoneIconLabel = null;
    
    this.HoldIconLabel = null;
	this.HoldAniLabel = null;
     
    this.HelpBar =null;
}

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

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

SceneVoiceCall.prototype.handleHide = function () {
	alert("SceneVoiceCall.handleHide()");
	// this function will be called when the scene manager hide this scene  
     if(this.VoiceCallView !=null)
    {
        this.highlight(null);
    }
}

SceneVoiceCall.prototype.handleFocus = function () {
	alert("SceneVoiceCall.handleFocus()");
	// this function will be called when the scene manager focus this scene
     
    var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    if(currentHighlight ==null)
    {
        this.highlight(this.CallEndBtn);
    }
    else
    {
        this.highlight(currentHighlight);
    }
}

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

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

			break;
		case sf.key.DOWN:

			break;

		case sf.key.ENTER:
            this.processEnterKey();
			break;
        
        case sf.key.VOL_DOWN:
        case sf.key.PANEL_VOL_DOWN:
		case sf.key.VOL_UP:
        case sf.key.PANEL_VOL_UP:
             this.processVolumeKey();
			break;
            
        case sf.key.N1:
        case sf.key.N2:
        case sf.key.N3:
        case sf.key.N4:
        case sf.key.N5:
        case sf.key.N6:
        case sf.key.N7:
        case sf.key.N8:
        case sf.key.N9:
        case 35:
		case 650: 
        case sf.key.N0:
        case 259:
            ProcMgr.SendDTMF(keyCode);
            break;  
            
       case sf.key.RED:
            //this.processRedKey();
			break;

		case sf.key.BLUE:
			this.processBlueKey();
			break;	
			
		case sf.key.YELLOW:
		case sf.key.GREEN:
            break;	

		case sf.key.TOOLS:
			this.processToolKey();
			break;
                        
        case sf.key.RETURN:
           this.processReturnKey();
            sf.key.block(event);
            break;
            
        case sf.key.EXIT:
            this.processExitKey();
            sf.key.block(event);
			break;
            
       case 147:  //infolink
       case 261:  //contents
       case 115:  //wiselink
            ProcMgr.processInfolinkKey();
			break;

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

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

SceneVoiceCall.prototype.create = function(){
    alert("SceneVoiceCall.create() ");
    this.VoiceCallView = new View("VoiceCall");
    this.VoiceCallView.SetBgImage(g_Image.IMAGE_VOICE_CALL_BG);
    
    this.CallDurationTextLabel = new Label(null,"voice_call_duration_text");
    this.CallDurationTextLabel.SetTextStyle("voice_call_duration_text_style");
    this.CallDurationTextLabel.SetText(IDWS_MOIP_SKYPE_CALL_DURATION);

    this.CallDurationTimeLabel = new Label(null,"voice_call_duration_time");
    this.CallDurationTimeLabel.SetTextStyle("voice_call_duration_time_style");
    this.CallDurationTimeLabel.SetText("00:00:00");

    this.YourNameLabel = new Label(null,"voice_call_your_name");
    this.YourNameLabel.SetTextStyle("voice_call_member_name_style");
    this.YourNameLabel.SetReverseDisable(true);

    this.MyNameLabel = new Label(null,"voice_call_my_name");
    this.MyNameLabel.SetTextStyle("voice_call_member_name_style");
    this.MyNameLabel.SetReverseDisable(true);

    this.YourThumbnailLabel= new Label("voice_call_your_thumbnail", null);
    this.YourThumbnailLabel.SetBgImage(g_Image.IMAGE_VOICE_CALL_THUMBNAIL);
    this.YourThumbnailLabel.AppendFgImage("voice_call_your_thumbnail_avata","3px","3px","143px","140px");
    this.YourThumbnailLabel.SetFgImage(g_Image.IMAGE_LIST_MAIN_VIEW_DEFAULT_AVATA);

    this.MyThumbnailLabel= new Label("voice_call_my_thumbnail", null);
    this.MyThumbnailLabel.SetBgImage(g_Image.IMAGE_VOICE_CALL_THUMBNAIL);
    this.MyThumbnailLabel.AppendFgImage("voice_call_my_thumbnail_avata","3px","3px","143px","140px");
    this.MyThumbnailLabel.SetFgImage(g_Image.IMAGE_LIST_MAIN_VIEW_DEFAULT_AVATA);

	var this_ = sf.scene.get("VoiceCall");
	var clickCF =  function(obj){this_.processClickEvent(obj);};
	
    this.CallEndBtn = new Button();
    this.CallEndBtn.SetImageObjId("voice_call_end_btn");
    this.CallEndBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_VOICE_CALL_END_BTN_NORMAL);
    this.CallEndBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_VOICE_CALL_END_BTN_NORMALFOCUS);	
    this.CallEndBtn.SetTextObjId("voice_call_end_btn_text");
    this.CallEndBtn.SetText(TV_SID_END_CALL);
    this.CallEndBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
    this.CallEndBtn.SetOnClickCallbackFunc(clickCF);

    this.VideoCallBtn = new Button();
    this.VideoCallBtn.SetImageObjId("voice_call_to_video_call_btn");
    this.VideoCallBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_VOICE_CALL_TO_VIDEO_CALL_BTN_NORMAL);
    this.VideoCallBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_VOICE_CALL_TO_VIDEO_CALL_BTN_NORMALFOCUS);	
	this.VideoCallBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_VOICE_CALL_TO_VIDEO_CALL_BTN_DIM);	
    this.VideoCallBtn.SetTextObjId("voice_call_to_video_call_btn_text");
    this.VideoCallBtn.SetText(TV_SID_START_VIDEO);
    this.VideoCallBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
	this.VideoCallBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"common_btn_text_f17_dim_style");
    this.VideoCallBtn.SetOnClickCallbackFunc(clickCF);

    this.MicVolumeBtn = new Button();
    this.MicVolumeBtn.SetImageObjId("voice_call_mic_volume_btn");
    this.MicVolumeBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_VOICE_CALL_BTN_NORMAL);
    this.MicVolumeBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_VOICE_CALL_BTN_NORMALFOCUS);	
    this.MicVolumeBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_VOICE_CALL_BTN_DIM);	
    this.MicVolumeBtn.SetTextObjId("voice_call_mic_volume_btn_text");
    this.MicVolumeBtn.SetText(TV_SID_MIC_VOL);
    this.MicVolumeBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
    this.MicVolumeBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"common_btn_text_f17_dim_style");
    this.MicVolumeBtn.SetOnClickCallbackFunc(clickCF);

    this.HoldBtn = new Button();
    this.HoldBtn.SetImageObjId("voice_call_hold_btn");
    this.HoldBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_VOICE_CALL_BTN_NORMAL);
    this.HoldBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_VOICE_CALL_BTN_NORMALFOCUS);	
    this.HoldBtn.SetTextObjId("voice_call_hold_btn_text");
    this.HoldBtn.SetText(IDWS_MOIP_SKYPE_HOLD);
    this.HoldBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
    this.HoldBtn.SetOnClickCallbackFunc(clickCF);
    
    this.PhoneIconLabel= new Label("voice_call_icon", null);
    this.PhoneIconLabel.SetBgImage(g_Image.IMAGE_VOICE_CALL_ICON);
    
    this.HoldIconLabel= new Label("voice_call_hold_icon", null);
    this.HoldIconLabel.SetBgImage(g_Image.IMAGE_VIDEO_CALL_HOLD_ICON);
	
	this.HoldAniLabel= new Label("voice_call_hold_animation", null);
	this.HoldAniLabel.AppendFgImage("voice_call_hold_animation_icon","0px","0px","108px","108px");
    this.HoldAniLabel.SetFgImage(WndMgr.Bg_LoadingGIF.src);
    
    this.HelpBar = new HelpBar(HelpBarIndex.VOICE_CALL, "VoiceCall");
    this.HelpBar.SetOnClickCallbackFunc(1, function(){this_.processBlueKey();});
    this.HelpBar.SetOnClickCallbackFunc(2, function(){this_.processToolKey();});
    this.HelpBar.SetOnClickCallbackFunc(3, function(){this_.processReturnKey();});

	this.CallEndBtn.registHelpBar( this.HelpBar); 
	this.VideoCallBtn.registHelpBar( this.HelpBar); 
	this.MicVolumeBtn.registHelpBar( this.HelpBar); 
	this.HoldBtn.registHelpBar( this.HelpBar);    

}

SceneVoiceCall.prototype.update = function()
{
    this.YourNameLabel.SetText( PluginAPIMgr.GetCallMemberDisplayName());
    this.YourThumbnailLabel.SetFgImage(PluginAPIMgr.GetCallMemberAvataImage());
    
    this.MyNameLabel.SetText(PluginAPIMgr.GetMyDisplayName() );
    this.MyThumbnailLabel.SetFgImage(PluginAPIMgr.GetMyAvataImageForCall());
    
    this.toggleVideoCallBtnEnable();
    
      if(g_Data.GetCallLocalHold() == true)
     {
        this.LocalHold();
     }
     else if(g_Data.GetCallRemoteHold() == true)
     {
        this.RemoteHold();
     }
     else
     {
	 	if(ProcMgr.callHoldTimer == true)
		{
			this.StartLocalHoldWait();
		}
		else
		{
			this.StopLocalHoldWait();
		}
		
        this.Resume();
     }
}

SceneVoiceCall.prototype.toggleVideoCallBtnEnable=function()
{      
    var callee_name = PluginAPIMgr.GetCallMemberID();
    var camera_state = PluginAPIMgr.GetCameraState();
    
    if(camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING)
    {
        alert("SceneVoiceCall.toggleVideoCallBtnEnable() Dim : true ->  callee_name : " + callee_name +" camera_state : "+ camera_state );
         var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
        if(currentHighlight ==  this.VideoCallBtn)
        {
            if(this.VideoCallBtn.flag_highlight ==  true)
            {
                this.highlight(this.CallEndBtn);
            }
            else
            {
                this.highlight(null);
            }
        }
        
        this.VideoCallBtn.SetFlagDim(true);
        
         if(currentHighlight ==  this.MicVolumeBtn)
        {
            if(this.MicVolumeBtn.flag_highlight ==  true)
            {
                this.highlight(this.CallEndBtn);
           }
           else
           {
                this.highlight(null);
           }
        }
        
        this.MicVolumeBtn.SetFlagDim(true);
    }
    else
    {
        alert("SceneVoiceCall.toggleVideoCallBtnEnable() Dim :  false ");
		if(PluginAPIMgr.IsInCall()==1)
		{
			PluginAPIMgr.StartRecord();
		}
		
		if(callee_name =="echo123" )
		{
			this.VideoCallBtn.SetFlagDim(true);
		}
		else
		{
			if (g_Data.GetCallLocalHold() != true && g_Data.GetCallRemoteHold() != true) 
			{					
				this.VideoCallBtn.SetFlagDim(false);
			}	
		} 
        
        this.MicVolumeBtn.SetFlagDim(false);
    }    
}

SceneVoiceCall.prototype.updateCallDuration = function(time)
{
     this.CallDurationTimeLabel.SetText(time);
}

SceneVoiceCall.prototype.updateCallMemberInfo = function()
{
	this.YourNameLabel.SetText( PluginAPIMgr.GetCallMemberDisplayName());
    this.YourThumbnailLabel.SetFgImage(PluginAPIMgr.GetCallMemberAvataImage());	
}

SceneVoiceCall.prototype.highlight=function(obj)
{
    this.VoiceCallView.setCurrenHighlight(obj);
}

SceneVoiceCall.prototype.processLeftKey=function()
{
    alert("SceneVoiceCall.processLeftKey() ");
    var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.CallEndBtn:
            this.highlight(this.HoldBtn);
            break;
         case this.VideoCallBtn:
            this.highlight(this.CallEndBtn);
            break;
        case this.MicVolumeBtn:
         if( this.VideoCallBtn.GetFlagDim() ==true)
         {
            this.highlight(this.CallEndBtn);
         }
         else
         {
            this.highlight(this.VideoCallBtn);
         }
            break; 
         case this.HoldBtn:
          if( this.MicVolumeBtn.GetFlagDim() ==true)
         {
            this.highlight(this.CallEndBtn);
         }
         else
         {
            this.highlight(this.MicVolumeBtn);
         }
         break;           
            
    }
}

SceneVoiceCall.prototype.processRightKey=function()
{
    alert("SceneVoiceCall.processRightKey() ");
    var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.CallEndBtn:
         if( this.VideoCallBtn.GetFlagDim() ==true  )
         {
		 	if(this.MicVolumeBtn.GetFlagDim() ==true)
			{
				this.highlight(this.HoldBtn);
			}
			else
			{
				this.highlight(this.MicVolumeBtn);
			}
            
         }
         else
         {
            this.highlight(this.VideoCallBtn);
         }
            break;
         case this.VideoCallBtn:
            this.highlight(this.MicVolumeBtn);
            break;
        case this.MicVolumeBtn:
            this.highlight(this.HoldBtn);
            break; 
         case this.HoldBtn:
            this.highlight(this.CallEndBtn);
            break;           
            
    }
}

SceneVoiceCall.prototype.processEnterKey=function()
{
    alert("SceneVoiceCall.processEnterKey() ");
    var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.CallEndBtn:
			ProcMgr.DisconnectCall();
            break;
         case this.VideoCallBtn:
			ProcMgr.StartSendVideo();
            break;
        case this.MicVolumeBtn:
            StateMgr.Start_Volume_Mic_State();
            break; 
         case this.HoldBtn:
			ProcMgr.ToggleLocalHold();
            break;                       
    }
}

SceneVoiceCall.prototype.processReturnKey=function()
{
    alert("SceneVoiceCall.processReturnKey() ");
	if(ProcMgr.isGenoaS==false)
	{
		StateMgr.Start_Main_State();
	}
	else
	{
		StateMgr.Start_Call_Switch_State(); 
	}
    
}

SceneVoiceCall.prototype.processExitKey = function(){
    alert("SceneVoiceCall.processExitKey() ");
;
   StateMgr.Start_Exit_State(false);
}

SceneVoiceCall.prototype.processVolumeKey=function()
{
    alert("SceneVoiceCall.processVolumeKey() ");
    StateMgr.Start_Volume_Speaker_State();
}

SceneVoiceCall.prototype.processBlueKey = function(){
    alert("SceneVoiceCall.processBlueKey() ");
    
	if(ProcMgr.isGenoaS==false)
	{
		StateMgr.Start_Live_Contact_List_State();
	}	
}

SceneVoiceCall.prototype.processToolKey=function()
{
    alert("SceneVoiceCall.processToolKey() ");
	
	StateMgr.Start_List_Tools_State(TOOL_MENU_LIST_TYPE.VOICE_CALL);    
}


SceneVoiceCall.prototype.StartLocalHoldWait=function()
{
	alert("SceneVoiceCall.StartLocalHoldWait() "); 
	this.HoldAniLabel.visibleObj(); 
	
	var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    if(currentHighlight ==  this.VideoCallBtn)
    {
        if(this.VideoCallBtn.flag_highlight ==  true)
        {
            this.highlight(this.CallEndBtn);
        }
        else
        {
            this.highlight(null);
        }
    }
    
    this.VideoCallBtn.SetFlagDim(true); 
}

SceneVoiceCall.prototype.StopLocalHoldWait=function()
{
	alert("SceneVoiceCall.StopLocalHoldWait() "); 
	this.HoldAniLabel.hiddenObj();
}

SceneVoiceCall.prototype.LocalHold=function()
{
    alert("SceneVoiceCall.LocalHold() ");
	this.StopLocalHoldWait();   
    this.HoldIconLabel.visibleObj();
    this.HoldBtn.SetText(SID_RESUME);
    this.CallDurationTextLabel.SetText(IDWS_MOIP_CALL_ON_HOLD);   
	
    var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    if(currentHighlight ==  this.VideoCallBtn)
    {
        if(this.VideoCallBtn.flag_highlight ==  true)
        {
            this.highlight(this.CallEndBtn);
        }
        else
        {
            this.highlight(null);
        }
    }
    
    this.VideoCallBtn.SetFlagDim(true); 
}

SceneVoiceCall.prototype.RemoteHold=function()
{
    alert("SceneVoiceCall.RemoteHold() "); 
	this.StopLocalHoldWait(); 
    this.HoldIconLabel.visibleObj();
    this.HoldBtn.SetText(IDWS_MOIP_SKYPE_HOLD);
    this.CallDurationTextLabel.SetText(TV_SID_YOU_ARE_ON_HOLD); 
	
    var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    if(currentHighlight ==  this.VideoCallBtn)
    {
        if(this.VideoCallBtn.flag_highlight ==  true)
        {
            this.highlight(this.CallEndBtn);
        }
        else
        {
            this.highlight(null);
        }
    }
    
    this.VideoCallBtn.SetFlagDim(true);
}

SceneVoiceCall.prototype.Resume=function()
{
    alert("SceneVoiceCall.Resume() ");  
    this.HoldIconLabel.hiddenObj();
    this.HoldBtn.SetText(IDWS_MOIP_SKYPE_HOLD);
    this.CallDurationTextLabel.SetText(IDWS_MOIP_SKYPE_CALL_DURATION); 
	
	var camera_state = PluginAPIMgr.GetCameraState();
	var callee_name = PluginAPIMgr.GetCallMemberID();
	
	if (callee_name !="echo123" && camera_state != ENUM_CAM_STATE.CAM_STATE_DISCONNECTED && camera_state != ENUM_CAM_STATE.CAM_STATE_CONNECTING)
	{
		this.VideoCallBtn.SetFlagDim(false);
	}
}

SceneVoiceCall.prototype.processClickEvent = function(obj){
	alert("SceneVoiceCall.processClickEvent() ");
	
	var currentHighlight =  this.VoiceCallView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	if(event.button==2)
	{
		alert("SceneVoiceCall.processClickEvent() -> right button ");
		this.processToolKey();
	}
	else
	{
		alert("SceneVoiceCall.processClickEvent() -> left button ");
		this.processEnterKey();
	}
}




