
var MINI_CALL_CONFIRM_POPUP ={ 
        CALLING_VIA_VIDEO : 1,
        WANT_TO_END_CALL : 2,
		WANT_TO_CONTINUE_WATCHING_TV : 3,
		GO_TO_SKYPE : 4,
		SIGN_OUT : 5
 };


function SceneminiCallConfirmPopup(options) {
	this.options = options;
    
	this.PopupType = null;
    this.PopupCallbackFn = null;
		
	//object
    this.View = null;    
    this.Msg = null;    
    this.OkBtn = null;
    this.CancelBtn = null;	
    
    //timer
	this.PopupTimer = false;    
   
}

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

   this.create();
}

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

	$("#miniCallConfirmPopup_id").show();
	$("#skype_default_dim").show();
	
	this.update();
    this.startTimer();
}

SceneminiCallConfirmPopup.prototype.handleHide = function () {
	alert("SceneminiCallConfirmPopup.handleHide()");
	
	$("#miniCallConfirmPopup_id").hide();
	$("#skype_default_dim").hide();
	
	this.stopTimer();
}

SceneminiCallConfirmPopup.prototype.handleFocus = function () {
	alert("SceneminiCallConfirmPopup.handleFocus()");
	
	this.highlight(this.CancelBtn);
}

SceneminiCallConfirmPopup.prototype.handleBlur = function () {
	alert("SceneminiCallConfirmPopup.handleBlur()");
	
	this.highlight(null);
}

SceneminiCallConfirmPopup.prototype.handleKeyDown = function (keyCode) {
	alert("SceneminiCallConfirmPopup.handleKeyDown(" + keyCode + ")");

	PluginAPIMgr.PlayAudio(keyCode);
	switch (keyCode) {
		case $.sfKey.LEFT:
			this.resetTimer();
        	this.processLeftKey();
			break;		
		case $.sfKey.RIGHT:
			this.resetTimer();
        	this.processRightKey();
			break;
		case $.sfKey.UP:
		case $.sfKey.DOWN:
			break;

		case $.sfKey.ENTER:
			this.processEnterKey();
			break;
            
        case $.sfKey.RETURN:
        case $.sfKey.EXIT:
            this.processReturnKey();
			$.sfKey.block(event);
			break;
            
        default:
            $.sfKey.block(event);
            break;
	}
	if(Flag_Hidden_State==false)
	event.stopPropagation();
}

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

SceneminiCallConfirmPopup.prototype.create = function(){
    alert("SceneminiCallConfirmPopup.create()");

    this.View = new View("miniCallConfirmPopup");
    this.View.CreatePopupBG(1,"miniCallConfirmPopup_BG");
    
    var this_ = this;
  	var clickCF =  function(obj){this_.processClickEvent(obj);};
    

    this.OkBtn = new Button();
    this.OkBtn.SetImageObjId("miniCallConfirmPopup_ok_btn",8,11);
    this.OkBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BUTTON_NORMAL);
    this.OkBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BUTTON_HIGHLIGHT);	
    this.OkBtn.SetTextObjId("miniCallConfirmPopup_ok_btn_text");
    this.OkBtn.SetText(SID_YES);
    this.OkBtn.SetOnClickCallbackFunc(clickCF);
    this.OkBtn.SetOnMouseOverCallbackFunc(function(obj){
        this_.processMouseOver(obj);
    });

    this.CancelBtn = new Button();
    this.CancelBtn.SetImageObjId("miniCallConfirmPopup_cancel_btn",8,11);
    this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BUTTON_NORMAL);
    this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BUTTON_HIGHLIGHT);	
    this.CancelBtn.SetTextObjId("miniCallConfirmPopup_cancel_btn_text");
    this.CancelBtn.SetText(SID_NO);
    this.CancelBtn.SetOnClickCallbackFunc(clickCF);
    this.CancelBtn.SetOnMouseOverCallbackFunc(function(obj){
        this_.processMouseOver(obj);
    });
	this.Msg = new Label(null,"miniCallConfirmPopup_message");
}

SceneminiCallConfirmPopup.prototype.update = function()
{		
	alert("SceneminiCallConfirmPopup.update -- " + this.PopupType);

	var popup_text;
	
	if(this.PopupType == MINI_CALL_CONFIRM_POPUP.CALLING_VIA_VIDEO)
	{
		alert("VideoAllowPopup  -->  show");

		popup_text = g_Data.CombinateStrings(SID_MIX_IS_CALLING_VIA_VIDEO,PluginAPIMgr.GetCallMemberDisplayName());

		this.OkBtn.SetText(SID_ALLOW);
		this.CancelBtn.SetText(IDWS_MOIP_NOT_ALLOW);
		
		this.OkBtn.setTextKPILog(SID_ALLOW);
		this.CancelBtn.setTextKPILog(IDWS_MOIP_NOT_ALLOW);
		
	}	
	else if(this.PopupType == MINI_CALL_CONFIRM_POPUP.WANT_TO_END_CALL)
	{
		popup_text = TV_SID_DO_YOU_WANT_TO_END_CALL;

		this.OkBtn.SetText(SID_YES);
		this.CancelBtn.SetText(SID_NO);

		this.OkBtn.setTextKPILog(SID_YES);
		this.CancelBtn.setTextKPILog(SID_NO);
		
	}
	else if(this.PopupType == MINI_CALL_CONFIRM_POPUP.GO_TO_SKYPE)
	{
		popup_text = g_Data.CombinateStrings(TV_SID_MIX_DO_YOU_WANT_TO_MOVE_TO_APPLICATION, "Skype");

		this.OkBtn.SetText(SID_YES);
		this.CancelBtn.SetText(SID_NO);

		this.OkBtn.setTextKPILog(SID_YES);
		this.CancelBtn.setTextKPILog(SID_NO);
		
	}
	else if(this.PopupType == MINI_CALL_CONFIRM_POPUP.SIGN_OUT){
		popup_text = TV_SID_DO_YOU_WANT_TO_SIGN_OUT
		
		this.OkBtn.SetText(SID_OK_KR_YES);
		this.CancelBtn.SetText(SID_CANCEL);	

		this.OkBtn.setTextKPILog(SID_OK_KR_YES);
		this.CancelBtn.setTextKPILog(SID_CANCEL);
		
	}
	this.Msg.SetText(popup_text);
	$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog(popup_text);
	
}

SceneminiCallConfirmPopup.prototype.processEnterKey=function()
{    
    var currentHighlight = this.View.getCurrentHighlight();
    
    if(currentHighlight == this.OkBtn)
    {
    	if(this.PopupType == MINI_CALL_CONFIRM_POPUP.CALLING_VIA_VIDEO)
    	{
    		ProcMgr.SetStartReceiveVideo();
    	}
    	else if(this.PopupType == MINI_CALL_CONFIRM_POPUP.WANT_TO_END_CALL)
    	{
    		alert('#######processEnterKey######################CALLING_VIA_VIDEO######################');
			ProcMgr.DisconnectCall();
    	}
    	else if(this.PopupType == MINI_CALL_CONFIRM_POPUP.GO_TO_SKYPE)
    	{
    		var widgetAPI = new Common.API.Widget();
			widgetAPI.runSearchWidget(WIDGET.id);
			//add by minseok : 130611 -> go to skype and back to main scene
			if(StateMgr.GetCurrentState()=="miniCannotCallInDualView"){
				StateMgr.Start_Main_State();
			}
    	}else if(this.PopupType == MINI_CALL_CONFIRM_POPUP.SIGN_OUT){
    		ProcMgr.Signout(false);
    	}
    }
    
    this.processReturnKey();
}

SceneminiCallConfirmPopup.prototype.processReturnKey=function()
{
	WndMgr.StopCallConfirmPopup();
}

SceneminiCallConfirmPopup.prototype.processLeftKey=function()
{    
    var currentHighlight = this.View.getCurrentHighlight();

    if(currentHighlight == this.CancelBtn)
    {
    	this.highlight(this.OkBtn);
    }
}

SceneminiCallConfirmPopup.prototype.processRightKey=function()
{
    var currentHighlight = this.View.getCurrentHighlight();

    if(currentHighlight == this.OkBtn)
    {
    	this.highlight(this.CancelBtn);
    }    
}

SceneminiCallConfirmPopup.prototype.highlight=function(obj)
{
    this.View.setCurrenHighlight(obj);
}

SceneminiCallConfirmPopup.prototype.setType = function(popupType)
{
	this.PopupType = popupType;
}


SceneminiCallConfirmPopup.prototype.startTimer = function()
{
    alert("SceneminiCallConfirmPopup.startTimer() ");

	this.PopupTimer = true;
	var this_ = this;
	PluginAPIMgr.StartOSDTimer("30000" , function() { this_.popupTimerCallback();}, ENUM_TIMER_TYPE.POPUP_WND);
}

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

	
	if(this.PopupTimer == true)
	{
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
		this.PopupTimer = false;
	}
	
}


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

SceneminiCallConfirmPopup.prototype.popupTimerCallback = function()
{
    alert("SceneminiCallConfirmPopup.popupTimerCallback() ");
    
	if(this.PopupTimer == false)
	{
		return;
	}
	
	this.PopupTimer = false;
    this.processReturnKey();
}
///////// Processing Click evnet  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SceneminiCallConfirmPopup.prototype.processMouseOver = function(obj){
    alert("SceneminiCallConfirmPopup.processMouseOver() ");
    
    var currentHighlight =  this.View.getCurrentHighlight();
    if(currentHighlight != obj)
    {
        this.highlight(obj);
    }
    this.resetTimer();
}

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


