function SceneExit(options) {
	this.options = options;
    
	this.MainView=null;
	this.MainViewDim=null;
	this.MainViewBG = null;
	
	this.TitleLabel = null;
	
	this.HelpMsgLabel = null;
	
	this.SigninBtn = null;
	this.SignoutBtn = null;
	this.CancelBtn = null;
	
	this.DefaultHelpBar = null;
	
	this.flag_FromReturnKey = false;
	this.flagWaiting = false;
	
	this.CloseTimer = false;

}

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

SceneExit.prototype.handleShow = function () {
	alert("SceneExit.handleShow()");
	// this function will be called when the scene manager show this scene 
	this.MainViewDim.show();
    
    WndMgr.startPopupHideTimer(30000);
}

SceneExit.prototype.handleHide = function () {
	alert("SceneExit.handleHide()");
	// this function will be called when the scene manager hide this scene  
	this.MainViewDim.hide();
    this.flag_FromReturnKey = false ; //init
    this.enableButton();
    
	WndMgr.stopPopupHideTimer();
}

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

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

SceneExit.prototype.handleKeyDown = function (keyCode) {
	alert("SceneExit.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:
			break;
		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();
            //2013 modify by minseok
            sf.key.preventDefault();
            //sf.key.block(event);
			break;

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

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

SceneExit.prototype.create = function(){
    alert("SceneExit.create()");
    this.MainView = new View("Exit");
    // this.MainView.SetBgImage(g_Image.IMAGE_EXIT_BG);
    this.MainViewBG = new View("ExitBG");
    this.MainViewBG.CreatePopupBG(0,"Exit_popup_BG");
    this.MainViewBG.SetTitleTextofPopupBG(TV_SID_EXIT_SKYPE);
	
	this.MainViewDim = new DimBg("ExitDim", "Exit");
    
    // this.TitleLabel = new Label(null,"exit_title");
    // this.TitleLabel.SetTextStyle("exit_title_style");
    // this.TitleLabel.SetText(TV_SID_EXIT_SKYPE);
    
    this.HelpMsgLabel = new Label(null,"exit_help_msg");
    this.HelpMsgLabel.SetTextStyle("exit_help_msg_style");
    this.HelpMsgLabel.SetText(TV_RECEIVE_CALLS_WHILE_WATCHING_TV_MSG);
    
    var this_ = sf.scene.get("Exit");
    var clickCF =  function(obj){this_.processClickEvent(obj);};
    var overCF =  function(obj){this_.processMouseOverEvent(obj);};
    
    this.SigninBtn = new Button();
    this.SigninBtn.SetImageObjId("exit_signin_btn", 20);
    this.SigninBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
    this.SigninBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);	
    this.SigninBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);	
    this.SigninBtn.SetTextObjId("exit_signin_btn_text");
    this.SigninBtn.SetText(TV_KEEP_ME_SIGNED_IN);
    this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"cPopup_btn_text");
    this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"cPopup_btn_text_high");
    this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"cPopup_btn_text_dim");
    this.SigninBtn.SetOnClickCallbackFunc(clickCF);   
    this.SigninBtn.SetOnMouseOverCallbackFunc(overCF);
    
    this.SignoutBtn = new Button();
    this.SignoutBtn.SetImageObjId("exit_signout_btn", 20);
    this.SignoutBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
    this.SignoutBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.SignoutBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);	
    this.SignoutBtn.SetTextObjId("exit_signout_btn_text");
    this.SignoutBtn.SetText(IDWS_MOIP_POPUP_EXIT_SIGN_OUT);
    this.SignoutBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"cPopup_btn_text");
    this.SignoutBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"cPopup_btn_text_high");
	this.SignoutBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"cPopup_btn_text_dim");
    this.SignoutBtn.SetOnClickCallbackFunc(clickCF);
    this.SignoutBtn.SetOnMouseOverCallbackFunc(overCF);	
    
    this.CancelBtn = new Button();
    this.CancelBtn.SetImageObjId("exit_cancel_btn", 20);
    this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
    this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);	
    this.CancelBtn.SetTextObjId("exit_cancel_btn_text");
    this.CancelBtn.SetText(SID_CANCEL);
    this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"cPopup_btn_text");
    this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"cPopup_btn_text_high");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"cPopup_btn_text_dim");
    this.CancelBtn.SetOnClickCallbackFunc(clickCF);	
    this.CancelBtn.SetOnMouseOverCallbackFunc(overCF);
   
}

SceneExit.prototype.SetFromReturnKey=function(fromReturnKey)
{
   this.flag_FromReturnKey  = fromReturnKey;
}


SceneExit.prototype.highlight=function(obj)
{
    this.MainView.setCurrenHighlight(obj);
    
    if(obj == this.SigninBtn)
    {
    	this.HelpMsgLabel.SetText(TV_RECEIVE_CALLS_WHILE_WATCHING_TV_MSG);
    }
    else if(obj == this.SignoutBtn)
    {
    	this.HelpMsgLabel.SetText(TV_NOT_RECEIVE_CALLS_WHILE_WATCHING_TV_MSG);
    }
    else
    {
    	this.HelpMsgLabel.SetText(TV_RETURN_TO_USING_SKYPE);
    }
}


SceneExit.prototype.processUpKey = function(){
    alert("SceneExit.processUpKey() ");
     if(this.flagWaiting ==true)
    {
        return;
    }
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
    switch(currentHighlight)
    {  
        
		
        case this.SignoutBtn:
            this.highlight(this.SigninBtn);
            break;   
            
        case this.CancelBtn:
            this.highlight(this.SignoutBtn);
            break;
    }
}

SceneExit.prototype.processDownKey = function(){
    alert("SceneExit.processDownKey() ");
     if(this.flagWaiting ==true)
    {
        return;
    }
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.SigninBtn:
       	 	this.highlight(this.SignoutBtn);
        break;
		
        case this.SignoutBtn:
            this.highlight(this.CancelBtn);
            break;   
            
        
    }
}

SceneExit.prototype.processEnterKey = function(){
    alert("SceneExit.processEnterKey() ");
    if(this.flagWaiting ==true)
    {
        return;
    }
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
  
    switch(currentHighlight)
    {
        case this.SigninBtn:
        	this.disableButton();
           if(this.flag_FromReturnKey==true)
           {
                ProcMgr.CloseWithSignIn();
            }
            else
            {
                ProcMgr.ExitWithSignIn();
            }
            break;
            
        case this.SignoutBtn:
            this.disableButton();
            if(this.flag_FromReturnKey==true)
            {
                ProcMgr.CloseWithSignOut();
            }
            else
            {
                ProcMgr.ExitWithSignOut();
            }
            break;
            
        case this.CancelBtn:
            StateMgr.Stop_Exit_State(true);
            break;
            
    }
}

SceneExit.prototype.enableButton = function(){
    alert("SceneExit.enableButton() ");
	
    this.SigninBtn.SetFlagDim(false);
    this.SignoutBtn.SetFlagDim(false);
    this.CancelBtn.SetFlagDim(false);

    this.flagWaiting = false;
}

SceneExit.prototype.disableButton = function(){
    alert("SceneExit.disableButton() ");
	
	WndMgr.stopPopupHideTimer();
	
    this.flagWaiting = true;

    var currentHighlight =  this.MainView.getCurrentHighlight();
    currentHighlight.blur();
    
    this.SigninBtn.SetFlagDim(true);
    this.SignoutBtn.SetFlagDim(true);
    this.CancelBtn.SetFlagDim(true);   
}

SceneExit.prototype.processReturnKey = function(){
    alert("SceneExit.processReturnKey() ");
         if(this.flagWaiting ==true)
    {
        return;
    }
  
    StateMgr.Stop_Exit_State(true);
}



SceneExit.prototype.processClickEvent = function(obj){
	alert("SceneExit.processClickEvent() ");
	
	
	this.processEnterKey();
}
SceneExit.prototype.processMouseOverEvent = function(obj){
	alert("SceneExit.processMouseOverEvent() ");
	
	var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	// this.processEnterKey();
}

