
var HISTORY_LIST_VM_STATUS = { 

	NOTHING			:	0,
	START_PALYBACK	:	1	
}

function SceneListMainHistory(options) {

	this.options = options;
	
    this.GIFLayer		= null;
	this.list			= null;
	// this.ListHelpBar	= null;
	// this.PlayVMHelpBar	= null;
	
	//flags	
	this.Status				= ENUM_SCENE_STATUS.INITIALIZED;
	this.SetFocus			= false;	
	this.IsShownObj			= false;
	this.VMStatus			= HISTORY_LIST_VM_STATUS.NOTHING;
	this.IsShownVolumWindow = false;
	this.IsJumpState		= false;
	this.JumpIndex			= 0;
	this.IsPlayRightNowVM	= false;
	
	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;
    
}

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

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

	if(this.Status > ENUM_SCENE_STATUS.CREATED)
		this.list.NotifingLabel.Hide();
	this.ShowLoading();	

	this.Timer = setTimeout("ShowObj()", 1000);
	
	ShowObj = function(){
	
		This_ = sf.scene.get("ListMainHistory");
		
		This_.ShowObj();
		This_.HideLoading();
		This_.FocusObj();
		This_.ProcessObj()
	}
}

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

    clearTimeout( this.Timer);
    this.Timer=null;	
		
	if(this.IsShownObj){
		
		this.list.Hide();	
		this.ResetVM();
		this.IsShownObj = false;
		this.Status = ENUM_SCENE_STATUS.DISAPPEARED;
	}
		
}

SceneListMainHistory.prototype.handleFocus = function () {

	this.SetFocus = true;
	if(this.IsShownObj){
		alert("SceneListMainHistory.handleFocus()");

		if(this.VMStatus == HISTORY_LIST_VM_STATUS.START_PALYBACK){
		
			// this.PlayVMHelpBar.visibleObj();
		}
		else{
			
			// this.ListHelpBar.visibleObj();	
		}
				
		this.list.highlight();
	}
	
	this.IsShownVolumWindow = false;
	HelpBar.changeHelpBarItems(this.HelpBarData);	


}

SceneListMainHistory.prototype.handleBlur = function () {	
	alert("SceneListMainHistory.handleBlur()");
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	
	this.list.blur();
	
	if(this.VMStatus == HISTORY_LIST_VM_STATUS.START_PALYBACK){
	
		if(this.IsShownVolumWindow == false)
		{
			ProcMgr.StopHistoryVoicemail(this.list.GetCurIndex());
		}
	}
	
	this.SetFocus = false;
}

SceneListMainHistory.prototype.handleKeyDown = function (keyCode) {
	
	alert("SceneListMainHistory.handleKeyDown(" + keyCode + ")");
	PluginAPIMgr.PlayAudio(keyCode);
	//TEMPCODE:
	if(this.IsShownObj == false){
		return;
	}
	
	if(this.VMStatus == HISTORY_LIST_VM_STATUS.NOTHING)
	{
		switch(keyCode) {
			
			case sf.key.RED:
                StateMgr.Start_Signout_State();
				break;
	
			default:
				this.list.KeyProcess(keyCode);					
				break;					
		}			
	}
	else
	{
		switch(keyCode) 
		{
			case sf.key.RED:
	            StateMgr.Start_Signout_State();
				break;

			case sf.key.PANEL_VOL_UP:
			case sf.key.PANEL_VOL_DOWN:
			case sf.key.VOL_UP:
			case sf.key.VOL_DOWN:
				this.processVolumeKey();	
				break;

			case sf.key.LEFT:
			case sf.key.RIGHT:
			case sf.key.ENTER:
				this.list.KeyProcess(keyCode);					
				break;					

			case sf.key.UP:
			case sf.key.DOWN:
				if((this.list.GetCurIndex() == 0 && keyCode == sf.key.DOWN) || (this.list.GetCurIndex() == this.list.GetTotalDataNum()-1 && keyCode == sf.key.UP)) {
					ProcMgr.StopHistoryVoicemail(this.list.GetCurIndex());	
					this.list.KeyProcess(keyCode);					
				}
				break;					

			case sf.key.RETURN:
			case sf.key.EXIT:
				ProcMgr.StopHistoryVoicemail(this.list.GetCurIndex());	
				this.list.KeyProcess(keyCode);					
				break;					

			default:
				sf.key.preventDefault();
				break;					
		}
	}
}





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

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

	this.list = new HistoryList();	
    this.list.Create();
	//help bar
	this.HelpBarData = {
		'red': IDWS_MOIP_POPUP_EXIT_SIGN_OUT,
		'tools':SID_TOOLS,
		'return' : SID_RETURN
	}
	
	
	/*this.ListHelpBar = new HelpBar(HelpBarIndex.LIST_MAIN_HISTORY_PAGE, "ListMain");
	this.PlayVMHelpBar = new HelpBar(HelpBarIndex.LIST_MAIN_HISTORY_VMPLAY, "ListMain");
*/
	var this_ = sf.scene.get('ListMainHistory');
   /* this.ListHelpBar.SetOnClickCallbackFunc(1, function(){this_.processRedKey();});
    this.ListHelpBar.SetOnClickCallbackFunc(2, function(){this_.processToolKey();});
    this.ListHelpBar.SetOnClickCallbackFunc(3, function(){this_.processReturnKey();});


    this.PlayVMHelpBar.SetOnClickCallbackFunc(1, function(){this_.processStopKey();});*/

	this.Status = ENUM_SCENE_STATUS.CREATED;

    this.TempDiv = document.getElementById("ListMainHistory");
   	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);
			}
	    }		
    };		

}

SceneListMainHistory.prototype.Refresh = function(){

	alert("SceneListMainHistory.Refresh");
	
	if(this.IsShownObj)
	{
		alert("shown state");
		if(this.Status == ENUM_SCENE_STATUS.ACTIVATED && this.VMStatus == HISTORY_LIST_VM_STATUS.NOTHING)
		{
			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();
			}
		}
	} 
}

SceneListMainHistory.prototype.setDestroyFlag= function(destroy_flag){

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

SceneListMainHistory.prototype.ProcessVM= function(EventType){
	
	if(this.VMStatus == HISTORY_LIST_VM_STATUS.START_PALYBACK){
		this.list.ProcessVM(EventType);		
	}
		
	switch(EventType) {
		
		case ENUM_VOICE_MAIL_STATUS.UNPLAYED:			
		case ENUM_VOICE_MAIL_STATUS.PLAYED:
		case ENUM_VOICE_MAIL_STATUS.UPLOADED:
		case ENUM_VOICE_MAIL_STATUS.FAILED:		
			this.CloseVolumeWnd();
			break;
	}
	
}

SceneListMainHistory.prototype.ResetVM = function(){
		
	if(this.VMStatus == HISTORY_LIST_VM_STATUS.START_PALYBACK){
		this.list.ProcessVM(ENUM_VOICE_MAIL_STATUS.PLAYED);		
	}
	
	this.CloseVolumeWnd();
}

SceneListMainHistory.prototype.CloseVolumeWnd = function(){
		
	if(this.IsShownVolumWindow){

		StateMgr.Stop_Volume_Speaker_State(true);
		this.IsShownVolumWindow = false;		
	}
	
}


SceneListMainHistory.prototype.StartVMPlay = function(){
	
	this.VMStatus = HISTORY_LIST_VM_STATUS.START_PALYBACK;
	ProcMgr.registerCallKey();

	
	// this.ListHelpBar.hiddenObj();
	// this.PlayVMHelpBar.visibleObj();
	
	g_Data.SetIndexOfPlayingVoicemail(this.list.GetCurIndex());	

}

SceneListMainHistory.prototype.StopVMPlay = function(){

	this.VMStatus = HISTORY_LIST_VM_STATUS.NOTHING;
	ProcMgr.unregisterCallKey();
	
	// this.PlayVMHelpBar.hiddenObj();
	// this.ListHelpBar.visibleObj();
	
	g_Data.SetIndexOfPlayingVoicemail(-1);
}

SceneListMainHistory.prototype.VMProgressPlayback = function(strTime){
	
	if(this.VMStatus == HISTORY_LIST_VM_STATUS.START_PALYBACK){
		this.list.VMProgressPlayback(strTime);
	}

}

SceneListMainHistory.prototype.CheckValidList = function(){
	
	var totalDataNum = parseInt(PluginAPIMgr.GetNumberOfHistorys());

	if( totalDataNum > 0){
		return true;
	}
	else {
		return false;
	}
}

SceneListMainHistory.prototype.GetState = function(){
	
	return this.Status;
}

SceneListMainHistory.prototype.SetState = function(ValueOfStatus){
	
	this.Status = ValueOfStatus;
}

SceneListMainHistory.prototype.Activation = function(){
	alert("SceneListMainHistory.Activation() : Status = "+this.Status);	
	
	if(this.Status > ENUM_SCENE_STATUS.CREATED){
		
		this.Status = ENUM_SCENE_STATUS.ACTIVATED;
		this.list.Refresh();			
	}
}

//TEMPCODE:
SceneListMainHistory.prototype.ActivationForIdentity = function(){
	alert("SceneListMainHistory.ActivationForIdentity()");	
	
	if(this.Status > ENUM_SCENE_STATUS.CREATED){
		
		this.Status = ENUM_SCENE_STATUS.ACTIVATED;
		this.list.RefreshForCurIdentity();			
	}
}


SceneListMainHistory.prototype.Deactivation = function(){
	alert("SceneListMainHistory.Deactivation()");	
	
	this.Status = ENUM_SCENE_STATUS.DEACTIVATED;
}

SceneListMainHistory.prototype.createLoading = function(){

	// this.GIFLayer = new JPGImageLayer("History_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("history_loading_animation", null);
    this.LoadingAni.SetBgImage(this.LoadingAniImage[this.iCurrAniImage]);
    this.LoadingMsg = new Label(null,"history_loading_message");
    this.LoadingMsg.SetText(SID_LOADING_3DOT_KR_DIF);
}
SceneListMainHistory.prototype.ShowLoading = function(){
	
	alert("SceneListMainHistory.ShowLoading()");

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

SceneListMainHistory.prototype.HideLoading = function(){
	
	alert("SceneListMainHistory.HideLoading()");

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

SceneListMainHistory.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]);
	
}
SceneListMainHistory.prototype.ShowObj = function(){
	alert("SceneListMainHistory.ShowObj()");
	if(this.Status == ENUM_SCENE_STATUS.INITIALIZED){					
		this.create();
	}						
	
	//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
	{
		//show new list
		if(this.Status == ENUM_SCENE_STATUS.CREATED || this.Status == ENUM_SCENE_STATUS.DESTORYED)
		{	
			this.list.Initialize();	
			this.Status = ENUM_SCENE_STATUS.ACTIVATED;
		}
		//normal... reflesh
		else
		{
			this.Activation();
		}
	}
		
	this.list.Show();
	if(this.list.GetNoItem() == true)
		this.list.NotifingLabel.Show();
	
	this.IsShownObj = true;
	
}

SceneListMainHistory.prototype.FocusObj = function(){
	
	//check focus
	if(this.SetFocus){
		alert("SceneListMainHistory.FocusObj()");
		this.list.highlight();			
	}	
}

SceneListMainHistory.prototype.GetIsShownObj = function(){
	
	return this.IsShownObj;
}

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

SceneListMainHistory.prototype.processVolumeKey = function(){
	
	this.IsShownVolumWindow = true;
	StateMgr.Start_Volume_Speaker_State();
}

SceneListMainHistory.prototype.MoveToVideoCallBtn = function(){
	
	this.list.MoveToVideoCallBtn();	
}

//move to main ... 
SceneListMainHistory.prototype.processReturnKey = function(){
	
	this.list.MoveToMain();	
}

SceneListMainHistory.prototype.processRedKey = function(){
    alert("SceneListMainHistory.processRedKey() ");
    
    StateMgr.Start_Signout_State();   
}

SceneListMainHistory.prototype.processToolKey=function()
{
    alert("SceneListMainHistory.processToolKey() ");
	
	var IsInCall = ProcMgr.GetIsInCall();
	
	if (IsInCall) {
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL_IN_HISTORY_LIST);
	}
	else {
		StateMgr.Start_List_Tools_State(TOOL_MENU_LIST_TYPE.HISTORY_LIST);
	}
}

SceneListMainHistory.prototype.processStopKey = function(){
	
	this.list.ProgressStopkey();	
}

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

SceneListMainHistory.prototype.RefreshForIndex = function(Index) {

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


SceneListMainHistory.prototype.ProcessObj = function()
{
	if(this.IsPlayRightNowVM == false)
	{
		return;
	}
    alert("SceneListMainHistory.enterPlaybtn() ");	
    	
	this.list.KeyProcess(sf.key.ENTER);
	this.IsPlayRightNowVM = false;
}


SceneListMainHistory.prototype.enterPlaybtn = function()
{
    this.IsPlayRightNowVM = true;
}

