
function SceneChat(options) {
	this.options = options;
	
	this.ChatView=null;
	
	this.ChatMsgBox = null;
	
	this.SendMsgBtn = null;
	
	this.CallEndBtn=null;
	this.VideoCallBtn=null;
	this.CallBtn=null;
	
	this.CallStatusLabel=null;
	
	this.ChatMsg="";
	
	 this.HelpBar =null;
	 this.ScrollHelpBar =null;
	 
	 this.ScrollBg=null;
	 this.ScrollTop=null;
	 this.ScrollCenter=null;
	 this.ScrollUnder=null;
	 
	 this.InitFlag = true;
	 
	 this.ChatTitle = null;
	 this.ChatTitleText  ="";
	 
	 this.ChatNumberTitle = null;
	 this.ChatNumberTitleText  ="";
	 this.ChatMemberTitle = null;
	 
	 this.flagMultiChatMode = false;
	 this.flagCallingMode = false;
	 
	 this.TotalChatMsg = 0;
	 this.CurrStartMsg = 0;
	 this.CurrEndMsg = 0;
	 
	 this.ChatMember ="";
	 this.NumOfChatMember =0;
	 
	 this.TopArrow = null;
	 this.BottomArrow = null;
}

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

SceneChat.prototype.handleShow = function () {
	alert("SceneChat.handleShow()");
	// this function will be called when the scene manager show this scene 
}

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

SceneChat.prototype.handleFocus = function () {
	alert("SceneChat.handleFocus()");
	// this function will be called when the scene manager focus this scene
	this.update();
	
	var currentHighlight =  this.ChatView.getCurrentHighlight();
	if(currentHighlight==null)
	{
		if(this.SendMsgBtn.GetFlagDim()== false)
		{
			this.highlight(this.SendMsgBtn);
		}
		else
		{
			if(this.flagCallingMode)
			{
				this.highlight(this.CallEndBtn);
			}
			else
			{
				this.highlight(this.CallBtn);
			}
		}
		
	}
	else
	{
		this.highlight(currentHighlight);
	}    
}

SceneChat.prototype.handleBlur = function () {
	alert("SceneChat.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
    
    var currentHighlight =  this.ChatView.getCurrentHighlight();
    if(currentHighlight !=null)
    {
        currentHighlight.blur();
    }
}

SceneChat.prototype.handleKeyDown = function (keyCode) {
	alert("SceneChat.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:
            this.processUpKey();
			break;
		case sf.key.DOWN:
            this.processDownKey();
			break;

		case sf.key.ENTER:
            this.processEnterKey();
			break;
            
        case sf.key.RED:
            
			break;

		case sf.key.BLUE:
			this.processBlueKey();
			break;			
			            
        case sf.key.RETURN:
           this.processReturnKey();
			sf.key.preventDefault();
            break;
        
        case sf.key.EXIT:
            this.processExitKey();
			sf.key.preventDefault();
			break;
            
         case 147:  //infolink
         case 261:  //contents
         case 115:  //wiselink
            ProcMgr.processInfolinkKey();
			break;
            
          default:
            ProcMgr.processBlockKey(keyCode);
            break;  

	}
}

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

SceneChat.prototype.create = function(){
    alert("SceneChat.create()");
    this.ChatView = new View("Chat");
    this.ChatView.SetBgImage(g_Image.IMAGE_CHAT_BG);
    
    this.ChatTitle = new Label(null,"chat_title");
    //this.ChatTitle.SetTextStyle("chat_title_style");
    this.ChatTitle.SetMarqueeEnable(700, "chat_title_marquee_style" ,"chat_title_style");
	
	this.ChatNumberTitle = new Label(null,"chat_join_number_title");
    this.ChatNumberTitle.SetTextStyle("chat_join_number_title_style");
	
	this.ChatMemberTitle = new Label(null,"chat_join_member_title");
    //this.ChatMemberTitle.SetTextStyle("chat_join_member_title_style");
    this.ChatMemberTitle.SetReverseDisable(true);
    this.ChatMemberTitle.SetMarqueeEnable(700, "chat_join_member_title_marquee_style" ,"chat_join_member_title_style");
    
    var this_ = sf.scene.get("Chat");
    
    this.ChatMsgBox= new ChatMsgBox("Chat", false);
    this.ChatMsgBox.setOnCompleteFunc(function(){this_.updateScrollBar()});
    
    var clickCF =  function(obj){this_.processClickEvent(obj);};
    
    this.SendMsgBtn= new Button();
    this.SendMsgBtn.SetImageObjId("chat_send_message_btn");
    this.SendMsgBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CHAT_SEND_MSG_BTN_NORMAL);
    this.SendMsgBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CHAT_SEND_MSG_BTN_NORMALFOCUS);
    this.SendMsgBtn.SetTextObjId("chat_send_message_btn_text");
    this.SendMsgBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
    this.SendMsgBtn.SetText(TV_SID_SEND_MESSAGE);
    this.SendMsgBtn.SetOnClickCallbackFunc(clickCF);
	
	this.CallEndBtn = new Button();
    this.CallEndBtn.SetImageObjId("chat_call_end_btn");
    this.CallEndBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CHAT_CALL_END_BTN_NORMAL);
    this.CallEndBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CHAT_CALL_END_BTN_NORMALFOCUS);	
    this.CallEndBtn.SetTextObjId("chat_call_end_btn_text");
    this.CallEndBtn.SetText(TV_SID_END_CALL);
    this.CallEndBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
	this.CallEndBtn.SetOnClickCallbackFunc(clickCF);
	
    this.VideoCallBtn = new Button();
    this.VideoCallBtn.SetImageObjId("chat_video_call_btn");
    this.VideoCallBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CHAT_CALL_BTN_NORMAL);
    this.VideoCallBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CHAT_CALL_BTN_NORMALFOCUS);
	this.VideoCallBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_CHAT_CALL_BTN_DIM);	
    this.VideoCallBtn.SetTextObjId("chat_video_call_btn_text");
    this.VideoCallBtn.SetText(IDWS_MOIP_VIDEO_CALL);
    this.VideoCallBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
    this.VideoCallBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"common_btn_text_f17_dim_style");
	this.VideoCallBtn.SetOnClickCallbackFunc(clickCF);
	
    this.CallBtn = new Button();
    this.CallBtn.SetImageObjId("chat_call_btn");
    this.CallBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CHAT_CALL_BTN_NORMAL);
    this.CallBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CHAT_CALL_BTN_NORMALFOCUS);
	this.CallBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_CHAT_CALL_BTN_DIM);
    this.CallBtn.SetTextObjId("chat_call_btn_text");
    this.CallBtn.SetText(SID_CALL_KR_CALL);
    this.CallBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f17_normal_style");
    this.CallBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"common_btn_text_f17_dim_style");
	this.CallBtn.SetOnClickCallbackFunc(clickCF);
	
	this.CallStatusLabel = new Label("chat_call_status", null);
	this.CallStatusLabel.SetBgImage(g_Image.IMAGE_CHAT_CALL_STATUS_BG);
    
    this.ScrollBg= new Label("chat_scroll_bg", null);
    this.ScrollBg.SetBgImage(g_Image.IMAGE_CHAT_SCROLL_BG);
    
    this.ScrollTop= new Label("chat_scroll_top", null);
    this.ScrollTop.SetBgImage(g_Image.IMAGE_CHAT_SCROLL_TOP);
    
    this.ScrollUnder= new Label("chat_scroll_under", null);
    this.ScrollUnder.SetBgImage(g_Image.IMAGE_CHAT_SCROLL_UNDER);
    
    this.ScrollCenter= new Label("chat_scroll_center", null);
    this.ScrollCenter.SetBgImage(g_Image.IMAGE_CHAT_SCROLL_CENTER);
    
    this.HelpBar = new HelpBar(HelpBarIndex.CHAT, "Chat");
    this.HelpBar.SetOnClickCallbackFunc(1, function(){this_.processBlueKey();});
    this.HelpBar.SetOnClickCallbackFunc(2, function(){this_.processReturnKey();});
    
    this.ScrollHelpBar = new HelpBar(HelpBarIndex.CHAT_SCROLL, "Chat");
    this.ScrollHelpBar.SetOnClickCallbackFunc(1, function(){this_.processBlueKey();});
    this.ScrollHelpBar.SetOnClickCallbackFunc(3, function(){this_.processReturnKey();});
    
    this.ChatView.registHelpBar( this.HelpBar);
    
    this.TopArrow= new Label("chat_top_arrow", null);
    this.TopArrow.SetBgImage(g_Image.IMAGE_CHAT_ALLOW_TOP_NOR);
    this.TopArrow.SetOnClickCallbackFunc(clickCF);
    this.TopArrow.SetOnMouseOutOverImage(g_Image.IMAGE_CHAT_ALLOW_TOP_NOR, g_Image.IMAGE_CHAT_ALLOW_TOP_OVER);

    this.BottomArrow= new Label("chat_bottom_arrow", null);
    this.BottomArrow.SetBgImage(g_Image.IMAGE_CHAT_ALLOW_BOTTOM_NOR);
    this.BottomArrow.SetOnClickCallbackFunc(clickCF);
    this.BottomArrow.SetOnMouseOutOverImage(g_Image.IMAGE_CHAT_ALLOW_BOTTOM_NOR, g_Image.IMAGE_CHAT_ALLOW_BOTTOM_OVER);  
}

SceneChat.prototype.setInitFlag= function(init_flag){
     this.InitFlag = init_flag;
}

SceneChat.prototype.init = function(){
	alert("SceneChat.init()");
	
	this.TotalChatMsg = 0;
	this.CurrStartMsg = 0;
	this.CurrEndMsg = 0; 
	
	this.ChatMember = "";
	this.NumOfChatMember =0;
	
	this.CallEndBtn.hiddenObj();
	this.VideoCallBtn.hiddenObj();
	this.CallBtn.hiddenObj();
	
	this.ChatMsgBox.initMsgBox();	
	
	this.highlight(null);
}

SceneChat.prototype.update = function(){
    alert("SceneChat.update()");
	
	this.updateChatTitle();
	this.updateCallBtn();
	this.toggleVideoCallBtnEnable();
   
    if(this.InitFlag ==true)
    {        
        this.InitFlag = false;
    }
}

SceneChat.prototype.updateCallBtn = function(){
    alert("SceneChat.updateCallBtn()" + this.flagCallingMode);
	var backup_callingMode = this.flagCallingMode;
	var backup_multiChatMode = this.flagMultiChatMode;
	
	this.flagCallingMode = ProcMgr.isCalling;
	
	if(this.NumOfChatMember>1)
	{
		this.flagMultiChatMode = true;
	}
	else
	{
		this.flagMultiChatMode = false;
	}
	
	if(this.InitFlag ==false && backup_callingMode == this.flagCallingMode && backup_multiChatMode== this.flagMultiChatMode)
	{
		return;
	}
	
	if(this.flagCallingMode==true)
	{
		this.CallEndBtn.visibleObj(); 
		this.VideoCallBtn.hiddenObj();
		this.CallBtn.hiddenObj();
	}
	else
	{	
		if(backup_callingMode != this.flagCallingMode || backup_multiChatMode != this.flagMultiChatMode)
		{
			this.highlight(null);
		}
		
		if(this.flagMultiChatMode==false)
		{			
			this.CallEndBtn.hiddenObj();
			this.VideoCallBtn.visibleObj();
			this.CallBtn.visibleObj();
		}
		else
		{
			this.CallEndBtn.hiddenObj();
			this.VideoCallBtn.hiddenObj();
			this.CallBtn.hiddenObj();
		}	
	}
}

SceneChat.prototype.toggleVideoCallBtnEnable=function()
{      
    var camera_state = PluginAPIMgr.GetCameraState();
    
    if(camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING)
    {
        alert("SceneChat.toggleVideoCallBtnEnable() Dim : true -> camera_state : "+ camera_state );
		if(this.flagCallingMode ==false && this.flagMultiChatMode==false )
		{
			var currentHighlight =  this.ChatView.getCurrentHighlight();
	        if(currentHighlight ==  this.VideoCallBtn)
	        {
	            if(this.VideoCallBtn.flag_highlight ==  true)
	            {
	                this.highlight(this.SendMsgBtn);
	            }
	            else
	            {
	                this.highlight(null);
	            }
	        }	        
	        this.VideoCallBtn.SetFlagDim(true);			
		}      
    }
    else
    {
        alert("SceneChat.toggleVideoCallBtnEnable() Dim :  false ");
		if(this.flagCallingMode==true)
		{
			if(PluginAPIMgr.IsInCall()==1)
			{
				PluginAPIMgr.StartRecord();
			} 
		}

		if (this.flagCallingMode == false && this.flagMultiChatMode == false) 
		{
			this.VideoCallBtn.SetFlagDim(false);
		}
    }    
}


SceneChat.prototype.updateMsgBox = function(){
    alert("SceneChat.updateMsgBox()");
    
	var numberOfMsg = PluginAPIMgr.GetNumOfMessages();
	var start_index =0;
	var end_index=0;
	
	if(numberOfMsg == 0 && this.TotalChatMsg==0)
	{
		this.hiddenScrollBar();
	}
	
	if(numberOfMsg > 0 )
	{
		if(this.TotalChatMsg < numberOfMsg)
		{
			if(this.TotalChatMsg==0)
			{
				this.CurrEndMsg = numberOfMsg-1;
				if(this.CurrEndMsg > 10)
				{
					this.CurrStartMsg = this.CurrEndMsg -9;
				}
				else
				{
					this.CurrStartMsg =0;
				}
				
				start_index = this.CurrStartMsg;
				end_index = this.CurrEndMsg;
			}
			else
			{
				start_index = this.CurrEndMsg+1;
				if((numberOfMsg - this.TotalChatMsg) >10)
				{
					this.CurrEndMsg = this.CurrEndMsg +9;
				}
				else
				{
					this.CurrEndMsg = this.CurrEndMsg +(numberOfMsg - this.TotalChatMsg);
				}
				
				end_index = this.CurrEndMsg;
				
			}
			
			this.TotalChatMsg = numberOfMsg;
			
			this.ChatMsg =  PluginAPIMgr.GetMessages(start_index , end_index);
    		this.ChatMsgBox.updateMsgBox(this.ChatMsg , false);
		}
	}	 
}

SceneChat.prototype.UpdateChatMemberInfo = function()
{
	 alert("SceneChat.UpdateChatMemberInfo()");
	this.ChatMsgBox.UpdateChatMemberInfo();
	this.updateChatTitle();
}

SceneChat.prototype.updateChatTitle = function()
{
	alert("SceneChat.updateChatTitle()");

	var curr_member =this.ChatMember;
	this.ChatMember = ProcMgr.GetCurrentChatMember();
	this.NumOfChatMember = ProcMgr.GetNumberOfChatMember();
	
	if(curr_member == this.ChatMember)
	{
		return;
	}
	else
	{
		if(this.NumOfChatMember ==1)
		{
			this.ChatTitleText = g_Data.CombinateStrings(TV_SID_MIX_CHATTING_WITH, this.ChatMember);
			this.ChatTitle.SetText(this.ChatTitleText);
						
			this.ChatTitle.visibleObj();
			this.ChatNumberTitle.hiddenObj();
			this.ChatMemberTitle.hiddenObj();
		}
		else
		{
			this.ChatNumberTitleText = g_Data.CombinateStrings(TV_SID_MIX_PEOPLE_JOINED_IN_CHATTING, this.NumOfChatMember+1);
			this.ChatNumberTitle.SetText(this.ChatNumberTitleText);
			this.ChatMemberTitle.SetText(this.ChatMember);
				
			this.ChatNumberTitle.visibleObj();
			this.ChatMemberTitle.visibleObj();
			this.ChatTitle.hiddenObj();
		}
		
		this.flagMultiChatMode = PluginAPIMgr.isMultiChat(); 
		this.updateCallBtn();
		if(this.flagCallingMode == false)
		{
			this.highlight(this.SendMsgBtn);	
		}		
	}	
}

SceneChat.prototype.updateMsgBoxForUpKey = function()
{
	var total_item = this.ChatMsgBox.getTotalMsgNum();
	var top_item= this.ChatMsgBox.getTopMsg();
		
	alert("SceneChat.updateMsgBoxForUpKey() -> total_item : "+ total_item +" top_item : "+top_item);
	
	if((total_item > 0) &&(top_item == 1))
	{
		if(this.CurrStartMsg > 0)
		{
			end_index = this.CurrStartMsg-1;
			
			if(this.CurrStartMsg >10)
			{
				this.CurrStartMsg = this.CurrStartMsg - 10;
			}
			else
			{
				this.CurrStartMsg = 0;
			}
			
			start_index = this.CurrStartMsg;
			
			this.ChatMsg =  PluginAPIMgr.GetMessages(start_index , end_index);
    		this.ChatMsgBox.updateMsgBox(this.ChatMsg, true);
		}
	}
}

SceneChat.prototype.updateMsgBoxForDownKey = function()
{
	var total_item = this.ChatMsgBox.getTotalMsgNum();
	var bottom_item= this.ChatMsgBox.getBottomMsg();   
	
	alert("SceneChat.updateMsgBoxForDownKey() -> total_item : "+ total_item +" bottom_item : "+bottom_item);
	
	if((total_item > 0) &&(total_item == bottom_item))
	{
		if(this.CurrEndMsg<this.TotalChatMsg-1)
		{
			start_index = this.CurrEndMsg+1;
			
			if((this.TotalChatMsg - this.CurrEndMsg) >10)
			{
				this.CurrEndMsg = this.CurrEndMsg +10;
			}
			else
			{
				this.CurrEndMsg = this.CurrEndMsg +( this.TotalChatMsg-(this.CurrEndMsg+1));
			}
			
			end_index = this.CurrEndMsg;
			
			this.ChatMsg =  PluginAPIMgr.GetMessages(start_index , end_index);
    		this.ChatMsgBox.updateMsgBox(this.ChatMsg, false);
		}
	}	
}

SceneChat.prototype.updateScrollBar = function(){
    
    var total_item = this.ChatMsgBox.getTotalMsgNum();
    var top_item= this.ChatMsgBox.getTopMsg();
    var bottom_item= this.ChatMsgBox.getBottomMsg();
    
    //var displayed_item = top_item-bottom_item+1;
	var displayed_item = bottom_item-top_item+1;
    
    var max_scroll_length = 341;
    var init_scroll_start_position = 95;
    var curr_scroll_start_position = init_scroll_start_position;
    var curr_scroll_length=0;
    
    this.hiddenScrollBar();
    
    if(total_item <=0)  //no item
    {
        this.hiddenScrollBar(); 
        this.ChatView.changeHelpBar( this.HelpBar);  
    }
    else
    {
        if(displayed_item == total_item)  // only one page
        {
            this.hiddenScrollBar();
            this.ChatView.changeHelpBar( this.HelpBar);  
        }
        else
        {
             //var upper_hidden_item = total_item - top_item;
             //var under_hidden_item = bottom_item-1;
			 
			 var upper_hidden_item =  top_item - 1;
             var under_hidden_item = total_item - bottom_item;
                
             var scroll_length = Math.floor((max_scroll_length *displayed_item)/total_item);
             var upper_hidden_length = Math.floor((max_scroll_length *upper_hidden_item)/total_item);
             var under_hidden_length = Math.floor((max_scroll_length *under_hidden_item)/total_item);
             
             if(scroll_length < 2)
             {
               upper_hidden_length =  Math.floor(( 2 *upper_hidden_length)/scroll_length);
               upper_hidden_length =  Math.floor(( 2 *under_hidden_length)/scroll_length);
               scroll_length =2; 
             }             
			 
             var extra_length =max_scroll_length - (scroll_length+upper_hidden_length+under_hidden_length);
            // alert("SceneChat.updateScrollBar() extra_length: "+ extra_length+ "scroll_length: "+ scroll_length+" upper_hidden_length : "+upper_hidden_length+" under_hidden_length : " + under_hidden_length); 
			 
              if(upper_hidden_length >0)
              {
                curr_scroll_start_position =  init_scroll_start_position + upper_hidden_length+ extra_length;
              }
              else
              {
			  	if(extra_length+scroll_length >= max_scroll_length ) //overflow
				{
					curr_scroll_start_position = init_scroll_start_position +max_scroll_length - scroll_length;
				}
				else
				{
					curr_scroll_start_position =  init_scroll_start_position + upper_hidden_length;
				}                
              }
              
			curr_scroll_length  =  scroll_length;
			
			var center_top = String(curr_scroll_start_position);
			var center_height = String(curr_scroll_length);
			
			var scroll_top = String(curr_scroll_start_position-5);
			var scroll_under = String(curr_scroll_start_position+curr_scroll_length);
			
			$("#chat_scroll_center").css("top",  center_top+"px");
			$("#chat_scroll_center").height(center_height+"px");
			
			$("#chat_scroll_top").css("top",  scroll_top+"px");
			$("#chat_scroll_under").css("top",  scroll_under+"px");
			
			//alert("SceneChat.updateScrollBar() top: "+ scroll_top+" length : "+center_height+" bottom : " + scroll_under);
			
			this.visibleScrollBar();
			this.ChatView.changeHelpBar( this.ScrollHelpBar);  
        }
    }
}

SceneChat.prototype.hiddenScrollBar = function()
{
	this.ScrollBg.hiddenObj();
    this.ScrollTop.hiddenObj();
    this.ScrollUnder.hiddenObj();
    this.ScrollCenter.hiddenObj();
    
 	this.TopArrow.hiddenObj();
    this.BottomArrow.hiddenObj();
}

SceneChat.prototype.visibleScrollBar = function()
{
	this.ScrollBg.visibleObj();
    this.ScrollTop.visibleObj();
    this.ScrollUnder.visibleObj();
    this.ScrollCenter.visibleObj();
    
 	//this.TopArrow.visibleObj();
    //this.BottomArrow.visibleObj();
    
    this.toggleArrow();
}

SceneChat.prototype.toggleArrow = function()
{
	var total_item = this.ChatMsgBox.getTotalMsgNum();
	var top_item= this.ChatMsgBox.getTopMsg();
	var bottom_item= this.ChatMsgBox.getBottomMsg(); 
	
	if((total_item > 0) &&(top_item == 1))
	{
		if(this.CurrStartMsg > 0)
		{
			this.TopArrow.visibleObj();
		}
		else
		{
			this.TopArrow.hiddenObj();
		}
	}
	else
	{
		this.TopArrow.visibleObj();
	}
	
	if((total_item > 0) &&(total_item == bottom_item))
	{
		if(this.CurrEndMsg<this.TotalChatMsg-1)
		{
			this.BottomArrow.visibleObj();
		}
		else
		{
			this.BottomArrow.hiddenObj();
		}	
	}
	else
	{
		this.BottomArrow.visibleObj();
	}
}


SceneChat.prototype.highlight=function(obj)
{
	alert("SceneChat.highlight()");
	
    this.ChatView.setCurrenHighlight(obj);
}

SceneChat.prototype.select=function(obj)
{
     this.ChatView.setCurrentSelect(obj);
}


SceneChat.prototype.processLeftKey = function(){
    alert("SceneChat.processLeftKey() ");
    
    var currentHighlight =  this.ChatView.getCurrentHighlight();

    switch(currentHighlight)
    {
        case this.SendMsgBtn:
            if(this.flagCallingMode==true)
			{
				this.highlight(this.CallEndBtn);
			}
			else
			{
				if(this.flagMultiChatMode==false)
				{
					this.highlight(this.CallBtn);
				}
				
			}
			
            break;
		case this.CallEndBtn:
			if(this.SendMsgBtn.GetFlagDim()== false)
			{
				this.highlight(this.SendMsgBtn);
			}			
		break;
		
		case this.CallBtn:
			if(this.VideoCallBtn.GetFlagDim() == true)
			{
				if(this.SendMsgBtn.GetFlagDim()== false)
				{
					this.highlight(this.SendMsgBtn);
				}			
			}
			else
			{
				this.highlight(this.VideoCallBtn);
			}
			
		break;
		
		case this.VideoCallBtn:
		if(this.SendMsgBtn.GetFlagDim()== false)
		{
			this.highlight(this.SendMsgBtn);
		}
		else
		{
			this.highlight(this.CallBtn);
		}
			
		break;
    }
}

SceneChat.prototype.processRightKey = function(){
    alert("SceneChat.processRightKey() ");
    
    var currentHighlight =  this.ChatView.getCurrentHighlight();

    switch(currentHighlight)
    {
        case this.SendMsgBtn:
            if(this.flagCallingMode==true)
			{
				this.highlight(this.CallEndBtn);
			}
			else
			{
				if(this.flagMultiChatMode==false)
				{
					if(this.VideoCallBtn.GetFlagDim() == true)
					{
						this.highlight(this.CallBtn);
					}
					else
					{
						this.highlight(this.VideoCallBtn);
					}
				}
			}
			
            break;
		case this.CallEndBtn:
			if(this.SendMsgBtn.GetFlagDim()== false)
			{
				this.highlight(this.SendMsgBtn);
			}
			
		break;
		
		case this.CallBtn:
			if(this.SendMsgBtn.GetFlagDim()== false)
			{
				this.highlight(this.SendMsgBtn);
			}				
		break;
		
		case this.VideoCallBtn:
			this.highlight(this.CallBtn);
		break;
    }
}

SceneChat.prototype.processDownKey = function(){
    alert("SceneChat.processDownKey() ");
    this.ChatMsgBox.msgDown();
	this.updateMsgBoxForDownKey();
}

SceneChat.prototype.processUpKey = function(){
    alert("SceneChat.processUpKey() ");
    this.ChatMsgBox.msgUp();
	this.updateMsgBoxForUpKey();
}

SceneChat.prototype.processEnterKey = function(){
    alert("SceneChat.processEnterKey() ");
    
    var currentHighlight =  this.ChatView.getCurrentHighlight();

    switch(currentHighlight)
    {
        case this.SendMsgBtn:
            StateMgr.Start_Chat_Msg_Send_State();
            break;
			
		case this.CallEndBtn:
            ProcMgr.DisconnectCall();
            break;
		case this.CallBtn:
			ProcMgr.CreateCall(ProcMgr.GetChatMemberSkypeName(), 0);
			break;
		
		case this.VideoCallBtn:
			ProcMgr.CreateCall(ProcMgr.GetChatMemberSkypeName(), 1);
			break;
    }
}

SceneChat.prototype.processBlueKey = function(){
    alert("SceneChat.processBlueKey() ");
    
	if(ProcMgr.isGenoaS==false)
	{
		StateMgr.Start_Live_Contact_List_State();
	}
}

SceneChat.prototype.processReturnKey = function(){
    alert("SceneChat.processReturnKey() ");
   
    ProcMgr.CloseChat(); 
}

SceneChat.prototype.processExitKey = function(){
    alert("SceneChat.processExitKey() ");

   StateMgr.Start_Exit_State(false);
}

SceneChat.prototype.processClickEvent = function(obj){
	alert("SceneChat.processClickEvent() ");
	
	if(obj == this.TopArrow || obj == this.BottomArrow)
	{
		if(obj == this.TopArrow)
		{
			this.processUpKey();
		}
		else
		{
			this.processDownKey();
		}
		
		return;
	}
	
	var currentHighlight =  this.ChatView.getCurrentHighlight();

	if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
    
    this.processEnterKey();	
}

