if(!this.StateMgr) {
	this.StateMgr = new Object();
}

 var MAIN_STATE={
        INIT : 0,
        MAIN : 1,
        CALLING : 2,
        VIDEO_CALL : 3,
        CONFERENCE_CALL:4,
		INCOMING_CALL : 5,
		WELCOME : 6,
		NOTCALLINDUALVIEW : 7,
				
		MAX_MAIN_STATE : 8
}

 var SUB_STATE={
        CALL_ENDING : 7,				//use
        VOLUME_SPEAKER : 10,			//use
        SIGNOUT : 13,
		
		
		MINI_STATUS_CHANGE : 26,
		MINI_CONTACT_CALL_MENU: 27,
		MINI_CONTACT_ADD_MENU:28,
		MINI_PHONE_NUMBER_LIST:29,
		
		
		MAX_SUB_STATE : 30
}

/*

var SUB_LIST = {

	COUNTRY_FLAG			: 0,
	CONTACT_PHONE_NUMBER	: 1,
	MAX_SUB_LIST 			: 2, 	
}*/


StateMgr = {
    MainStateList : new Array(MAIN_STATE.MAX_MAIN_STATE),    
    SubStateList : new Array(SUB_STATE.MAX_SUB_STATE),   
   // SubListArray : new Array(SUB_LIST.MAX_SUB_LIST),
	
    currentState : "Init",
    preState : "Deactivate",
    
   // MainInfo : null,
        
    currentSubState : "",
    preSubState : "",
 	
    skypeLoadCheckTimer : null,
	
    FuncParamA : null,
	FuncParamB : null,
	FuncParamC : null,
	FuncParamD : null,
	
	/*
	delaySubLoadingState : null,
		flagDelaySubLoading : false,*/
	

}
//2013mini add by minseok

StateMgr.SetCurrentState = function(index)
{
	//this.preState = this.currentState;
	alert("##mini##[SkypeMini]StateMgr.SetCurrentState() : "+this.currentState+" -> "+this.MainStateList[index].id);
	//this.preState =this.currentState; 
	this.currentState = this.MainStateList[index].id;
	
}
StateMgr.GetCurrentStateIdx = function(){
	for(a=0; a<this.MainStateList.length; a++)
    {
    	if(this.MainStateList[a].id==this.currentState){
    		return a;
    	}
    }
    return 0; //init
}

StateMgr.GetCurrentState = function()
{
    return this.currentState;
}

StateMgr.GetCurrentSubState = function()
{
    return this.currentSubState;
}

StateMgr.GetPreSubState = function()
{
    return this.preSubState;
}

StateMgr.initState = function(){
 	alert("##mini##***** StateMgr.initState ()");
	
    this.initMainState();
    this.initSubState();
    this.preLoadScene();
    
	//this.initNotiState();
	//this.initSubList();

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////  Main State  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


StateMgr.initMainState = function(){
    var a=0;
    for(a=0; a<this.MainStateList.length; a++)
    {
        this.MainStateList[a] = new Object();
        this.MainStateList[a].flagLoad = false;
       // this.MainStateList[a].flagLoading = false;
    }
    
    this.MainStateList[MAIN_STATE.INIT].id = "miniWidgetLoading";
    this.MainStateList[MAIN_STATE.MAIN].id = "miniMainContact";
    this.MainStateList[MAIN_STATE.VIDEO_CALL].id = "miniSkypeCall";
    this.MainStateList[MAIN_STATE.CONFERENCE_CALL].id = "miniConferenceCall";
    this.MainStateList[MAIN_STATE.CALLING].id = "miniCalling";
	this.MainStateList[MAIN_STATE.WELCOME].id = "miniWelcome";
	this.MainStateList[MAIN_STATE.INCOMING_CALL].id = "miniIncomingCall";
	this.MainStateList[MAIN_STATE.NOTCALLINDUALVIEW].id = "miniCannotCallInDualView";
	    
   // this.MainStateList[MAIN_STATE.INIT].flagLoad = true;
    	
    /*
    this.MainInfo = new Object();      
        this.MainInfo.prevState = null;
        this.MainInfo.curState = null;*/
    
        
}
/*

StateMgr.setMainStateLoading = function(index){
    
	this.initMainStateLoading();    
    this.MainStateList[index].flagLoading = true;
}

StateMgr.initMainStateLoading = function(){
    
    var a=0;
    for(a=0; a<this.MainStateList.length; a++)
    {
        this.MainStateList[a].flagLoading = false;
    }
}
*/

StateMgr.showMainState = function(index , callbackShowFn){
    alert("##mini##-------------------------------------------------------------- show MainState -------------------------------------------------");
   /*
    if(this.MainStateList[index].flagLoading == true)
       {
           return;
       }*/
   
	// StateMgr.StartLoadingState();
	
 
    if(this.MainStateList[index].flagLoad ==false) {
 
    	//2013mini modify by minseok : load scene
    	//this.MainStateList[index].flagLoad = true;
    	alert("##mini##StateMgr.showMainState() loadScene : "+this.MainStateList[index].id + " in "+this.MainStateList[index].id+"_id");
   
    	//$('#MiniSkype').loadScene({id:this.MainStateList[index].id, scope:WIDGET.id});
    	$('#'+this.MainStateList[index].id+'_id').loadScene({id:this.MainStateList[index].id, scope:WIDGET.id});
		//$.sfScene.hide({id:this.MainStateList[index].id, scope:WIDGET.id});
		StateMgr.MainStateList[index].flagLoad = true;
	
	    
    }
    callbackShowFn();
}

/*

StateMgr.isMainStateLoaing = function()
{
	var a=0;
    for(a=0; a<this.MainStateList.length; a++)
    {
		if(this.MainStateList[a].flagLoading == true)
		{
			return true;
		} 
    }
	
	return false;
}


StateMgr.setDelaySubLoadingState = function(callbackSubStartFn)
{
	this.delaySubLoadingState =callbackSubStartFn;
}*/

//2013mini add by minseok
StateMgr.Start_Current_State = function(currentIndex){
	this.preState = this.currentState;
    alert("##mini##***** Start_Current_State = old [" +  this.preState + "]");
    if(currentIndex==null)
   		currentIndex = this.GetCurrentStateIdx();
	//var currentIndex = this.GetCurrentStateIdx();
    StateMgr.showMainState(currentIndex , function(){ StateMgr.Show_Current_State(currentIndex);}) ;
}
StateMgr.Show_Current_State = function(currentIndex){
	//var currentIndex = this.GetCurrentStateIdx();
	this.currentState = this.MainStateList[currentIndex].id;
    alert("##mini##***** Show_Current_State = [" +  this.currentState + "]");
    this.StopPreState();
    
    WndMgr.ShowCurrentScene(this.currentState);
}
StateMgr.Focus_Current_State = function(){
	alert("##mini##[SkypeMini] Focus_Current_State = [" +  this.currentState + "]");
	
	if(this.currentState=="miniWidgetLoading"||this.currentState=="Init"){
		alert("##mini##[SkypeMini] Skype Loading....");
			return;
		}
	utilitySet.changeTabBGStatus(WIDGET.id,'focus',true);
	$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).tabFocus=false;
	WndMgr.FocusCurrentScene(this.currentState);
}
StateMgr.Hide_Current_State = function(){
	WndMgr.HideCurrentScene(this.currentState);
}

StateMgr.Start_Init_State = function(){
	
	WndMgr.init();						//variable setting
	StateMgr.initState(); 
   // StateMgr.SetCurrentState(MAIN_STATE.WELCOME);
    this.Start_Current_State(MAIN_STATE.INIT);

    alert("##mini##***** Start_Init_State = new [" +  this.currentState + "]");
    
    ResMgr.initResource();					//get lanaguage code
    
    //PluginAPIMgr.initPluginAPI();
    EventMgr.initEvent();
        	
	setTimeout("CloseTimerCF()", 0);
	CloseTimerCF = function(){

		PluginAPIMgr.SyncCameraState();
		PluginAPIMgr.GetPanelResolution();
		
		if(WndMgr.Is1366x768Panel() == true)
		{
			PluginAPIMgr.SetTVRecvRect(996,154,296,222);//996,154,298,224
			PluginAPIMgr.SetTVPreviewRect(996,386,296,222);//996,386,298,224
			PluginAPIMgr.SetCallingViewRect(1067,504,160,120);//1067,504,162,121
		}
		else
		{
			PluginAPIMgr.SetTVRecvRect(1400,217,420,315);
			PluginAPIMgr.SetTVPreviewRect(1400,543,420,315);
			PluginAPIMgr.SetCallingViewRect(1500,710,228,171);
		}
	
		if(PluginAPIMgr.GetSkypeState() == 1)
	    {
	        ProcMgr.StartWidget();
	    }
	}
}

StateMgr.Start_Main_State = function(){
    this.preState =  this.currentState;
    alert("##mini##***** Start_Main_State = old [" +  this.preState + "]");

    StateMgr.showMainState(MAIN_STATE.MAIN, function(){ StateMgr.Show_Main_State();}) ;
}

StateMgr.Show_Main_State = function(){
    this.currentState = this.MainStateList[MAIN_STATE.MAIN].id;
    alert("##mini##***** Start_Main_State = [" +  this.currentState + "]");
    
    alert("##mini##***** StateMgr.Show_Main_State ()");
    this.StopPreState();
    
    WndMgr.ShowMain();
}

StateMgr.Start_Video_Call_State = function(){

   /*
    if( this.MainStateList[MAIN_STATE.VIDEO_CALL].flagLoading == true)
       {
           return;
       }*/
   
    
    this.preState =  this.currentState;
    this.preStateIdx = MAIN_STATE.VIDEO_CALL;
    alert("##mini##***** Start_Video_Call_State = old [" +  this.preState + "]");

    StateMgr.showMainState(MAIN_STATE.VIDEO_CALL, function(){ StateMgr.Show_Video_Call_State();}) ;
}

StateMgr.Show_Video_Call_State = function(){
	if(this.currentSubState == "miniCallEnding")
	{
		return;
	}
	
    this.currentState = this.MainStateList[MAIN_STATE.VIDEO_CALL].id;
    alert("##mini##***** Start_Video_Call_State = new [" +  this.currentState + "]");
    
    alert("##mini##***** StateMgr.Show_Video_Call_State ()");
    this.StopPreState();
    
    WndMgr.ShowVideoCall();
}

StateMgr.Start_Conference_Call_State = function(){
    this.preState =  this.currentState;
    alert("##mini##***** Start_Conference_Call_State = old [" +  this.preState + "]");

    StateMgr.showMainState(MAIN_STATE.CONFERENCE_CALL, function(){ StateMgr.Show_Conferenc_Call_State();}) ;
}

StateMgr.Show_Conferenc_Call_State = function(){
	if(this.currentSubState == "miniCallEnding")
	{
		return;
	}
	
    this.currentState =this.MainStateList[MAIN_STATE.CONFERENCE_CALL].id;
    alert("##mini##***** Start_Conference_Call_State = new [" +  this.currentState + "]");
    
    alert("##mini##***** StateMgr.Show_Conferenc_Call_State ()");
    this.StopPreState();
    
    WndMgr.ShowConferenceCall();
}

StateMgr.Start_Welcome_State = function(){
    this.preState =  this.currentState;
    alert("##mini##***** Start_Welcome_State = old [" +  this.preState + "]");
    StateMgr.showMainState(MAIN_STATE.WELCOME, function(){ StateMgr.Show_Welcome_State();}) ;
}

StateMgr.Show_Welcome_State = function(){
    this.currentState = this.MainStateList[MAIN_STATE.WELCOME].id;
    alert("##mini##***** Start_Welcome_State = [" +  this.currentState + "]");
    
    alert("##mini##***** StateMgr.Show_Create_Account_State ()");
    this.StopPreState();
	
	if(this.MainStateList[MAIN_STATE.MAIN].flagLoad ==true)
    {
        WndMgr.DestroyMain();
    }

    WndMgr.ShowWelcome();   
}

StateMgr.Start_Calling_State = function(){
	
    this.preState =  this.currentState;
    this.preStateIdx = MAIN_STATE.CALLING;
    alert("##mini##***** Start_Calling_State = old [" +  this.preState + "]");

    StateMgr.showMainState(MAIN_STATE.CALLING, function(){ StateMgr.Show_Calling_State();}) ;

}

StateMgr.Show_Calling_State = function(){
	
    this.currentState = this.MainStateList[MAIN_STATE.CALLING].id;
    alert("##mini##***** Start_Calling_State = new [" +  this.currentState + "]");
    
    alert("##mini##***** StateMgr.Show_Calling_State ()");

    this.StopPreState();
    
    WndMgr.ShowCalling();
}

StateMgr.Start_Incoming_Call_State = function()
{
	
    this.preState =  this.currentState;
	this.preStateIdx = MAIN_STATE.INCOMING_CALL;
    alert("##mini##***** Start_Incoming_Call_State = old [" +  this.preState + "]");
    
    StateMgr.showMainState(MAIN_STATE.INCOMING_CALL, function(){ StateMgr.Show_Incoming_Call_State();}) ;
}

StateMgr.Show_Incoming_Call_State = function()
{
    this.currentState = this.MainStateList[MAIN_STATE.INCOMING_CALL].id;
    alert("##mini##***** Start_Incoming_Call_State = new [" +  this.currentState + "]");
    
    alert("##mini##***** StateMgr.Show_Incoming_Call_State ()");

    this.StopPreState();

    WndMgr.ShowIncomingCall();
}
StateMgr.Start_NotCall_In_DualView_State = function()
{
	
    this.preState =  this.currentState;
	this.preStateIdx = MAIN_STATE.NOTCALLINDUALVIEW;
    alert("##mini##***** Start_NotCall_In_DualView_State = old [" +  this.preState + "]");
    
    StateMgr.showMainState(MAIN_STATE.NOTCALLINDUALVIEW, function(){ StateMgr.Show_NotCall_In_DualView_State();}) ;
}

StateMgr.Show_NotCall_In_DualView_State = function()
{
    this.currentState = this.MainStateList[MAIN_STATE.NOTCALLINDUALVIEW].id;
    alert("##mini##***** Start_NotCall_In_DualView_State = new [" +  this.currentState + "]");
    
    alert("##mini##***** StateMgr.Show_NotCall_In_DualView_State ()");

    this.StopPreState();
    WndMgr.ShowNotCallInDualView();

}
StateMgr.preLoadScene = function(){
	alert("##mini##preLoadScene loadScene : "+this.SubStateList[SUB_STATE.CALL_ENDING].id);
	$('#'+this.SubStateList[SUB_STATE.CALL_ENDING].id+'_id').loadScene({id:this.SubStateList[SUB_STATE.CALL_ENDING].id, scope:WIDGET.id});

	this.MainStateList[MAIN_STATE.INCOMING_CALL].flagLoad = true; 
	$('#miniIncomingCall_id').loadScene({id:"miniIncomingCall", scope:WIDGET.id});
	$.sfScene.hide({id:"miniIncomingCall", scope:WIDGET.id});
	
	this.SubStateList[SUB_STATE.CALL_ENDING].flagLoad = true; 
	$.sfScene.hide({id:"miniCallEnding", scope:WIDGET.id});
	
	$('#miniOneButtonPopup_id').loadScene({id:"miniOneButtonPopup", scope:WIDGET.id});
	$.sfScene.hide({id:"miniOneButtonPopup", scope:WIDGET.id});

	$('#miniCallConfirmPopup_id').loadScene({id:"miniCallConfirmPopup", scope:WIDGET.id});
	$.sfScene.hide({id:"miniCallConfirmPopup", scope:WIDGET.id});
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////  Sub State  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

StateMgr.initSubState = function(){

    var b=0;
    for(b=0; b<this.SubStateList.length; b++)
    {
        this.SubStateList[b] = new Object();
        this.SubStateList[b].flagLoad = false;
    }
	
	this.SubStateList[SUB_STATE.CALL_ENDING].id = "miniCallEnding";
    this.SubStateList[SUB_STATE.VOLUME_SPEAKER].id = "miniVolume";
    this.SubStateList[SUB_STATE.SIGNOUT].id = "miniSignout";    
	/*ADDED*/
	this.SubStateList[SUB_STATE.MINI_STATUS_CHANGE].id = "miniStatusChange";
	this.SubStateList[SUB_STATE.MINI_CONTACT_CALL_MENU].id = "miniContactCallMenu"; 
	this.SubStateList[SUB_STATE.MINI_CONTACT_ADD_MENU].id = "miniContactAddMenu"; 
	this.SubStateList[SUB_STATE.MINI_PHONE_NUMBER_LIST].id = "miniPhoneNumberList";  	   
	
}

/*

StateMgr.setSubStateLoading = function(index)
{
    this.initSubStateLoading();
    this.SubStateList[index].flagLoading = true;
}

StateMgr.initSubStateLoading= function(){
	var b=0;
    for(b=0; b<this.SubStateList.length; b++)
    {
        this.SubStateList[b].flagLoading = false;
    }
}*/


StateMgr.showSubState = function(index , callbackShowFn, callbackStartFn){
	alert("##mini##StateMgr.showSubState()");
    if(this.SubStateList[index].flagLoad ==false)
    {
		alert("##mini##showSubState loadScene : "+this.SubStateList[index].id);
    	$('#'+this.SubStateList[index].id+'_id').loadScene({id:this.SubStateList[index].id, scope:WIDGET.id});
				
		StateMgr.SubStateList[index].flagLoad = true;
     }  
     callbackShowFn();
}


StateMgr.Start_Call_Ending_State = function(flagCallEndByMe){
    if(this.currentState == "miniCalling")// || StateMgr.MainStateList[MAIN_STATE.CALLING].flagLoading == true)
    {
        WndMgr.updateCallingButton(true);
        return;
    }

    this.preSubState = this.currentSubState;
	
	this.FuncParamA = flagCallEndByMe;
	
   
    alert("##mini##***** Start_Call_Ending_State = old [" +  this.preSubState + "]");

    StateMgr.showSubState(SUB_STATE.CALL_ENDING, function(){ StateMgr.Show_Call_Ending_State();}, function(){ StateMgr.Start_Call_Ending_State(flagCallEndByMe);}) ;
}

StateMgr.Show_Call_Ending_State = function(){
	
    this.currentSubState =this.SubStateList[SUB_STATE.CALL_ENDING].id;
    alert("##mini##***** Start_Call_Ending_State = new [" +  this.currentSubState + "]");
    
    alert("##mini##***** StateMgr.Show_Call_Ending_State ()");
   
    if(this.preSubState ==  this.currentSubState)
    {
       WndMgr.UpdateCallEndingStatus();
    }
    else
    {
   
        StateMgr.StopPreSubState();
        WndMgr.ShowCallEnding(this.FuncParamA);
    }

	this.FuncParamA = null;
}

StateMgr.Stop_Call_Ending_State = function(flagReturn){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Stop_Call_Ending_State = old [" +  this.preSubState + "]");

    this.currentSubState = "";
    alert("##mini##***** Stop_Call_Ending_State = new [" +  this.currentSubState + "]");
    
    WndMgr.HideCallEnding();
    
    if(flagReturn==true)
    {
        this.ReturnState();
    }
}

    

StateMgr.Start_Volume_Speaker_State = function(){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Start_Volume_Speaker_State = old [" +  this.preSubState + "]");

    StateMgr.showSubState(SUB_STATE.VOLUME_SPEAKER, function(){ StateMgr.Show_Volume_Speaker_State();}, function(){ StateMgr.Start_Volume_Speaker_State();}) ;
}

StateMgr.Show_Volume_Speaker_State = function(){
    this.currentSubState = this.SubStateList[SUB_STATE.VOLUME_SPEAKER].id ;
    alert("##mini##***** Start_Volume_Speaker_State = new [" +  this.currentSubState + "]");
    
    alert("##mini##***** StateMgr.Show_Volume_Speaker_State ()");

    StateMgr.StopPreSubState();
    WndMgr.ShowVolumeSpeaker();
}


StateMgr.Stop_Volume_Speaker_State = function(flagReturn){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Stop_Volume_Speaker_State = old [" +  this.preSubState + "]");

    this.currentSubState = "";
    alert("##mini##***** Stop_Volume_Speaker_State = new [" +  this.currentSubState + "]");
    
    WndMgr.HideVolumeSpeaker();
    
    if(flagReturn==true)
    {
        this.ReturnState();
    }
}

StateMgr.Start_Signout_State = function(){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Start_Signout_State = old [" +  this.preSubState + "]");

	//no use replace callconfirmpopup
     // StateMgr.showSubState(SUB_STATE.SIGNOUT, function(){ StateMgr.Show_Signout_State();}, function(){ StateMgr.Start_Signout_State();}) ;
     StateMgr.Show_Signout_State();
}

StateMgr.Show_Signout_State = function(){
    this.currentSubState = this.SubStateList[SUB_STATE.SIGNOUT].id;
    alert("##mini##***** Start_Signout_State = new [" +  this.currentSubState + "]");
    
    alert("##mini##***** StateMgr.Show_Signout_State ()");
    StateMgr.StopPreSubState();
    WndMgr.StartCallConfirmPopup(MINI_CALL_CONFIRM_POPUP.SIGN_OUT);
    // WndMgr.ShowSignout();
}

StateMgr.Stop_Signout_State = function(flagReturn){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Stop_Signout_State = old [" +  this.preSubState + "]");

    this.currentSubState = "";
    alert("##mini##***** Stop_Signout_State = new [" +  this.currentSubState + "]");
    
    WndMgr.HideSignout();
    
    if(flagReturn==true)
    {
        this.ReturnState();
    }
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////// Return  State  ////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

StateMgr.ReturnToMainState = function()
{   
  //  WndMgr.HideTextEditor();
	WndMgr.HideOneBottonPopup();
	WndMgr.HideCallConfirmPopup();
	//WndMgr.HideKeypad(); 
    
    if(this.currentSubState.length != 0)
    {
        this.StopSubState();
    }
  //  this.stopSubList();
    
    StateMgr.ReturnState(); 
}

StateMgr.ReturnState = function()
{
	alert("##mini##***** ReturnState");
	if($.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).tabFocus==true){
		$.sfScene.focus({id:WIDGET.name,scope:WIDGET.id});		//because callconfimpopup->sign out
	 	return ;
	}
	WndMgr.FocusCurrentScene(this.currentState);
	/*
	switch(this.currentState)
		{     
			case "miniMainContact": 
				WndMgr.ReturnMain();
				break;
	
			case "miniCalling":
				WndMgr.ReturnCalling(); 
				break;
			
			case "miniSkypeCall":     
				WndMgr.ReturnVideoCall();
				break;
			
			case "miniConferenceCall":     
				WndMgr.ReturnConferenceCall();
				break;
	
			case "miniWelcome": 
				WndMgr.ReturnWelcome(); 
				break;	
	
			case "miniIncomingCall":
				WndMgr.ReturnIncomingCall(); 
				break;			
		}*/
	
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////// Stop Pre State   //////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
StateMgr.StopPreState = function() {

	alert("##mini##***** StopPreState");
	WndMgr.HideOneBottonPopup();
	WndMgr.HideCallConfirmPopup();   

	if (Flag_Hidden_State == false && popupHandler != null) {
		if (popupHandler.CURRENT_POPUP == 1) {//SERVICE_TOOLS_POPUP
			popupHandler.hidePopup(popupHandler.SERVICE_TOOLS_POPUP);
		} else if (popupHandler.CURRENT_POPUP == 4) {//EXIT_POPUP
			popupHandler.hideMessagePopup();
		}
	}

    if(this.currentSubState.length != 0)
    {
        this.StopSubState();
    }
    if(this.preState == this.currentState)
   		return ;
    switch(this.preState)
    {
       case "miniWidgetLoading":     
            this.Stop_Init_State(); 
            break;
              
        case "miniMainContact":     
            this.Stop_Main_State(); 
            break;
            
		case "miniCalling":
			this.Stop_Calling_State(); 
            break;
            
        case "miniSkypeCall":     
            this.Stop_Video_Call_State(); 
            break;
            
        case "miniConferenceCall":     
            this.Stop_Conference_Call_State(); 
            break;
            
		case "miniWelcome": 
			this.Stop_Welcome_State(); 
			break;
		
		case "miniIncomingCall":
			this.Stop_Incoming_Call_State(); 
            break;
		case "miniCannotCallInDualView":
			this.Stop_NotCall_In_DualView_State(); 
            break;
    }
}

StateMgr.Stop_Init_State = function(){
    alert("##mini##***** Stop_Init_State =  [" +  this.preState + "]");
    
    WndMgr.HideInit();
}

StateMgr.Stop_Main_State = function(){
    alert("##mini##***** Stop_Main_State =  [" +  this.preState + "]");
    
    WndMgr.HideMain();
}

StateMgr.Stop_Video_Call_State = function()
{
    alert("##mini##***** Stop_Video_Call_State =  [" +  this.preState + "]");
    
    WndMgr.HideVideoCall();
}

StateMgr.Stop_Conference_Call_State = function()
{
    alert("##mini##***** Stop_Conference_Call_State =  [" +  this.preState + "]");
    
    WndMgr.HideConferenceCall();
}

StateMgr.Stop_Welcome_State = function()
{
    alert("##mini##***** Stop_Welcome_State =  [" +  this.preState + "]");
    
    WndMgr.HideWelcome();
}

StateMgr.Stop_Calling_State = function(){
    
    alert("##mini##***** Stop_Calling_State = old [" +  this.preState + "]");

    WndMgr.HideCalling();
}

StateMgr.Stop_Incoming_Call_State = function(){
    
    alert("##mini##***** Stop_Incoming_Call_State = old [" +  this.preState + "]");
    
    WndMgr.HideIncomingCall();
    
}
StateMgr.Stop_NotCall_In_DualView_State = function(){
    
    alert("##mini##***** Stop_NotCall_In_DualView_State = old [" +  this.preState + "]");
    
    WndMgr.HideNotCallInDualView();
    
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////Stop Sub State///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


StateMgr.StopSubState = function() {
	alert("StopSubState : "+this.currentSubState);
    switch(this.currentSubState)
    {
		case "miniCallEnding":
			this.Stop_Call_Ending_State(); 
			break;     
		
		case "VolumeMic":
			this.Stop_Volume_Mic_State(); 
			break;
		
		case "miniVolume":
			this.Stop_Volume_Speaker_State(); 
			break;
		
		
		case "miniSignout":     
			this.Stop_Signout_State(); 
			break;
		

			
		/*added*/
		case "miniStatusChange":
			this.Stop_Mini_Status_Change(); 
			break;	
		case "miniContactAddMenu":
			this.Stop_Mini_Contact_Add_Menu(); 
			break;
		case "miniPhoneNumberList":
			this.Stop_Mini_Phone_Number_List(); 
			break;
		case "miniContactCallMenu":
			this.Stop_Mini_Contact_Call_Menu(); 
			break;	
    }
}

//////Stop Pre Sub State///////////////////////////////////////////////////////////////////////////////////////////////////

StateMgr.StopPreSubState = function() {
    
	alert("##mini##StateMgr.StopPreSubState");
    if(this.preSubState == this.currentSubState){
    	alert("##mini##presubstate & currentsubstate is same !")
     	return ;
     }
	WndMgr.HideOneBottonPopup();
	WndMgr.HideCallConfirmPopup();
  //  WndMgr.HideTextEditor();
	/*
	WndMgr.HideOneBottonPopup();
		WndMgr.HideCallConfirmPopup();*/
	//WndMgr.HideKeypad();


	if (Flag_Hidden_State == false && popupHandler != null) {
		if (popupHandler.CURRENT_POPUP == 1) {//SERVICE_TOOLS_POPUP
			popupHandler.hidePopup(popupHandler.SERVICE_TOOLS_POPUP);
		} else if (popupHandler.CURRENT_POPUP == 4) {//EXIT_POPUP
			popupHandler.hideMessagePopup();
		}
	}   

	
    
    if(this.preSubState.length ==0)
    {
            return;
    }
    
    var nextSubState = this.currentSubState;
    
    switch(this.preSubState)
    {
		
		case "miniCallEnding":
			this.Stop_Call_Ending_State(); 
			break;     
		
		case "VolumeMic":
			this.Stop_Volume_Mic_State(); 
			break;
		
		case "miniVolume":
			this.Stop_Volume_Speaker_State(); 
			break;
		
		
		case "miniSignout":     
			this.Stop_Signout_State(); 
			break;
		
		/*added*/
		case "miniStatusChange":
			this.Stop_Mini_Status_Change(); 
			break;	
		case "miniContactAddMenu":
			this.Stop_Mini_Contact_Add_Menu(); 
			break;
		case "miniPhoneNumberList":
			this.Stop_Mini_Phone_Number_List(); 
			break;
		case "miniContactCallMenu":
			this.Stop_Mini_Contact_Call_Menu(); 
			break;		
    }
    
    this.currentSubState = nextSubState;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////  Sub List  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
StateMgr.initSubList = function(){

    var d=0;
    for(d=0; d < SUB_LIST.MAX_SUB_LIST; d++)
    {
        this.SubListArray[d] = new Object();
        this.SubListArray[d].flagLoad = false;
    }
    
    this.SubListArray[SUB_LIST.COUNTRY_FLAG].id = "SignupCountryList";
    this.SubListArray[SUB_LIST.CONTACT_PHONE_NUMBER].id = "ListMainContactPhoneNumberList";
   
}



StateMgr.showSubList = function(index , callbackShowFn){
	
    if(this.SubListArray[index].flagLoad == false)
    {		        
        $.sfScene.loadMode(		
			this.SubListArray[index].id , 		
		    function() {
            	StateMgr.SubListArray[index].flagLoad = true;
				callbackShowFn();
        	}
		);
    }
    else{
        callbackShowFn();
    }

}

StateMgr.stopSubList = function(){

	if(this.currentSubList == 'SignupCountryList')
	{
		$.sfScene.get("SignupCountryList").ProcessKeyReturn();
	}
	else if(this.currentSubList == 'ListMainContactPhoneNumberList')
	{
		$.sfScene.get("ListMainContactPhoneNumberList").ProcessKeyReturn();
	}

	this.currentSubList = null;
}

StateMgr.Show_CountryFlagName = function(FuncParamA,FuncParamB,FuncParamC,FuncParamD){

	this.currentSubList = 'SignupCountryList';
	
     StateMgr.showSubList(
	 	SUB_LIST.COUNTRY_FLAG,
	 	function(){
			$.sfScene.get("SignupCountryList").Init(FuncParamA,FuncParamB,FuncParamC,FuncParamD );	
			$.sfScene.show('SignupCountryList');
			$.sfScene.focus('SignupCountryList');								
		}
	);
	 
}

StateMgr.Show_ContactPhoneNumberList = function(FuncParamA,FuncParamB,FuncParamC){

	this.currentSubList = 'ListMainContactPhoneNumberList';

     StateMgr.showSubList(
	 	SUB_LIST.CONTACT_PHONE_NUMBER,
	 	function(){
			$.sfScene.get("ListMainContactPhoneNumberList").SetInfo(FuncParamA,FuncParamB,FuncParamC);	
			$.sfScene.show('ListMainContactPhoneNumberList');
			$.sfScene.focus('ListMainContactPhoneNumberList');
		}
	);
	 
}*/


/*added */

StateMgr.Start_Mini_Status_Change = function(){
    this.preSubState = this.currentSubState;
    alert("##mini##***** Start_Mini_Status_Change = old [" +  this.preSubState + "]");

    StateMgr.showSubState(SUB_STATE.MINI_STATUS_CHANGE, function(){ StateMgr.Show_Mini_Status_Change();}, function(){ StateMgr.Start_Mini_Status_Change();});
}

StateMgr.Show_Mini_Status_Change = function(){
    this.currentSubState = this.SubStateList[SUB_STATE.MINI_STATUS_CHANGE].id ;
    alert("##mini##***** Start_Mini_Status_Change = new [" +  this.currentSubState + "]");
    
    alert("##mini##***** StateMgr.Mini_Status_Change ()");
    StateMgr.StopPreSubState();
    WndMgr.ShowMiniStatusChange();
}

StateMgr.Stop_Mini_Status_Change = function(flagReturn){
    this.preSubState = this.currentSubState;
    alert("##mini##***** Stop_Mini_Status_Change = old [" +  this.preSubState + "]");

    this.currentSubState = "";
    alert("##mini##***** Stop_Mini_Status_Change = new [" +  this.currentSubState + "]");
    
    WndMgr.HideMiniStatusChange();
    
    if(flagReturn==true)
    {
        this.ReturnState();
    }
}

StateMgr.Start_Mini_Contact_Add_Menu = function(itemIndex,skypeId){
    this.preSubState = this.currentSubState;
    this.FuncParamA = itemIndex;
	this.FuncParamB = skypeId;
    alert("##mini##***** Start_Mini_Contact_Add_Menu = old [" +  this.preSubState + "]");

    StateMgr.showSubState(SUB_STATE.MINI_CONTACT_ADD_MENU, function(){ StateMgr.Show_Mini_Contact_Add_Menu();}, function(){ StateMgr.Start_Mini_Contact_Add_Menu();});
}

StateMgr.Show_Mini_Contact_Add_Menu = function(){
    this.currentSubState = this.SubStateList[SUB_STATE.MINI_CONTACT_ADD_MENU].id ;
    alert("##mini##***** Start_Mini_Contact_Add_Menu = new [" +  this.currentSubState + "]");
    
    alert("##mini##***** StateMgr.Mini_Contact_Add_Menu ()");
    StateMgr.StopPreSubState();
    WndMgr.ShowMiniContactAddMenu(this.FuncParamA,this.FuncParamB);
}

StateMgr.Stop_Mini_Contact_Add_Menu = function(flagReturn){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Stop_Mini_Contact_Add_Menu = old [" +  this.preSubState + "]");

    this.currentSubState = "";
    alert("##mini##***** Stop_Mini_Contact_Add_Menu = new [" +  this.currentSubState + "]");
    
    WndMgr.HideMiniContactAddMenu();
    
    if(flagReturn==true)
    {
        this.ReturnState();
    }
}
StateMgr.Start_Mini_Contact_Call_Menu = function(itemIndex,skypeId,enableVideo){
    this.preSubState = this.currentSubState;
    this.FuncParamA = itemIndex;
	this.FuncParamB = skypeId;
	this.FuncParamC = enableVideo;
    
    alert("##mini##***** Start_Mini_Contact_Call_Menu = old [" +  this.preSubState + "]");

    StateMgr.showSubState(SUB_STATE.MINI_CONTACT_CALL_MENU, function(){ StateMgr.Show_Mini_Contact_Call_Menu();}, function(){ StateMgr.Start_Mini_Contact_Call_Menu();});
}

StateMgr.Show_Mini_Contact_Call_Menu = function(){
    this.currentSubState = this.SubStateList[SUB_STATE.MINI_CONTACT_CALL_MENU].id ;
    alert("##mini##***** Start_Mini_Contact_Call_Menu = new [" +  this.currentSubState + "]");
    
    alert("##mini##***** StateMgr.Mini_Contact_Call_Menu ()");
    StateMgr.StopPreSubState();
    WndMgr.ShowMiniContactCallMenu(this.FuncParamA,this.FuncParamB,this.FuncParamC);
}

StateMgr.Stop_Mini_Contact_Call_Menu = function(flagReturn){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Stop_Mini_Contact_Call_Menu = old [" +  this.preSubState + "]");

    this.currentSubState = "";
    alert("##mini##***** Stop_Mini_Contact_Call_Menu = new [" +  this.currentSubState + "]");
    
    WndMgr.HideMiniContactCallMenu();
    
    if(flagReturn==true)
    {
        this.ReturnState();
    }
}
StateMgr.Start_Mini_Phone_Number_List = function(itemIndex,skypeId){
    this.preSubState = this.currentSubState;
    this.FuncParamA = itemIndex;
	this.FuncParamB = skypeId;
    
    alert("##mini##***** Start_Mini_Phone_Number_List = old [" +  this.preSubState + "]");

    StateMgr.showSubState(SUB_STATE.MINI_PHONE_NUMBER_LIST, function(){ StateMgr.Show_Mini_Phone_Number_List();}, function(){ StateMgr.Start_Mini_Phone_Number_List();});
}

StateMgr.Show_Mini_Phone_Number_List = function(){
    this.currentSubState = this.SubStateList[SUB_STATE.MINI_PHONE_NUMBER_LIST].id ;
    alert("##mini##***** Start_Mini_Phone_Number_List = new [" +  this.currentSubState + "]");
    
    alert("##mini##***** StateMgr.Show_Mini_Phone_Number_List ()");
    StateMgr.StopPreSubState();
    WndMgr.ShowMiniPhoneNumberList(this.FuncParamA,this.FuncParamB);
}

StateMgr.Stop_Mini_Phone_Number_List = function(flagReturn){
    this.preSubState = this.currentSubState;
    
    alert("##mini##***** Stop_Mini_Phone_Number_List = old [" +  this.preSubState + "]");

    this.currentSubState = "";
    alert("##mini##***** Stop_Mini_Phone_Number_List = new [" +  this.currentSubState + "]");
    
    WndMgr.HideMiniPhoneNumberList();
    
    if(flagReturn==true)
    {
        this.ReturnState();
    }
}
