/*
 * To do in this scene
 * 1. list control.
 *
 */

function SceneListMainContact(options) {

	this.options = options;

	//object
	this.GIFLayer = null;
	this.list =undefined;
	// this.ContactListHelpBar		= null;

	//flags
	this.Status = ENUM_SCENE_STATUS.INITIALIZED;
	this.LiveCallMode = false;
	this.SetFocus = false;
	this.IsShownObj = false;
	
	this.IsJumpState		= false;
	this.JumpIndex			= 0;

	this.Timer = null;

	this.WheelOperation = false;

	//2013 add by minseok
	this.HelpBarData = null;
	
	
    //add 10.4
    this.LoadingAni = null;
    this.LoadingMsg=null;
    this.FlagAnimation = false;
    this.LoadingAniImage = new Array(18);
    this.iCurrAniImage =0;
    
    this.LoadingAniImagePath = null;
    this.WidgetLoadingTimer = null;
    

}

SceneListMainContact.prototype.initialize = function() {
	alert("SceneListMainContact.initialize()");
	this.createLoading();
	
}

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

	//TEMPCODE : only one to function call 'GetIsCall'
	if(this.Status > ENUM_SCENE_STATUS.CREATED)
		this.list.NotifingLabel.Hide();
	this.ShowLoading();
  
	this.Timer = setTimeout("ShowObj()", 1000);
	ShowObj = function() {
		This_ = sf.scene.get("ListMainContact");
		
		This_.ShowObj();
		This_.HideLoading();
		This_.FocusObj();
	}
}

SceneListMainContact.prototype.handleHide = function() {
	alert("SceneListMainContact.handleHide()");

	clearTimeout(this.Timer);
	this.Timer = null;

	if(this.IsShownObj) {

		this.list.Hide();
		this.IsShownObj = false;
		this.Status = ENUM_SCENE_STATUS.DISAPPEARED;
	}

}

SceneListMainContact.prototype.handleFocus = function() {

	//TEMPCODE:
	//set focus when popup was shown...
	this.SetFocus = true;
	if(this.IsShownObj) {
		alert("SceneListMainContact.handleFocus()");
		// this.ContactListHelpBar.visibleObj();
		
		if(this.list==undefined || this.list.GetTotalDataNum()<=0){
			this.processReturnKey();
		}else{
		this.list.highlight();
	}
	}
	HelpBar.changeHelpBarItems(this.HelpBarData);
}

SceneListMainContact.prototype.handleBlur = function() {
	alert("SceneListMainContact.handleBlur()");

	if(this.IsShownObj) {
	this.list.blur();
	}
	
	//TEMPCODE: must not disappear when showing popup wnd.
	// this.ContactListHelpBar.hiddenObj();
	this.SetFocus = false;
}

SceneListMainContact.prototype.handleKeyDown = function(keyCode) {

	alert("SceneListMainContact.handleKeyDown(" + keyCode + ")");
	PluginAPIMgr.PlayAudio(keyCode);
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}

	switch(keyCode) {

		case sf.key.RED:
			StateMgr.Start_Signout_State();
			break;

		case sf.key.YELLOW:
			this.processYellowKey();
			break;
		default:
				this.list.KeyProcess(keyCode);
			break;
	}

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////

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

	this.list = new ContactList();
	this.list.Create();

	// this.ContactListHelpBar = new HelpBar(HelpBarIndex.LIST_MAIN_CONTACT_PAGE, "ListMain");

	var this_ = sf.scene.get('ListMainContact');
	/*this.ContactListHelpBar.SetOnClickCallbackFunc(1, function(){this_.processRedKey();});
	 this.ContactListHelpBar.SetOnClickCallbackFunc(2, function(){this_.processYellowKey();});
	 this.ContactListHelpBar.SetOnClickCallbackFunc(3, function(){this_.processToolKey();});
	 this.ContactListHelpBar.SetOnClickCallbackFunc(4, function(){this_.processReturnKey();});*/

	this.Status = ENUM_SCENE_STATUS.CREATED;

	this.HelpBarData = {
		'red' : IDWS_MOIP_POPUP_EXIT_SIGN_OUT,
		'yellow' : IDWS_MOIP_SKYPE_ADD_A_CONTACT,
		'tools' : SID_TOOLS,
		'return' : SID_RETURN
	};

	this.TempDiv = document.getElementById("ListMainContact");
	this.TempDiv.onmousewheel = function() {
		if(this_.WheelOperation == false) {
			alert("SceneListMainContact.onmousewheel");
			this_.WheelOperation = true;
			PluginAPIMgr.StartOSDTimer("700", function() {
				this_.timerCallback();
			}, ENUM_TIMER_TYPE.POPUP_WND);

			if(event.wheelDelta > 0) {
				//alert("Up Up");
				this_.list.PageScroll(true);
			} else {
				//alert("Down Down");
				this_.list.PageScroll(false);
			}
		}
	};
}


//to refresh in current page
SceneListMainContact.prototype.Refresh = function() {

	if(this.Status == ENUM_SCENE_STATUS.ACTIVATED && this.IsShownObj == true) {
		if(this.IsJumpState == true)
		{
			alert("IsJumpState is true");
			//show new list
			this.list.RefreshForJumpIndex(this.JumpIndex);
			//reset flags
			this.IsJumpState = false;
			this.JumpIndex = 0;
		}
		else
		{
			alert("IsJumpState is false");
			this.list.Refresh();
		}	
	}

}

SceneListMainContact.prototype.setDestroyFlag = function(destroy_flag) {

	if(destroy_flag) {
		this.Status = ENUM_SCENE_STATUS.DESTORYED;
	}

}

SceneListMainContact.prototype.CheckValidList = function() {

	if(this.list.GetTotalDataNum() > 0) {
		return true;
	} else {
		return false;
	}
}
//Initializ list
SceneListMainContact.prototype.InitializeScene = function() {

	this.list.Initialize();
	this.Status = ENUM_SCENE_STATUS.ACTIVATED;
	this.LiveCallMode = ProcMgr.GetIsInCall();

}

SceneListMainContact.prototype.GetState = function() {

	return this.Status;
}

SceneListMainContact.prototype.Activation = function() {
	alert("SceneListMainContact.Activation()");

	if(this.Status > ENUM_SCENE_STATUS.CREATED) {

		this.Status = ENUM_SCENE_STATUS.ACTIVATED;
		this.list.Refresh();
	}

}

SceneListMainContact.prototype.Deactivation = function() {
	alert("SceneListMainContact.Deactivation()");

	this.Status = ENUM_SCENE_STATUS.DEACTIVATED;
}

SceneListMainContact.prototype.ProgressCallDuration = function(strTime) {

	if(this.IsShownObj && this.LiveCallMode) {
		this.list.ProgressCallDuration(strTime);
	}

}
SceneListMainContact.prototype.createLoading = function() {

	// this.GIFLayer = new JPGImageLayer("Contact_loading_gif");
	// this.GIFLayer.SetImage(WndMgr.Bg_LoadingGIF.src);
	var ResStr = sf.env.getResolution();
   	this.LoadingAniImagePath = "images/"+ResStr+"/loading/loading_64/";
   	alert("SceneWidgetLoading.create() : loadinganiImagePath"+this.LoadingAniImagePath);
    
    
    var a=0;
    for (a=0; a < this.LoadingAniImage.length; a++)
    {
        var b = (a+1);
        if(b<10)
        {
            this.LoadingAniImage[a] = this.LoadingAniImagePath +"loading_64_"+"0"+b+".png";
        }
        else
        {
            this.LoadingAniImage[a] = this.LoadingAniImagePath +"loading_64_"+b+".png";
        }
    }
 	this.LoadingAni= new Label("contact_loading_animation", null);
    this.LoadingAni.SetBgImage(this.LoadingAniImage[this.iCurrAniImage]);
    this.LoadingMsg = new Label(null,"contact_loading_message");
    this.LoadingMsg.SetText(SID_LOADING_3DOT_KR_DIF);
}

SceneListMainContact.prototype.ShowLoading = function() {

	alert("SceneListMainContact.ShowLoading()");

	this.LoadingAni.visibleObj();
	this.LoadingMsg.visibleObj();
	var scene = sf.scene.get('ListMainContact');
    this.WidgetLoadingTimer=setInterval("timerCF()", 100);
    timerCF = function() {  scene.loadingTimerCallback();}
}

SceneListMainContact.prototype.HideLoading = function() {

	alert("SceneListMainContact.HideLoading()");

	clearInterval( this.WidgetLoadingTimer);
    this.WidgetLoadingTimer=null;
    this.iCurrAniImage =0;
    this.LoadingAni.hiddenObj();
    this.LoadingMsg.hiddenObj();
}

SceneListMainContact.prototype.loadingTimerCallback= function()
{
     this.iCurrAniImage++;
     
    if(this.iCurrAniImage >= this.LoadingAniImage.length)
    {
        this.iCurrAniImage = 0;
    }   
    
    this.LoadingAni.SetBgImage(this.LoadingAniImage[this.iCurrAniImage]);
    // this.WidgetLoadingView.popup.SetLoadingBG(this.LoadingAniImage[this.iCurrAniImage]);
}
SceneListMainContact.prototype.ShowObj = function() {

	alert("SceneListMainContact.ShowObj()");
	if(this.Status == ENUM_SCENE_STATUS.INITIALIZED) {
		this.create();
	}

	var IsInCall = ProcMgr.GetIsInCall();
	
		//when jump..
	if(this.IsJumpState == true)
	{					
		//show new list
		if(this.Status == ENUM_SCENE_STATUS.CREATED || this.Status == ENUM_SCENE_STATUS.DESTORYED)
		{
			this.list.InitializeForJump(this.JumpIndex);
		}
		else
		{
			this.list.RefreshForJumpIndex(this.JumpIndex);
		}

		this.Status = ENUM_SCENE_STATUS.ACTIVATED;
		//reset flags
		this.IsJumpState = false;
		this.JumpIndex = 0;
	}
	else
	{
		if(this.Status == ENUM_SCENE_STATUS.CREATED || this.Status == ENUM_SCENE_STATUS.DESTORYED || this.LiveCallMode != IsInCall) {
		this.list.Initialize();

		this.Status = ENUM_SCENE_STATUS.ACTIVATED;
		this.LiveCallMode = IsInCall;
		
		} else {
			this.Activation();
		}
	}

	this.list.Show();
	if(this.list.GetNoItem() == true)
		this.list.NotifingLabel.Show();

	this.IsShownObj = true;

}

SceneListMainContact.prototype.FocusObj = function() {

	//check focus
	if(this.SetFocus) {
		alert("SceneListMainContact.FocusObj()");
		this.list.highlight();
	}
}

SceneListMainContact.prototype.GetIsShownObj = function() {

	return this.IsShownObj;
}

SceneListMainContact.prototype.SetJumpState = function(jump_index){
	alert("SceneListMainContact.SetJumpState( "+jump_index+" )");
		
	if(jump_index < 0)
	{
		return;
	}
	else
	{
		this.IsJumpState = true;
		this.JumpIndex = jump_index;
	}
}

SceneListMainContact.prototype.MoveToVideoCallBtn = function() {

	this.list.MoveToVideoCallBtn();
}

SceneListMainContact.prototype.RefreshForIndex = function(Index) {

	this.Status = ENUM_SCENE_STATUS.ACTIVATED;
	this.list.RefreshForIndex(Index);
}

//move to main ...
SceneListMainContact.prototype.processReturnKey = function() {

	this.list.MoveToMain();
}

SceneListMainContact.prototype.processYellowKey = function() {
	alert("SceneListMainContact.processYellowKey() ");

	var IsInCall = ProcMgr.GetIsInCall();

	if(IsInCall) {
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL);
	} else {
		StateMgr.Start_Add_Contact_State();
	}
}

SceneListMainContact.prototype.processRedKey = function() {
	alert("SceneListMainContact.processRedKey() ");

	StateMgr.Start_Signout_State();
}

SceneListMainContact.prototype.processToolKey = function() {
	alert("SceneListMainContact.processToolKey() ");

	var IsInCall = ProcMgr.GetIsInCall();

	if(IsInCall) {
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL_IN_CONTACT_LIST);
	} else {

		StateMgr.Start_List_Tools_State(TOOL_MENU_LIST_TYPE.CONTACT_LIST);
	}
}

SceneListMainContact.prototype.timerCallback = function() {
	this.WheelOperation = false;
}