
function SceneWelcome(options) {
	this.options = options;
	
    this.destroyFlag = true;
    
    this.MainView=null;
    
    this.TitleLabel = null;
	this.ImageLabel = null;
	this.MsgLabel = null; 
    
    this.SigninBtn = null;
    this.CreateAccountBtn = null;
    this.MSABtn = null;
    this.NeedHelpBtn = null;
    
    
    //flag
    this.IsShowTooltipFlag = false;
	
}

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

SceneWelcome.prototype.handleShow = function () {
	alert("SceneWelcome.handleShow()");
	// this function will be called when the scene manager show this scene 
	
	if(this.destroyFlag==true)
	{
		this.highlight(null);
        this.destroyFlag= false;	
	}    
	this.hideTooltip();
}

SceneWelcome.prototype.handleHide = function () {
	alert("SceneWelcome.handleHide()");
	// this function will be called when the scene manager hide this scene  
}

SceneWelcome.prototype.handleFocus = function () {
	alert("SceneWelcome.handleFocus()");
	// this function will be called when the scene manager focus this scene
    var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight ==null)
    {
        this.highlight(this.SigninBtn);
    }
    else
    {
         this.highlight(currentHighlight);
    }
    
    var this_ = sf.scene.get("Welcome");
  	var returnCF =  function(){this_.processReturnKey();};
    WndMgr.SetReturnIconClickCallback(returnCF);
}

SceneWelcome.prototype.handleBlur = function () {
	alert("SceneWelcome.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
    currentHighlight.blur();
    
    WndMgr.SetReturnIconClickCallback(null);
}
 
SceneWelcome.prototype.handleKeyDown = function (keyCode) {
	alert("SceneWelcome.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:
			this.processLeftKey();
			break;
		case sf.key.RIGHT:
			this.processRightKey();
			break;
		case sf.key.UP:
		case sf.key.DOWN:
           this.processUpDownKey(keyCode);
			break;

		case sf.key.ENTER:
            this.processEnterKey();
			break;
        
		case sf.key.TOOLS:
            
			break; 
            
        case sf.key.RETURN:
            this.processReturnKey();
            //2013 modify by minseok
            sf.key.preventDefault();
            //sf.key.block(event);
			break;
            
        case sf.key.EXIT:
            this.processExitKey();
            //2013 modify by minseok
            sf.key.preventDefault();
            //sf.key.block(event);
			break;
		case sf.key.RED:
			//this.startDebugMode();
			break;
        case 147:  //infolink
        case 261:  //contents
        case 115:  //wiselink
            ProcMgr.processInfolinkKey(); 
			break;
			
		default:
            ProcMgr.processBlockKey(keyCode);
            break;

	}
}

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

SceneWelcome.prototype.create = function(){
    alert("SceneWelcome.create()");
    this.MainView = new View("Welcome");
    // this.MainView.SetBgImage(g_Image.IMAGE_WELCOME_BG);
    
   /* this.TitleLabel = new Label(null,"welcome_title");
    this.TitleLabel.SetTextStyle("welcome_title_style");
    this.TitleLabel.SetText(IDWS_MOIP_WELCOM_TO_SKYPE);    
	*/
	
	this.ImageLabel= new Label("welcome_image", null);
    this.ImageLabel.SetBgImage(g_Image.IMAGE_WELCOME_IMAGE);
    /*
    this.MsgLabel = new Label(null,"welcome_msg");
    this.MsgLabel.SetTextStyle("welcome_msg_style");
    this.MsgLabel.SetText(TV_ENJOY_FREE_VIDEO_CALLS_MSG);  
  */
  	var this_ = sf.scene.get("Welcome");
  	var clickCF =  function(obj){this_.processClickEvent(obj);};
  	var overCF =  function(obj){this_.processMouseOverEvent(obj);};
  	
	//Signin Button
    this.SigninBtn= new Button();
    this.SigninBtn.SetImageObjId("welcome_signin_btn");
    this.SigninBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_WELCOME_SIGNIN_BTN_NORMAL);
    this.SigninBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_WELCOME_SIGNIN_BTN_NORMALFOCUS);
	this.SigninBtn.AppendFgImage("welcome_signin_picture_icon", "5px", "5px", "166px", "166px");
	this.SigninBtn.SetFgImage(g_Image.IMAGE_WELCOME_SIGNIN_ICON);
	
    this.SigninBtn.SetTextObjId("welcome_signin_btn_text");
    this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"welcome_btn_normal_style");
	this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"welcome_btn_select_style");
    this.SigninBtn.SetText(IDWS_MOIP_SKYPE_SIGNIN);
    this.SigninBtn.SetOnClickCallbackFunc(clickCF);
    this.SigninBtn.SetOnMouseOverCallbackFunc(overCF);


	
	//CreateAccount Button
    this.CreateAccountBtn= new Button();
    this.CreateAccountBtn.SetImageObjId("welcome_create_account_btn",30);
    this.CreateAccountBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_WELCOME_BTN_NORMAL);
    this.CreateAccountBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_WELCOME_BTN_NORMALFOCUS);
    this.CreateAccountBtn.SetTextObjId("welcome_create_account_btn_text");
    this.CreateAccountBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"welcome_btn_normal_style");
	this.CreateAccountBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"welcome_btn_select_style");
    this.CreateAccountBtn.SetText(SID_CREATE_ACCOUNT);
    this.CreateAccountBtn.SetOnClickCallbackFunc(clickCF);
    this.CreateAccountBtn.SetOnMouseOverCallbackFunc(overCF);


	//Microsoft Account Button
	this.MSABtn = new Button();
	this.MSABtn.SetImageObjId("welcome_msa_btn",30);
    this.MSABtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_WELCOME_BTN_NORMAL);
    this.MSABtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_WELCOME_BTN_NORMALFOCUS);
    this.MSABtn.SetTextObjId("welcome_msa_btn_text");
    this.MSABtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"welcome_btn_normal_style");
	this.MSABtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"welcome_btn_select_style");
    this.MSABtn.SetText(TV_SID_USE_MY_MICROSOFT_ACCOUNT);
    this.MSABtn.SetOnClickCallbackFunc(clickCF);
    this.MSABtn.SetOnMouseOverCallbackFunc(overCF);
    this.MSABtn.ResizeButton("L");
    
    
    //need help Button
    this.NeedHelpBtn = new Button();
    this.NeedHelpBtn.SetImageObjId("welcome_need_help_btn");
    this.NeedHelpBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_WELCOME_NEED_HELP_NORMAL);
    this.NeedHelpBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_WELCOME_NEED_HELP_NORMALFOCUS);
    this.NeedHelpBtn.SetOnClickCallbackFunc(clickCF);
    this.NeedHelpBtn.SetOnMouseOverCallbackFunc(overCF);
	
	$('#welcome_need_help_tootip').sfTooltip({
		text : TV_SID_NEED_HELP,
		orientation : 'down'
	});

}


SceneWelcome.prototype.setDestroyFlag= function(destroy_flag){
     this.destroyFlag = destroy_flag;
}

SceneWelcome.prototype.highlight=function(obj)
{
	alert("SceneWelcome.highlight()");
	if(obj==this.NeedHelpBtn){
		this.showTooltip();
	}else if(this.IsShowTooltipFlag==true){
		this.hideTooltip();
	}
	
    this.MainView.setCurrenHighlight(obj);
	
}

SceneWelcome.prototype.processLeftKey = function(){
	alert("SceneWelcome.processLeftKey() ");
	var currentHighlight =  this.MainView.getCurrentHighlight();
	switch(currentHighlight){
		case this.CreateAccountBtn:
			this.highlight(this.MSABtn);
			break;
		case this.NeedHelpBtn:
			this.highlight(this.CreateAccountBtn);
			break;
	}
	
}
SceneWelcome.prototype.processRightKey = function(){
	alert("SceneWelcome.processRightKey() ");
	var currentHighlight =  this.MainView.getCurrentHighlight();
	switch(currentHighlight){
		case this.MSABtn:
			this.highlight(this.CreateAccountBtn);
			break;
		case this.CreateAccountBtn:
			this.highlight(this.NeedHelpBtn);
			break;
	}
	
}
//prevent Curculation
SceneWelcome.prototype.processUpDownKey = function(keyCode){
    alert("SceneWelcome.processUpDownKey() ");
    //var currentHighlight =  this.MainView.getCurrentHighlight();
    
    switch(keyCode)
    {       
		case sf.key.UP:
			this.highlight(this.SigninBtn);
			break;
		case sf.key.DOWN:
			this.highlight(this.MSABtn);
            break;
    }
}

SceneWelcome.prototype.processEnterKey = function(){
    alert("SceneWelcome.processEnterKey() ");
    
    var currentHighlight =  this.MainView.getCurrentHighlight();

    switch(currentHighlight)
    {
        case this.SigninBtn:
	        if(PluginAPIMgr.RecognitionPluginAvailable==true)
	        {
	        	if(PluginAPIMgr.GetLoginMode()==0)
	        	{
	        		StateMgr.Start_Signin_State();
	        	}
	        	else
	        	{
	        		ProcMgr.StartFaceRecogSignin();
	        	}
	        }
	        else
	        {
	        	StateMgr.Start_Signin_State();
	        }
			
            break;
            
        case this.CreateAccountBtn:
			//StateMgr.Start_Create_Account_State();
			StateMgr.Start_Guide_Page_State(GUIDEPAGE_TYPE.CREATE_NEW_ACCOUNT);
            break;
        case this.MSABtn:
        	StateMgr.Start_Guide_Page_State(GUIDEPAGE_TYPE.SIGNIN_WITH_MSA);
        	break;
        case this.NeedHelpBtn:
        	StateMgr.Start_Guide_Page_State(GUIDEPAGE_TYPE.NEED_HELP);
            break;
    }
     //NewPopup.showPopup('Test_popup');

   
   
}

SceneWelcome.prototype.processReturnKey = function(){
    alert("SceneWelcome.processReturnKey() ");
   
   ProcMgr.CloseWithSignIn();
}

SceneWelcome.prototype.processExitKey = function(){
    alert("SceneWelcome.processExitKey() ");
   
   ProcMgr.ExitWithSignIn();
}
SceneWelcome.prototype.showTooltip = function(){
    alert("SceneWelcome.showTooltip() ");
    $('#welcome_need_help_tootip').sfTooltip('show');
    this.IsShowTooltipFlag = true;
   
}
SceneWelcome.prototype.hideTooltip = function(){
    alert("SceneWelcome.hideTooltip() ");
    $('#welcome_need_help_tootip').sfTooltip('hide');
    this.IsShowTooltipFlag = false;
   
}


///////// Processing Click evnet  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneWelcome.prototype.processClickEvent = function(obj){
	alert("SceneWelcome.processClickEvent() ");
	
	/*var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }*/
	
	this.processEnterKey();
}
SceneWelcome.prototype.processMouseOverEvent = function(obj){
	alert("SceneWelcome.processMouseOverEvent() ");
	
	var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	//this.processEnterKey();
}
SceneWelcome.prototype.startDebugMode = function(){
	var imeBox = new IMEShell_Common();
	imeBox.imputTitle="Input debug code";
	imeBox.onKeyPressFunc = this.debugKeyCallback;
	imeBox.onShow();
}
SceneWelcome.prototype.debugKeyCallback = function(key, str, id){
	var Scene = sf.scene.get("Welcome");
    switch (key) {
        case sf.key.ENTER: // Enter Key
            alert("ENTER - str is "+str);
            WndMgr.isDebugMode = true;
            WndMgr.StartOneBottonPopup(parseInt(str));
            // Scene.str = str;
            // Scene.processEnterKey();
            break;
        case sf.key.RETURN:  //return
            alert("RETURN");
            break;
        case sf.key.EXIT:  //exit
            alert("EXIT");
            break;
    }
}
