
function SceneListMainChatHistory(options) {

	this.options = options;
 
 	this.GIFLayer		= null;   
    this.list			= null;
	this.ListHelpBar	= null;

	//flags
	this.Status			= ENUM_SCENE_STATUS.INITIALIZED;
	this.SetFocus		= false;	
	this.IsShownObj		= false;
	
	this.Timer	= null;
	
	this.WheelOperation = false;	

}

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

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

	this.ShowLoading();	

	this.Timer = setTimeout("ShowObj()", 300);	

	ShowObj = function(){
	
		This_ = sf.scene.get("ListMainChatHistory");
		
		This_.ShowObj();
		This_.HideLoading();
		This_.FocusObj();
				
	}

}

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

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

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

SceneListMainChatHistory.prototype.handleFocus = function () {
			
	if(this.IsShownObj){
		
		alert("SceneListMainChatHistory.handleFocus()");
		this.ListHelpBar.visibleObj();
		this.list.highlight();
	}
		
	this.SetFocus = true;	
	

}

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

	this.list.blur();

	this.ListHelpBar.hiddenObj();	
	
	this.SetFocus = false;
}

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

}

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

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

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

	this.ListHelpBar = new HelpBar(HelpBarIndex.LIST_MAIN_CHAT_HISTORY_PAGE, "ListMain");

	var this_ = sf.scene.get('ListMainChatHistory');
    this.ListHelpBar.SetOnClickCallbackFunc(1, function(){this_.processRedKey();});
    this.ListHelpBar.SetOnClickCallbackFunc(2, function(){this_.processToolKey();});
    this.ListHelpBar.SetOnClickCallbackFunc(3, function(){this_.processReturnKey();});

	this.Status = ENUM_SCENE_STATUS.CREATED;

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

}

SceneListMainChatHistory.prototype.createLoading = function(){

	this.GIFLayer = new JPGImageLayer("Chat_loading_gif");
	this.GIFLayer.SetImage(WndMgr.Bg_LoadingGIF.src); 
 
}

SceneListMainChatHistory.prototype.Refresh = function(){

	if(this.Status == ENUM_SCENE_STATUS.ACTIVATED && this.IsShownObj == true){
				
		this.list.Refresh();
	} 

}

SceneListMainChatHistory.prototype.setDestroyFlag= function(destroy_flag){

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

SceneListMainChatHistory.prototype.CheckValidList = function(){
	
	if( this.list.GetTotalDataNum() > 0){
		return true;
	}
	else {
		return false;
	}
}

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

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

SceneListMainChatHistory.prototype.ShowLoading = function(){
	
	$("#"+ this.GIFLayer.Obj).css('display', 'block');
}

SceneListMainChatHistory.prototype.HideLoading = function(){
	
	$("#"+ this.GIFLayer.Obj).css('display', 'none');
}

SceneListMainChatHistory.prototype.ShowObj = function(){
	
	if(this.Status == ENUM_SCENE_STATUS.INITIALIZED){					
		this.create();
	}						

	if(this.Status == ENUM_SCENE_STATUS.CREATED || this.Status == ENUM_SCENE_STATUS.DESTORYED){		

		this.list.Initialize();	
		this.Status = ENUM_SCENE_STATUS.ACTIVATED;
	}
	else{
		this.Activation();
	}
	
	this.list.Show();
	
	this.IsShownObj = true;
	
}

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

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


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


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

SceneListMainChatHistory.prototype.processToolKey=function()
{
    alert("SceneListMainChatHistory.processToolKey() ");
	
	var IsInCall = ProcMgr.GetIsInCall();
	
	if(IsInCall){
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL_IN_CHAT_LIST);
	}
	else{

		StateMgr.Start_List_Tools_State(TOOL_MENU_LIST_TYPE.CHAT_LIST);	
	}	
}

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