function SceneIncomingCall(options) {
	this.options = options;
    
    this.IncomingCallView = null;

    this.SkypeLogoLabel = null;
	
    this.CallMemberThumbnail = null;
    this.NameLabel = null;
    this.MassageLabel = null;

    this.CameraOnBtn	= null;
    //this.CameraOffBtn	= null;    
	this.CallStartBtn	= null;
    this.CallEndBtn		= null;

	this.TooltipTimer = null;
	this.flag_shown_tooltip = false;
	this.flag_conference_call = false;
	
	this.currentVolumeValue = 0;

}

SceneIncomingCall.prototype.initialize = function () {
	alert("SceneIncomingCall.initialize()");
    
   this.create();
}

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

	this.update();
}

SceneIncomingCall.prototype.handleHide = function () {
	alert("SceneIncomingCall.handleHide()");
	
	//this.hiddenPreview();
	if(this.TooltipTimer)
	{
		clearTimeout(this.TooltipTimer);
		$('#incoming_call_btn_tooltip').sfTooltip('hide');
		this.flag_shown_tooltip = false;		
	}
	this.flag_conference_call = false;
}

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

	if(this.CameraOnBtn.GetFlagVisible() == true)
	{
		this.highlight(this.CameraOnBtn);
	}
	else
	{
		this.highlight(this.CallStartBtn);
	}
	
}

SceneIncomingCall.prototype.handleBlur = function () {
	alert("SceneIncomingCall.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
    this.highlight(null);
}

SceneIncomingCall.prototype.handleKeyDown = function (keyCode) {
	alert("SceneIncomingCall.handleKeyDown(" + keyCode + ")");
	
	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.ENTER:
            this.processEnterKey();
			break;
            
        case sf.key.RETURN:
			this.processReturnKey();
            sf.key.preventDefault();
			break;
        
        case sf.key.EXIT:
            this.processExitKey();
            sf.key.preventDefault();
			break;

		case sf.key.VOL_DOWN:
        case sf.key.PANEL_VOL_DOWN:
		case sf.key.LEFT:
			this.processVolume(false);
			break;
			
		case sf.key.VOL_UP:
        case sf.key.PANEL_VOL_UP:
		case sf.key.RIGHT:			
			this.processVolume(true);
			break;

		case 602:	//INFOLINK
		case 606:	//CONTENTS
		case 608:	//WISELINK
            ProcMgr.processInfolinkKey(); 
			break;
	}
}

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

SceneIncomingCall.prototype.create = function(){
    alert("SceneIncomingCall.create()");
    
    this.IncomingCallView = new View("IncomingCall");
    this.IncomingCallView.SetBgImage('images/720p/skype_bg.png');

	this.SkypeLogoLabel = new Label("incoming_skype_logo", null);
    this.SkypeLogoLabel.SetBgImage(g_Image.IMAGE_CALL_SKYPE_LOGO);
    
	this.CallMemberThumbnail = new CompBase(); 
	this.CallMemberThumbnail.CreateBG("incoming_call_thumbnail");
	this.CallMemberThumbnail.AddJPGImageLayer("incoming_call_thumbnail_avatar");

    this.NameLabel = new Label(null, "incoming_call_name");
    this.NameLabel.SetIsPlainText(true);

    this.MassageLabel= new Label(null, "incoming_call_message");
    this.MassageLabel.SetTextStyle("calling_message_text_style");

    var this_ = sf.scene.get("IncomingCall");
    var clickCF =  function(obj){this_.processClickEvent(obj);};
    
    this.CameraOnBtn = new Button();
    this.CameraOnBtn.SetImageObjId("camera_on_btn");
    this.CameraOnBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_VIDEO_CALL_CAMERA_BTN_NORMAL);
    this.CameraOnBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_VIDEO_CALL_CAMERA_BTN_NORMALFOCUS);
    this.CameraOnBtn.SetOnClickCallbackFunc(clickCF); 
    $('#camera_on_btn').bind('mouseover',function(){this_.processCameraOnBtnOver();});
        
    this.CallStartBtn = new Button();
    this.CallStartBtn.SetImageObjId("call_start_btn");
    this.CallStartBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CALL_START_BTN_NORMAL);
    this.CallStartBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CALL_START_BTN_NORMALFOCUS);
    this.CallStartBtn.SetOnClickCallbackFunc(clickCF);
    $('#call_start_btn').bind('mouseover',function(){this_.processCallStartBtnOver();});

	this.CallEndBtn = new Button();
    this.CallEndBtn.SetImageObjId("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);
    $('#call_end_btn').bind('mouseover',function(){this_.processCallEndBtnOver();});
    
	$('#incoming_call_btn_tooltip').sfTooltip({
		text : TV_SID_END_CALL,
		orientation : 'down'
	});
}

SceneIncomingCall.prototype.highlight=function(obj)
{
    this.IncomingCallView.setCurrenHighlight(obj);
    
    if(obj)
    {
    	this.ShowTooltip(obj);
    }
}

SceneIncomingCall.prototype.update = function()
{	
	//check if conference call or not !!!
	var callee_display = PluginAPIMgr.GetCallMemberDisplayName();
	var callee_name = PluginAPIMgr.GetCallMemberID();
	//temp code..
	this.CallMemberThumbnail.SetImageLayer(1,PluginAPIMgr.GetContactAvataImage(callee_name));
		
	this.NameLabel.SetText(callee_display);
	
	if(PluginAPIMgr.IsConference() == 1)
	{
		this.flag_conference_call = true;
		this.MassageLabel.SetText(TV_INIVITED_JOIN_CONFERENCE_CALL);
	}
	else
	{
		this.flag_conference_call = false;
		this.MassageLabel.SetText(TV_CALLING_PROGRESS);
	}

	
	this.SetBtn();

	this.currentVolumeValue = PluginAPIMgr.GetSpeakerVolume();	
}

SceneIncomingCall.prototype.processLeftKey=function()
{
    alert("SceneIncomingCall.processLeftKey() ");
    
    var currentHighlight =  this.IncomingCallView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
		case this.CallEndBtn:
			this.highlight(this.CallStartBtn);
			break;
			
		case this.CallStartBtn:
			if(this.CameraOnBtn.GetFlagVisible() == true)
			{
				this.highlight(this.CameraOnBtn);	
			}			
			break;
	}
}

SceneIncomingCall.prototype.processRightKey=function()
{

    alert("SceneIncomingCall.processLeftKey() ");
    
    var currentHighlight =  this.IncomingCallView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
		case this.CameraOnBtn:	
			this.highlight(this.CallStartBtn);
			break;
			
		case this.CallStartBtn:        
			this.highlight(this.CallEndBtn);
			break;
	}

}

SceneIncomingCall.prototype.processEnterKey=function()
{
    alert("SceneIncomingCall.processEnterKey() ");
    
    var currentHighlight =  this.IncomingCallView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
		case this.CameraOnBtn:
			ProcMgr.AnswerByVideo(); 
			break;
			
		case this.CallStartBtn:
			ProcMgr.AnswerByVoice();
			break;
			
		case this.CallEndBtn:
			if(PluginAPIMgr.IsConference() == 1)
			{
				ProcMgr.DeclineIncomingConferenceCall();
			}
			else
			{
				ProcMgr.DeclineIncomingCall();
			}
			
		break;
	}
}

SceneIncomingCall.prototype.processReturnKey=function()
{
    alert("SceneIncomingCall.processReturnKey() ");
    
	if(PluginAPIMgr.IsConference() == 1)
	{
		ProcMgr.DeclineIncomingConferenceCall();
	}
	else
	{
		ProcMgr.DeclineIncomingCall();
	}
}

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

	if(PluginAPIMgr.IsConference() == 1)
	{
		ProcMgr.DeclineIncomingConferenceCall();
	}
	else
	{
		ProcMgr.DeclineIncomingCall();
	}
    
	if(ProcMgr.ProductInfo.support_multitasking == true)
	{
		ProcMgr.ExitWidget();
	}
	else
	{
		ProcMgr.flag_show_exit_popup = true;
	}
}


SceneIncomingCall.prototype.SetBtn = function(){
	alert("SceneVideoCall.SetBtn() ");

	var flag_visible_camera_btn = true;
	
	if(this.flag_conference_call == true)
	{
		flag_visible_camera_btn = false;
	}
	else
	{
		var camera_state = PluginAPIMgr.GetCameraState();
		if(camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING)
		{
			flag_visible_camera_btn = false;
		}
	}

	if(flag_visible_camera_btn == false)
	{
		this.CameraOnBtn.hiddenObj();
		
		$('#call_start_btn').css('left','555px');
		$('#call_end_btn').css('left','661px');
	}
	else{
		
		this.CameraOnBtn.visibleObj();

		$('#camera_on_btn').css('left','491px'); 
		$('#call_start_btn').css('left','608px');
		$('#call_end_btn').css('left','725px');
	}
}


SceneIncomingCall.prototype.processClickEvent = function(obj){
	alert("SceneIncomingCall.processClickEvent() ");

	this.processEnterKey();
}


SceneIncomingCall.prototype.ShowTooltip = function(btn_obj)
{		
	var tooltip_text;
	var tooltip_left;
	
	//1st. show
	if(this.flag_shown_tooltip == false)
	{
		$('#incoming_call_btn_tooltip').sfTooltip('show');
		this.flag_shown_tooltip = true;
	}	
	
	//check mode
	if(this.CameraOnBtn.GetFlagVisible() == true)
	{
		if(btn_obj == this.CameraOnBtn)
		{
			tooltip_text = IDWS_MOIP_VIDEO_CALL_KR_VOICE;
			tooltip_left = '523px';
		}
		else if(btn_obj == this.CallStartBtn)
		{
			tooltip_text = IDWS_MOIP_VOICE_CALL_KR_VOICE;
			tooltip_left = '640px';
		}
		else if(btn_obj == this.CallEndBtn)
		{
			tooltip_text = TV_SID_DECLINE;
			tooltip_left = '757px';
		}
	}
	else
	{
		if(btn_obj == this.CallStartBtn)
		{
			if(this.flag_conference_call == true)
			{
				tooltip_text = TV_VCMD_ANSWER;
			}
			else
			{
				tooltip_text = IDWS_MOIP_VOICE_CALL_KR_VOICE;
			}
			
			tooltip_left = '587px';
		}
		else if(btn_obj == this.CallEndBtn)
		{
			tooltip_text = TV_SID_DECLINE;
			tooltip_left = '693px';
		}
			
	}	

	$('#incoming_call_btn_tooltip').sfTooltip('setText',tooltip_text);
	$('#incoming_call_btn_tooltip').css('left',tooltip_left);
	
	if(this.TooltipTimer)
	{
		clearTimeout(this.TooltipTimer);
	}
    
	this.TooltipTimer = setTimeout("HideToolTipCallBack()", 6000);
	
	HideToolTipCallBack = function(){
		$('#incoming_call_btn_tooltip').sfTooltip('hide');
		sf.scene.get('IncomingCall').flag_shown_tooltip = false;
    }
}

SceneIncomingCall.prototype.processVolume = function(Increase){
    alert("SceneIncomingCall.processVolume() ");
    
    if(Increase == true)
    {
    	this.currentVolumeValue++
    	if(this.currentVolumeValue > 100)
    	{
    		this.currentVolumeValue = 100;
    	}
    }
    else
    {
    	this.currentVolumeValue--
    	if(this.currentVolumeValue < 0 )
    	{
    		this.currentVolumeValue = 0;
    	}
    }
    
   	PluginAPIMgr.SetSpeakerVolume(this.currentVolumeValue);
   	
}

SceneIncomingCall.prototype.processBtnOver = function(obj){
	
	var currentHighlight =  this.IncomingCallView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }    
}

SceneIncomingCall.prototype.processCameraOnBtnOver = function(){
	this.processBtnOver(this.CameraOnBtn);
}

SceneIncomingCall.prototype.processCallStartBtnOver = function(){
    this.processBtnOver(this.CallStartBtn);
}

SceneIncomingCall.prototype.processCallEndBtnOver = function(){
    this.processBtnOver(this.CallEndBtn);
}
