
var CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE = 4;

function SceneminiConferenceCall(options) {
	this.options = options;
    
    this.ConferenceCallView = null;
    
    this.CallDurationTextLabel = null;

    this.CallEndBtn		= null;
	this.VolumeBtn		= null;

	this.NoVolumeMixingTVLabel		= null;
	this.NoVolumeMixingSkypeLabel	= null;
    
    this.list_bg = null;
	this.list_line_bg = new Array(CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE-1);
    
    this.CallMemberDisplay	= new Array(CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE);
	this.CallMemberInfo		= new Array();    
    
	this.CurrentCallmemberPage	= 0;
	this.MaxCallmemberPage		= 0;
    this.NumOfCallMember		= 0;
        
	this.CallMemberNumberLabel	= null;
	this.HostNmaeLabel			= null;
	this.HostLabel				= null;
	
	this.ScrollBar = null;
	this.createdScrollBar = false;
	this.shownScrollBar = false;
	
	this.arrow_up	= null;
	this.arrow_down	= null;
	
	this.call_tooltip = null;
	this.flag_shown_tooltip = false;
	this.TooltipTimer = null;
}

SceneminiConferenceCall.prototype.initialize = function () {
	alert("SceneminiConferenceCall.initialize()");

	this.create();
}

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

	this.update();
	if(Flag_Hidden_State==false)
       $("#skype_popup_background").show();
}

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

	this.CurrentCallmemberPage = 1;
	this.initializeCallMemberDisplay();
    this.initializeCallMemberInfo();
    
	this.highlight(null);
	if(Flag_Hidden_State==false)
       $("#skype_popup_background").hide();
}

SceneminiConferenceCall.prototype.handleFocus = function () {
	alert("SceneminiConferenceCall.handleFocus()");

    var currentHighlight = this.ConferenceCallView.getCurrentHighlight();
    
    if(currentHighlight == null)
    {
        this.highlight(this.CallEndBtn);
    }
    else
    {
    	this.highlight(currentHighlight);
    }

	this.ShowKeyHelpbar();    
}

SceneminiConferenceCall.prototype.handleBlur = function () {
	alert("SceneminiConferenceCall.handleBlur()");
	
	this.highlight(null);
}

SceneminiConferenceCall.prototype.handleKeyDown = function (keyCode) {
	alert("SceneminiConferenceCall.handleKeyDown(" + keyCode + ")");

	//PluginAPIMgr.PlayAudio(keyCode);
	
	switch (keyCode) {
		case $.sfKey.LEFT:
        	this.processLeftKey();
			break;
		case $.sfKey.RIGHT:
        	this.processRightKey();
			break;
		case $.sfKey.UP:
             this.processUpKey();
			break;
		case $.sfKey.DOWN:
            this.processDownKey();
			break;

		case $.sfKey.ENTER:
         	this.processEnterKey();
			break;
            
        case $.sfKey.VOL_DOWN:
        case $.sfKey.PANEL_VOL_DOWN:
		case $.sfKey.VOL_UP:
        case $.sfKey.PANEL_VOL_UP:
			this.processVolumeKey();
			//$.sfKey.block(event);
			break;

        case $.sfKey.RED:
			break;

		case $.sfKey.BLUE:
			break;	 
			
		case $.sfKey.YELLOW:
		case $.sfKey.GREEN:
            break;
            
		case $.sfKey.TOOLS:
            break;
			
       case $.sfKey.RETURN:      
            this.processReturnKey();
            $.sfKey.block(event);
			break;
			
		case $.sfKey.EXIT:		   
		    this.processExitKey();
			$.sfKey.block(event);
			break;
            
          case 147:  //infolink
          case 261:  //contents
          case 115:  //wiselink
            ProcMgr.processInfolinkKey();
			break;
            
         default:
            ProcMgr.processBlockKey(keyCode);
            break;  
	}
	if(Flag_Hidden_State==false)
	event.stopPropagation();
}

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

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

    this.ConferenceCallView = new View("miniConferenceCall");

	this.CallDurationTextLabel = new Label(null,"conf_call_duration_text");
	this.CallDurationTextLabel.SetText(IDWS_MOIP_SKYPE_CALL_DURATION + " 00:00:00");

    var this_ = $.sfScene.get({id:"miniConferenceCall",scope:WIDGET.id});
    var clickCF =  function(obj){this_.processClickEvent(obj);};

	this.CallEndBtn = new Button();
    this.CallEndBtn.SetImageObjId("conf_call_end_btn");
    this.CallEndBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CALL_END_BTN_NORMAL);
    this.CallEndBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CALL_END_BTN_NORMALFOCUS);
    this.CallEndBtn.SetOnClickCallbackFunc(clickCF);
    this.CallEndBtn.setTextKPILog(TV_SID_END_CALL);
    this.CallEndBtn.SetOnMouseOverCallbackFunc(function(obj){
        this_.highlight(obj);
    });    

    this.VolumeBtn = new Button();
    this.VolumeBtn.SetImageObjId("conf_call_volume_btn");
    this.VolumeBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CALL_VOLUME_BTN_NORMAL);
    this.VolumeBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CALL_VOLUME_BTN_NORMALFOCUS);
    this.VolumeBtn.SetOnClickCallbackFunc(clickCF);
    this.VolumeBtn.setTextKPILog(SID_VOLUME);
    this.VolumeBtn.SetOnMouseOverCallbackFunc(function(obj){
        this_.highlight(obj);
    });    

    this.arrow_up = new Button();
    this.arrow_up.SetImageObjId("conf_call_arrow_up_btn");
    this.arrow_up.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CONFERENCE_ARROW_UP_NORMAL);
    this.arrow_up.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CONFERENCE_ARROW_UP_FOCUS);
    this.arrow_up.SetOnClickCallbackFunc(clickCF);
    this.arrow_up.SetOnMouseOverCallbackFunc(function(obj){
        this_.highlight(obj);
    });    
     
    this.arrow_down = new Button();
    this.arrow_down.SetImageObjId("conf_call_arrow_down_btn");
    this.arrow_down.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CONFERENCE_ARROW_DOWN_NORMAL);
    this.arrow_down.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CONFERENCE_ARROW_DOWN_FOCUS);
    this.arrow_down.SetOnClickCallbackFunc(clickCF);
    this.arrow_down.SetOnMouseOverCallbackFunc(function(obj){
        this_.highlight(obj);
    });    

	if(ProcMgr.ModelCode == TV_MODEL_CODE.X12 || ProcMgr.ModelCode == TV_MODEL_CODE.FOX_SBB)
	{
		this.NoVolumeMixingTVLabel = new Label(null,"conf_call_volume_mixing_tv");
		this.NoVolumeMixingTVLabel.SetText('TV');
		
		this.NoVolumeMixingSkypeLabel = new Label(null,"conf_call_volume_mixing_skype");
		this.NoVolumeMixingSkypeLabel.SetText('Skype');
	}
        
	this.CallMemberNumberLabel	= new Label(null,"conf_call_member_number");
	this.HostNmaeLabel			= new Label(null,"conf_call_host_name");
	this.HostLabel				= new Label(null,"conf_call_host");
	
	this.HostLabel.SetText(g_Data.CombinateStrings(TV_SID_MIX_HOST,' '));
	
	this.list_bg = new Label("conf_call_member_bg",null);
	this.list_bg.SetBgImage(g_Image.IMAGE_CONFERENCE_CALL_BG);
	
    var i=0;
	for( i=0; i<(CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE-1); i++)	
	{
        this.list_line_bg[i] = new Label("conf_call_member_line_"+(i+1),null);
		this.list_line_bg[i].SetBgImage(g_Image.IMAGE_CONFERENCE_CALL_LINE_BG);
    }	
	
    var a=0;
	for( a=0; a< this.CallMemberDisplay.length; a++)
	{
        this.CallMemberDisplay[a] = new Object();  	
        this.CallMemberDisplay[a].ui = new CompBase();
        this.CallMemberDisplay[a].ui.CreateBG("conf_call_member_"+a);
        this.CallMemberDisplay[a].ui.AddJPGImageLayer("conf_call_member_"+a+"_avatar");		//avatar	1
        this.CallMemberDisplay[a].ui.AddImageLayer("conf_call_member_"+a+"_online_status");	//status	2
        this.CallMemberDisplay[a].ui.AddTextLayer("conf_call_member_"+a+"_name");			//name		3
        this.CallMemberDisplay[a].ui.AddImageLayer("conf_call_member_"+a+"_frame");			//frame		4
        this.CallMemberDisplay[a].ui.AddImageLayer("conf_call_member_"+a+"_status");        //status	5
        this.CallMemberDisplay[a].thumbObj = "conf_call_member_"+a+"_avatar";				
		this.CallMemberDisplay[a].isShow = false;
    }
    this.SetNoVolumeMixingLabel();

	this.creatTooltip();   
}

SceneminiConferenceCall.prototype.update = function()
{  
    alert("SceneminiConferenceCall.update() ");
	//get host name
	var callmember_text = PluginAPIMgr.GetCallMemberDisplayName(0);
	var hostName;	
	if(callmember_text.length > 15)
	{
		hostName = callmember_text.slice(0,14) + '...';
	}
	else
	{
		hostName = callmember_text;
	}
	
	this.HostNmaeLabel.SetText(hostName);
	
	$("#conf_call_host_name_checker").html(hostName);
	var host_name_left = 228 - parseInt($("#conf_call_host_name_checker").css('width').replace(/[^-\d\.]/g, ''));
	alert('host_name_left='+host_name_left);
	$("#conf_call_host").css('left',host_name_left+'px');

	this.CurrentCallmemberPage = 1;
	this.updateCallMember();

	//VTP code
	//$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog(g_Data.CombinateStrings(TV_SID_MIX_HOST,' '));
	//$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog(IDWS_MOIP_SKYPE_CALL_DURATION + " 00:00:00");
	//$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog(hostName);
}


SceneminiConferenceCall.prototype.initializeCallMemberDisplay = function()
{    
	var a=0;
	for( a=0; a< this.CallMemberDisplay.length; a++)
	{
		this.clearCallMemberDisplay(a);
	}
}

SceneminiConferenceCall.prototype.clearCallMemberDisplay = function(index)
{	
    alert("SceneminiConferenceCall.clearCallMemberDisplay(" + index + ")");
    	    	
    if(this.CallMemberDisplay[index].isShow == true)
    {
    	alert("SceneminiConferenceCall.hideCallMemberDisplay(" + index + ")");    	

    	this.CallMemberDisplay[index].ui.Hide();
    	
		this.CallMemberDisplay[index].ui.SetImageLayer(1," ");
		this.CallMemberDisplay[index].ui.SetImageLayer(2, " ");
		this.CallMemberDisplay[index].ui.SetTextLayer(3, " ");
		this.CallMemberDisplay[index].ui.SetImageLayer(4, " ");
		this.CallMemberDisplay[index].ui.SetImageLayer(5, " ");
		this.CallMemberDisplay[index].isActivate = false
    	this.CallMemberDisplay[index].isShow = false;
    	  	
  		if(index > 0)
		{
			this.list_line_bg[index-1].hiddenObj();
		}  	    	
    }
}


SceneminiConferenceCall.prototype.initializeCallMemberInfo = function()
{
	var a=0;
	for( a=0; a< this.CallMemberInfo.length; a++)
	{
		this.clearCallMemberInfo(a);
	}
}

SceneminiConferenceCall.prototype.clearCallMemberInfo = function(index)
{
	if(this.CallMemberInfo[index])
	{
		this.CallMemberInfo[index].avatarImage	= null;
		this.CallMemberInfo[index].name			= null;
		this.CallMemberInfo[index].onlineState	= null;
		this.CallMemberInfo[index].callStatus	= null;
		this.CallMemberInfo[index].isActivate	= null;
	}
}


SceneminiConferenceCall.prototype.updateCallMember = function()
{
    alert("SceneminiConferenceCall.updateCallMember() ");

	//temp
    var NumberOfCallMember = PluginAPIMgr.GetNumOfCallMembers();
     
	var i=0;
	for(i=0; i< NumberOfCallMember; i++)
	{
		if(this.CallMemberInfo[i] == null)
		{
			this.CallMemberInfo[i] = new Object();
			this.CallMemberInfo[i].name = null;
		}

		if(this.CallMemberInfo[i].name == null)
		{
			//ther is a data!!
			this.CallMemberInfo[i].avatarImage	= PluginAPIMgr.GetConferenceCallMemberAvataImage(i);
			this.CallMemberInfo[i].name			= PluginAPIMgr.GetCallMemberDisplayName(i);
			this.CallMemberInfo[i].onlineState	= PluginAPIMgr.GetConferenceCallMemberOnlineState(i);
			this.CallMemberInfo[i].callStatus	= PluginAPIMgr.ConferenceCallMemberStatus(i);
			this.CallMemberInfo[i].isActivate	= false;
			
			this.UpdateCallMemberDisplay(i,0);
		}
		else
		{
			var callStatus = PluginAPIMgr.ConferenceCallMemberStatus(i);
			
			if(this.CallMemberInfo[i].callStatus != callStatus)
			{
				this.CallMemberInfo[i].callStatus = callStatus;
				this.UpdateCallMemberDisplay(i,1);
			}
			
			var onlineState = PluginAPIMgr.GetConferenceCallMemberOnlineState(i);
			
			if(this.CallMemberInfo[i].onlineState != onlineState)
			{
				this.CallMemberInfo[i].onlineState = onlineState;
				this.UpdateCallMemberDisplay(i,2);
			}
		}
	}
	
	if(NumberOfCallMember < this.NumOfCallMember)
	{
		for(i=NumberOfCallMember; i< this.NumOfCallMember; i++)
		{
			//check... check... check....
			this.clearCallMemberInfo(i);
		}
	}
	    
	var callMumber_text = g_Data.CombinateStrings(TV_SID_MIX_PEOPLE_ON_CALL, NumberOfCallMember);	
	this.CallMemberNumberLabel.SetText(callMumber_text);
		
	var quotient = parseInt(NumberOfCallMember / CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE);
	var rest = parseInt(NumberOfCallMember % CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE);
	
	if(rest > 0)
	{
		quotient++;
	}

	this.MaxCallmemberPage = quotient;
	alert('MaxCallmemberPage = ' + this.MaxCallmemberPage);
	
	//check scroll
	this.showScrollBar();
	
    this.NumOfCallMember = NumberOfCallMember;

	//VTP code
	//$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog(callMumber_text);
} 


SceneminiConferenceCall.prototype.updateActiveMemberInfo = function(callmemberIndex,loudness)
{
    alert("SceneminiConferenceCall.updateActiveMemberInfo() : "+ callmemberIndex);
    
	if(callmemberIndex > this.NumOfCallMember || callmemberIndex < 0)
	{
		alert("callmemberIndex error!!!")
		return;
	}
	else	
	{
		alert("callmemberIndex=" + callmemberIndex + " loudness="+loudness);
	}
	
	if(loudness > 0)
	{
		this.CallMemberInfo[callmemberIndex].isActivate = true;
	}
	else
	{
		this.CallMemberInfo[callmemberIndex].isActivate = false;
	}
	
	this.UpdateCallMemberDisplay(callmemberIndex,3);
}

SceneminiConferenceCall.prototype.GetOnlineStatusImage = function(state)
{
	var OnlineStatusImg = null;
	
    switch(state)
    {
        case ENUM_CONTACT_AVAILABILITY.ONLINE:
        case ENUM_CONTACT_AVAILABILITY.ONLINE_FROM_MOBILE:
            OnlineStatusImg = g_Image.IMAGE_CONFERENCE_CALL_ONLINE;
            break;

        case ENUM_CONTACT_AVAILABILITY.OFFLINE:
        case ENUM_CONTACT_AVAILABILITY.NOT_AVAILABLE_FROM_MOBILE:
            OnlineStatusImg = g_Image.IMAGE_CONFERENCE_CALL_OFFLINE;
            break;

        case ENUM_CONTACT_AVAILABILITY.AWAY :
        case ENUM_CONTACT_AVAILABILITY.AWAY_FROM_MOBILE:
            OnlineStatusImg = g_Image.IMAGE_CONFERENCE_CALL_AWAY;
            break;

        case ENUM_CONTACT_AVAILABILITY.DO_NOT_DISTURB :
        case ENUM_CONTACT_AVAILABILITY.DO_NOT_DISTURB_FROM_MOBILE:
            OnlineStatusImg = g_Image.IMAGE_CONFERENCE_CALL_DONOTDISTURB;
            break;

        case ENUM_CONTACT_AVAILABILITY.OFFLINE_BUT_CF_ABLE :
        case ENUM_CONTACT_AVAILABILITY.OFFLINE_BUT_VM_ABLE:
            OnlineStatusImg = g_Image.IMAGE_CONFERENCE_CALL_INVISIBLE;   
            break;
		
		//check!!!!!!!
        case ENUM_CONTACT_AVAILABILITY.BLOCKED  :
        case ENUM_CONTACT_AVAILABILITY.BLOCKED_SKYPEOUT:
            OnlineStatusImg = g_Image.IMAGE_CONFERENCE_CALL_BLOCK;   
            break;

        default:
            OnlineStatusImg = g_Image.IMAGE_CONFERENCE_CALL_OFFLINE; 
            break;      
    }
	
	return OnlineStatusImg;

	
}


/*
 *  function name	: UpdateCallMemberDisplay
 * 	param [index]	:  0~8 display id
 *  param [type]	: 	0 - change all components 
 * 						1 - 
 * 						2 - change online status
 * 
 */

SceneminiConferenceCall.prototype.UpdateCallMemberDisplay = function(infoIndex,type)
{
    alert("SceneminiConferenceCall.UpdateCallMemberDisplay(" + infoIndex + ")");

	var InfoPage;	
	var displayIndex;	
		
	if(infoIndex < CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE)
	{
		InfoPage = 1;	
		displayIndex = infoIndex;		
	}
	else{		
		var quotient = parseInt(infoIndex / CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE);	
		var rest = parseInt(infoIndex % CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE);
    	    
		InfoPage = quotient + 1;	
		displayIndex = rest;	
	}
		
	if(InfoPage != this.CurrentCallmemberPage)
	{
		alert("InfoPage : " + InfoPage + "  // CurrentCallmemberPage : " + this.CurrentCallmemberPage);
		return;
	}
    
	if(type == 0)
	{
		this.CallMemberDisplay[displayIndex].ui.SetImageLayer(4,g_Image.IMAGE_CONFERENCE_CALL_AVATAR_FRAME);
		this.CallMemberDisplay[displayIndex].ui.SetImageLayer(1,this.CallMemberInfo[infoIndex].avatarImage);		
		this.CallMemberDisplay[displayIndex].ui.SetImageLayer(2,this.GetOnlineStatusImage(this.CallMemberInfo[infoIndex].onlineState));		
		this.CallMemberDisplay[displayIndex].ui.SetTextLayer(3,this.CallMemberInfo[infoIndex].name);		
		this.UpdateStatus(displayIndex,this.CallMemberInfo[infoIndex].callStatus);
		
		if(displayIndex > 0)
		{
			this.list_line_bg[displayIndex-1].visibleObj();
		}
		
		//VTP code
		//$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog(this.CallMemberInfo[infoIndex].name);
	}
	//display status
	else if(type == 1)
	{
		this.UpdateStatus(displayIndex,this.CallMemberInfo[infoIndex].callStatus);
	
	}
	//online status
	else if (type == 2){
		this.CallMemberDisplay[displayIndex].ui.SetImageLayer(2,this.GetOnlineStatusImage(this.CallMemberInfo[infoIndex].onlineState));	
	}
	//activate
	else if (type == 3)
	{
		if(this.CallMemberDisplay[displayIndex].isActivate == true)
		{
			if(this.CallMemberInfo[infoIndex].isActivate == false)
			{
				this.CallMemberDisplay[displayIndex].ui.SetImageLayer(5,' ');
				this.CallMemberDisplay[displayIndex].isActivate = false;
			}
		}
		else
		{
			if(this.CallMemberInfo[infoIndex].isActivate == true)
			{
				this.CallMemberDisplay[displayIndex].ui.SetImageLayer(5,g_Image.IMAGE_CONFERENCE_CALL_SPEAKING_ICON);
				this.CallMemberDisplay[displayIndex].isActivate = true;
			}
		}
	}	
	else{		
    	alert("error");
		return;
	}

	//check check check
	if(this.CallMemberDisplay[displayIndex].isShow == false)
	{		
		this.CallMemberDisplay[displayIndex].ui.Show();
		this.CallMemberDisplay[displayIndex].isShow = true;
	}
       
}


SceneminiConferenceCall.prototype.NextCallMemberDisplayPage = function()
{
    alert("SceneminiConferenceCall.NextCallMemberDisplayPage");
    	
	if(this.MaxCallmemberPage == this.CurrentCallmemberPage)
	{
		return;
	}
	
	//Increase page number
	this.CurrentCallmemberPage++;
	
	var maxNum = this.CurrentCallmemberPage * CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE;
	var startIndex = (this.CurrentCallmemberPage-1)*CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE;
	var curPageItemNum = 0;
	
	if(this.MaxCallmemberPage == this.CurrentCallmemberPage)
	{
		curPageItemNum = this.NumOfCallMember - startIndex;
	}	
	else
	{
		curPageItemNum = CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE;
	}
		
	var i=0;
	for(i = 0; i < curPageItemNum; i++)
	{		
		this.UpdateCallMemberDisplay(startIndex+i,0);
	}
	
	for(i = curPageItemNum; i < CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE; i++)
	{		
		this.clearCallMemberDisplay(i);
	}
	
	//check scroll
	this.nextScrollBar();
}

SceneminiConferenceCall.prototype.PrevCallMemberDisplayPage = function()
{	
	alert("SceneminiConferenceCall.PrevCallMemberDisplayPage");
	
	if(this.CurrentCallmemberPage == 1)
	{
		return;
	}
	
	this.CurrentCallmemberPage--;
	
	var startIndex = (this.CurrentCallmemberPage-1) * CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE;

	var i=0;
	for(i = 0; i < CONFERENCE_CALL_MAX_MEMBER_NUM_IN_PAGE; i++)
	{		
		this.UpdateCallMemberDisplay(startIndex+i,0);
	}

	//check scroll
	this.prevSrollBar();
} 


SceneminiConferenceCall.prototype.highlight=function(obj)
{
    this.ConferenceCallView.setCurrenHighlight(obj);
    
    if(obj)
    {
    	this.showTooltip(obj);
    }
}


SceneminiConferenceCall.prototype.processEnterKey = function(){
    alert("SceneminiConferenceCall.processEnterKey() ");
    
    var currentHighlight =  this.ConferenceCallView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.VolumeBtn:        
			this.processVolumeKey();
			break;

		case this.CallEndBtn:
			ProcMgr.DisconnectCall();
			break;

        case this.arrow_up:        
			this.PrevCallMemberDisplayPage();
			break;

		case this.arrow_down:
			this.NextCallMemberDisplayPage();
			break;
    }
}

SceneminiConferenceCall.prototype.processRightKey = function(){
    alert("SceneminiConferenceCall.processRightKey() ");
    
    var currentHighlight =  this.ConferenceCallView.getCurrentHighlight();
    
    if(currentHighlight == this.VolumeBtn)
    {
    	this.highlight(this.CallEndBtn);
    } 	
}

SceneminiConferenceCall.prototype.processLeftKey = function(){
    alert("SceneminiConferenceCall.processLeftKey() ");
    
    var currentHighlight =  this.ConferenceCallView.getCurrentHighlight();

    if(currentHighlight == this.CallEndBtn)
    {
		this.highlight(this.VolumeBtn);
	}
}

SceneminiConferenceCall.prototype.processUpKey = function(){
    alert("SceneminiConferenceCall.processUpKey() ");

    var currentHighlight =  this.ConferenceCallView.getCurrentHighlight();

    if(currentHighlight == this.CallEndBtn || currentHighlight == this.VolumeBtn)
    {
		this.highlight(this.arrow_down);
	}
	else if(currentHighlight == this.arrow_down)
	{
		this.highlight(this.arrow_up);
	}
}

SceneminiConferenceCall.prototype.processDownKey = function(){
    alert("SceneminiConferenceCall.processDownKey() ");

    var currentHighlight =  this.ConferenceCallView.getCurrentHighlight();

    if(currentHighlight == this.arrow_up)
    {
		this.highlight(this.arrow_down);
	}
	else if(currentHighlight == this.arrow_down)
	{
		this.highlight(this.CallEndBtn);
	}
}

SceneminiConferenceCall.prototype.processVolumeKey=function()
{
    alert("SceneminiConferenceCall.processVolumeKey() ");

	if(ProcMgr.ModelCode == TV_MODEL_CODE.X12 || ProcMgr.ModelCode == TV_MODEL_CODE.FOX_SBB)
	{
		if(ProcMgr.CurOutputMixVolume == 0)
		{			
			PluginAPIMgr.MuteMic(true);
			PluginAPIMgr.SetCallMixVolume(0);			
			PluginAPIMgr.SetTVMixVolume(100);
			ProcMgr.CurOutputMixVolume = 1;
			
			$("#conf_call_volume_mixing_tv").css('color','#000000');
			$("#conf_call_volume_mixing_skype").css('color','#FFFFFF');
		}
		else
		{
			PluginAPIMgr.MuteMic(false);
			PluginAPIMgr.SetTVMixVolume(0);
			PluginAPIMgr.SetCallMixVolume(100);
			ProcMgr.CurOutputMixVolume = 0;

			$("#conf_call_volume_mixing_tv").css('color','#FFFFFF');
			$("#conf_call_volume_mixing_skype").css('color','#000000');
		}		
	}
	else
	{
		StateMgr.Start_Volume_Speaker_State();
	}
}

SceneminiConferenceCall.prototype.processClickEvent = function(obj){
	alert("SceneminiConferenceCall.processClickEvent() ");
	
	var currentHighlight =  this.ConferenceCallView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	this.processEnterKey();
}

SceneminiConferenceCall.prototype.updateCallDuration = function(time)
{
     this.CallDurationTextLabel.SetText(IDWS_MOIP_SKYPE_CALL_DURATION + "  "  + time);
}

SceneminiConferenceCall.prototype.processReturnKey = function(){
    alert("SceneminiConferenceCall.processReturnKey() ");
        
	WndMgr.StartCallConfirmPopup(MINI_CALL_CONFIRM_POPUP.WANT_TO_END_CALL);
}

SceneminiConferenceCall.prototype.showScrollBar = function(){
    alert("SceneminiConferenceCall.showScrollBar() ");

	if(this.MaxCallmemberPage < 2)
	{		
		if(this.shownScrollBar == true)
		{
			if(this.ScrollBar)
			{
				this.ScrollBar.Hide();
			}
		}
		return;
	}
	
	if(this.createdScrollBar == false)
	{
		this.ScrollBar = new ScrollBar();
		this.ScrollBar.Create("conf_call_scrollbar");
		this.ScrollBar.SetShapeStyle(SCROLLBAR_SHAPE_STYLE.VERTICAL);
		this.ScrollBar.SetFirstImage(g_Image.IMAGE_LIST_MAIN_SCROLLBAR_TOP);
		this.ScrollBar.SetSegmentImage(g_Image.IMAGE_LIST_MAIN_SCROLLBAR_CENTER);
		this.ScrollBar.SetLastImage(g_Image.IMAGE_LIST_MAIN_SCROLLBAR_BOTTOM);	
		this.ScrollBar.SetPosition(this.MaxCallmemberPage,240,0,3);
		this.ScrollBar.SetBGImage(g_Image.IMAGE_LIST_MAIN_SCROLLBAR_BG_TOP, g_Image.IMAGE_LIST_MAIN_SCROLLBAR_BG_CENTER, g_Image.IMAGE_LIST_MAIN_SCROLLBAR_BG_BOTTOM);
		
		this.createdScrollBar = true;
	}
        
	this.ScrollBar.SetTotalNum(this.MaxCallmemberPage);
	this.ScrollBar.SetCurrentNum(this.CurrentCallmemberPage);
	this.ScrollBar.ResetScrollBar();
                
	if(this.shownScrollBar == false)
	{		
		this.ScrollBar.Show();
	}

}

SceneminiConferenceCall.prototype.nextScrollBar = function(){
    alert("SceneminiConferenceCall.nextScrollBar() ");
	
	if(this.CurrentCallmemberPage > this.MaxCallmemberPage)
	{
		alert('last page');
		return;	
	}

	this.ScrollBar.SetCurrentNum(this.CurrentCallmemberPage);
	this.ScrollBar.ResetScrollBar();
}

SceneminiConferenceCall.prototype.prevSrollBar = function(){
    alert("SceneminiConferenceCall.prevSrollBar() ");

	if(this.CurrentCallmemberPage < 1)
	{
		alert('first page');
		return;	
	}

	this.ScrollBar.SetCurrentNum(this.CurrentCallmemberPage);
	this.ScrollBar.ResetScrollBar();
}

//volume btn is first!!
SceneminiConferenceCall.prototype.SetNoVolumeMixingLabel = function()
{	
	if(ProcMgr.ModelCode != TV_MODEL_CODE.X12 && ProcMgr.ModelCode != TV_MODEL_CODE.FOX_SBB)
	{
		return;
	}

	this.NoVolumeMixingTVLabel.visibleObj();
	this.NoVolumeMixingSkypeLabel.visibleObj();

	//VTP code
	//$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog('TV');
	//$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog('Skype');	
	
	if(ProcMgr.CurOutputMixVolume == 0)
	{
		$("#conf_call_volume_mixing_tv").css('color','#FFFFFF');
		$("#conf_call_volume_mixing_skype").css('color','#000000');
	}
	else
	{
		$("#conf_call_volume_mixing_skype").css('color','#FFFFFF');
		$("#conf_call_volume_mixing_tv").css('color','#000000');
	}
}

SceneminiConferenceCall.prototype.ShowKeyHelpbar = function()
{	
	if(WIDGET.mouse==true){
		helpBarHandler.hideHelpIcon('red',"");
		helpBarHandler.hideHelpIcon('green',"");
		helpBarHandler.hideHelpIcon('yellow',"");
		helpBarHandler.hideHelpIcon('blue',TV_SID_CHANGE_VIEW);
		helpBarHandler.hideHelpIcon('tools',sfLang.SID_TOOLS);
		helpBarHandler.showHelpIcon('return',SID_RETURN);
	}else{
		$("#HomeHelp").sfKeyHelp({
		//	'blue' : TV_SID_CHANGE_VIEW,
		//	'tools' : sfLang.SID_TOOLS,
			'return' : SID_RETURN
		});	
	}
}

SceneminiConferenceCall.prototype.UpdateStatus = function(displayIndex,callStatus)
{
	alert('SceneminiConferenceCall.UpdateStatus');
	
	var StatusImg;
			
	switch(callStatus)
	{
		case ENUM_CALL_MEMBER_STATUS.ROUTING:
		case ENUM_CALL_MEMBER_STATUS.EARLYMEDIA:
		case ENUM_CALL_MEMBER_STATUS.RINGING_OUT:
		case ENUM_CALL_MEMBER_STATUS.RINGING_IN:
			StatusImg = g_Image.IMAGE_CONFERENCE_CALL_CALLING_ICON;
			break;
			
		case ENUM_CALL_MEMBER_STATUS.FINISHED:
		case ENUM_CALL_MEMBER_STATUS.CANCELLED:
		case ENUM_CALL_MEMBER_STATUS.FAILED:
		case ENUM_CALL_MEMBER_STATUS.MISSED:
		case ENUM_CALL_MEMBER_STATUS.REFUSED:
		case ENUM_CALL_MEMBER_STATUS.BUSY:
		case ENUM_CALL_MEMBER_STATUS.DROPPED:			
			StatusImg = g_Image.IMAGE_CONFERENCE_CALL_END_ICON;
			break;

		case ENUM_CALL_MEMBER_STATUS.LOCALHOLD:
		case ENUM_CALL_MEMBER_STATUS.REMOTEHOLD:		
			StatusImg = g_Image.IMAGE_CONFERENCE_CALL_HOLD_ICON;
			break;

		default:
			StatusImg = ' ';
	}

	this.CallMemberDisplay[displayIndex].ui.SetImageLayer(5,StatusImg);	
}	

SceneminiConferenceCall.prototype.creatTooltip = function()
{	
	this.call_tooltip = new CompBase(); 
	this.call_tooltip.CreateBG("conf_call_tooltip_bg");
	this.call_tooltip.AddImageLayer("conf_call_tooltip_left_corner");
	this.call_tooltip.AddImageLayer("conf_call_tooltip_left_px");
	this.call_tooltip.AddImageLayer("conf_call_tooltip_center");
	this.call_tooltip.AddImageLayer("conf_call_tooltip_right_px");
	this.call_tooltip.AddImageLayer("conf_call_tooltip_right_corner");
	this.call_tooltip.AddTextLayer("conf_call_tooltip_text");	
	
	this.call_tooltip.SetImageLayer(1,g_Image.IMAGE_TOOLTIP_LEFT);
	this.call_tooltip.SetImageLayer(2,g_Image.IMAGE_TOOLTIP_PX);
	this.call_tooltip.SetImageLayer(3,g_Image.IMAGE_TOOLTIP_CENTER);
	this.call_tooltip.SetImageLayer(4,g_Image.IMAGE_TOOLTIP_PX);
	this.call_tooltip.SetImageLayer(5,g_Image.IMAGE_TOOLTIP_RIGHT);	
	
	this.flag_shown_tooltip = false;
}

SceneminiConferenceCall.prototype.showTooltip = function(cur_button)
{
	alert('SceneminiConferenceCall.showTooltip');
	
	var center_pos;
	var text_width_st;
	var tooltip_text;

	if(cur_button == this.VolumeBtn)
	{
		tooltip_text = SID_VOLUME;	
		center_pos = 120;
	}
	else if(cur_button == this.CallEndBtn)
	{
		tooltip_text = TV_SID_END_CALL;	
		center_pos = 191;
	}
	else
	{
		if(this.flag_shown_tooltip == true)
		{
			this.call_tooltip.Hide();
			this.flag_shown_tooltip = false;
		}
		return;
	}
	
	alert('center_pos='+center_pos);

	$('#conf_call_tooltip_text_checker').html(tooltip_text);
	var text_width = parseInt($("#conf_call_tooltip_text_checker").css('width').replace(/[^-\d\.]/g, ''));
		
	var text_width_half = parseInt(text_width/2);
			
	//setting bg position
	var bg_width = (40+text_width) +'px';
	var bg_left = (center_pos-text_width_half-20) + 'px';
	$('#conf_call_tooltip_bg').css('left',bg_left);	
	$('#conf_call_tooltip_bg').css('width',bg_width);
		
	//setting left px position
	var left_px_width_pos = (text_width_half-10)+'px';
	$('#conf_call_tooltip_left_px').css('width',left_px_width_pos);
	
	//setting center position
	var center_left_pos = (text_width_half+10)+'px';	
	$('#conf_call_tooltip_center').css('left',center_left_pos);
	
	//setting right px position
	var right_px_left_pos = (text_width_half+30)+'px';
	$('#conf_call_tooltip_right_px').css('left',right_px_left_pos);
	$('#conf_call_tooltip_right_px').css('width',left_px_width_pos);//same width left_px_width
		
	//setting right corner position	
	var right_corner_left_pos = (text_width+20)+'px';
	if(text_width%2 > 0)
	{
		right_corner_left_pos = (text_width+19)+'px';
	}
	
	$('#conf_call_tooltip_right_corner').css('left',right_corner_left_pos);
	
	//setting right corner position
	var text_width_pos = text_width+'px';
	$('#conf_call_tooltip_text').css('width',text_width_pos);	
	
	if(this.flag_shown_tooltip == false)
	{
		this.call_tooltip.Show();
		this.flag_shown_tooltip = true;
	}

	this.call_tooltip.SetTextLayer(6,tooltip_text);

	//start & reset tooltip timer
	this.StartTimerTooltip();
}

SceneminiConferenceCall.prototype.StartTimerTooltip = function()
{
	if(this.TooltipTimer)
	{
		clearTimeout(this.TooltipTimer);
	}
    
	this.TooltipTimer = setTimeout("ConfHideToolTipCB()", 6000);
	
	ConfHideToolTipCB = function(){
		var this_ = $.sfScene.get({id:'miniConferenceCall',scope:WIDGET.id});
		this_.call_tooltip.Hide();
		this_.flag_shown_tooltip = false;
    }	
}

SceneminiConferenceCall.prototype.processExitKey = function()
{
	if(ProcMgr.isUDmodel == false)
	{
		$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).processExitKey();
	}
	//ud model
	else
	{
		this.processReturnKey();
	}
}
