

function SceneCallSwitch(options) {
	this.options = options;
    
    this.CallSwitchView=null;
	this.CallSwitchDim=null;
    
    this.PopupMsg = null;
	this.PopupCenterMsg = null;
	
    this.YesBtn = null;
    this.NoBtn = null;
   
    this.CallSwitchTimer = false;

}

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

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

    this.startTimer();
    
}

SceneCallSwitch.prototype.handleHide = function () {
	alert("SceneCallSwitch.handleHide()");
	// this function will be called when the scene manager hide this scene  
	this.CallSwitchDim.hide();
    if(this.CallSwitchTimer == true)
    {
        this.stopTimer();
    }
}

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

}

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

SceneCallSwitch.prototype.handleKeyDown = function (keyCode) {
	alert("SceneCallSwitch.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:
		this.resetTimer();
        this.processLeftRightKey();
			break;
		case sf.key.UP:

			break;
		case sf.key.DOWN:

			break;

		case sf.key.ENTER:
             this.processEnterKey();
			break;
            
        case sf.key.RETURN:
        case sf.key.EXIT:
            this.processReturnKey();
            sf.key.block(event);
			break;

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

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

SceneCallSwitch.prototype.create = function(){
    alert("SceneCallSwitch.create()");
    this.CallSwitchView = new View("CallSwitch");
    this.CallSwitchView.SetBgImage(WndMgr.Bg_Popup.src); 
	
	this.CallSwitchDim = new DimBg("CallSwitchDim", "CallSwitch");    
    
    this.PopupMsg = new Label(null,"call_switch_message");
    this.PopupMsg.SetTextStyle("call_switch_message_style");
	this.PopupMsg.SetText(TV_SID_START_NEW_CALL_CURRENT_CALL_WILL_END_MSG);

	this.PopupCenterMsg = new Label(null,"call_switch_center_message");
    this.PopupCenterMsg.SetTextStyle("call_switch_center_message_style");
	this.PopupCenterMsg.SetText(TV_SID_DO_YOU_WANT_TO_END_CALL);
	
	if(ProcMgr.isGenoaS == false)
	{
		this.PopupMsg.visibleObj();
		this.PopupCenterMsg.hiddenObj();
	}
	else
	{
		this.PopupMsg.hiddenObj();
		this.PopupCenterMsg.visibleObj();
	}   
	
    var this_ = sf.scene.get("CallSwitch");
    var clickCF =  function(obj){this_.processClickEvent(obj);}; 

    this.YesBtn = new Button();
    this.YesBtn.SetImageObjId("call_switch_yes_btn");
    this.YesBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_LOADING_BTN_NORMAL);
    this.YesBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_LOADING_BTN_NORMALFOCUS);	
    this.YesBtn.SetTextObjId("call_switch_yes_btn_text");
    this.YesBtn.SetText(SID_YES);
	this.YesBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f19_normal_style");
	this.YesBtn.SetOnClickCallbackFunc(clickCF);
	    
    this.NoBtn = new Button();
    this.NoBtn.SetImageObjId("call_switch_no_btn");
    this.NoBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_LOADING_BTN_NORMAL);
    this.NoBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_LOADING_BTN_NORMALFOCUS);	
    this.NoBtn.SetTextObjId("call_switch_no_btn_text");
    this.NoBtn.SetText(SID_NO);
	this.NoBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f19_normal_style");
	this.NoBtn.SetOnClickCallbackFunc(clickCF);
	
}

SceneCallSwitch.prototype.highlight=function(obj)
{
    this.CallSwitchView.setCurrenHighlight(obj);

}

SceneCallSwitch.prototype.startTimer = function()
{
    alert("SceneCallSwitch.startTimer() ");
	
	this.CallSwitchTimer = true;
	PluginAPIMgr.StartOSDTimer("30000" , function() { sf.scene.get('CallSwitch').popupTimerCallback();}, ENUM_TIMER_TYPE.POPUP_WND);
}

SceneCallSwitch.prototype.resetTimer = function()
{
    alert("SceneCallSwitch.resetTimer() ");
	
	if(this.CallSwitchTimer == true)
	{
		PluginAPIMgr.RestartOSDTimer("30000" ,ENUM_TIMER_TYPE.POPUP_WND);
	}
}

SceneCallSwitch.prototype.stopTimer = function()
{
    alert("SceneCallSwitch.stopTimer() ");

	this.CallSwitchTimer = false;
	PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND); 
}

SceneCallSwitch.prototype.popupTimerCallback = function()
{
    alert("SceneCallSwitch.popupTimerCallback() ");
	
	if (this.CallSwitchTimer == false)
	{
		return;
	}
	this.CallSwitchTimer = false;	
		
   	if(ProcMgr.isGenoaS == false) 
   {
   	ProcMgr.CancelCallSwitch();
   }
   else
   {
   	StateMgr.Stop_Call_Switch_State(true);
   }
}


SceneCallSwitch.prototype.processLeftRightKey = function(){
    alert("SceneCallSwitch.processLeftRightKey() ");
    
    var currentHighlight =  this.CallSwitchView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.YesBtn:
           this.highlight(this.NoBtn);
            break;
            
        case this.NoBtn:
           this.highlight(this.YesBtn);
            break;
    }
}

SceneCallSwitch.prototype.processEnterKey = function(){
    alert("SceneCallSwitch.processEnterKey() ");
    
    var currentHighlight =  this.CallSwitchView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.YesBtn:
		   if(ProcMgr.isGenoaS == false)
		   {
		   	ProcMgr.StartCallSwitch();
		   }
		   else
		   {
		   	ProcMgr.DisconnectCall();
		   }
		    
            break;
            
        case this.NoBtn:
  		   if(ProcMgr.isGenoaS == false) 
		   {
		   	ProcMgr.CancelCallSwitch();
		   }
		   else
		   {
		   	StateMgr.Stop_Call_Switch_State(true);
		   }
            break;
    }
}

SceneCallSwitch.prototype.processReturnKey = function(){
    alert("SceneCallSwitch.processReturnKey() ");
	
	if(ProcMgr.isGenoaS == false) 
   {
   	ProcMgr.CancelCallSwitch();
   }
   else
   {
   	StateMgr.Stop_Call_Switch_State(true);
   }

}

SceneCallSwitch.prototype.processClickEvent = function(obj){
	alert("SceneCallSwitch.processClickEvent() ");
	
	var currentHighlight =  this.CallSwitchView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	this.processEnterKey();
}


