function SceneminiContactCallMenu(options) {
	this.options = options;

	this.miniContactCallMenuView = null;

	this.MenuItemBtn = new Array(3);

	this.CallerObj = null;
	this.SkypeId = null;
	this.IsEnableVideo =null;
	this.CancelBtn = null;

	this.CloseTimer = false;

}

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

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


	this.startTimer();
	this.ShowKeyHelpbar();
	$("#skype_popup_background").show();
}

SceneminiContactCallMenu.prototype.handleHide = function() {
	alert("SceneminiContactCallMenu.handleHide()");
	// this function will be called when the scene manager hide this scene

	if(this.CloseTimer == true) {
		this.stopTimer();
	}
	this.highlight(null);
	$("#skype_popup_background").hide();
}

SceneminiContactCallMenu.prototype.handleFocus = function() {
	alert("SceneminiContactCallMenu.handleFocus()");
	// this function will be called when the scene manager focus this scene
	var obj = this.miniContactCallMenuView.getCurrentHighlight();
	if(obj)
		this.highlight(obj);
	else
		this.highlight(this.MenuItemBtn[0]);
}

SceneminiContactCallMenu.prototype.handleBlur = function() {
	alert("SceneminiContactCallMenu.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
	var obj = this.miniContactCallMenuView.getCurrentHighlight();
	if(obj)
		obj.blur();
}

SceneminiContactCallMenu.prototype.handleKeyDown = function(keyCode) {
	alert("SceneminiContactCallMenu.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	PluginAPIMgr.PlayAudio(keyCode);
	switch (keyCode) {
		case $.sfKey.LEFT:
		case $.sfKey.RIGHT:

			break;
		case $.sfKey.UP:
			this.resetTimer();
			this.processUpKey();
			break;
		case $.sfKey.DOWN:
			this.resetTimer();
			this.processDownKey();
			break;

		case $.sfKey.ENTER:
			this.processEnterKey();
			$.sfKey.block(event);
			
			break;
		case $.sfKey.RETURN:
		case $.sfKey.EXIT:
			this.processReturnKey();
			$.sfKey.block(event);
			break;

		case 147:
		//infolink
		case 261:
		//contents
		case 115:
			//wiselink
			ProcMgr.processInfolinkKey();
			break;
	}
	if(Flag_Hidden_State==false)
		event.stopPropagation();
}
SceneminiContactCallMenu.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.hideHelpIcon('return',SID_RETURN);
	}else{
		$("#HomeHelp").sfKeyHelp({
		//	'blue' : TV_SID_CHANGE_VIEW,
		//	'tools' : sfLang.SID_TOOLS,
			'return' : SID_RETURN
		});	
	}
}
SceneminiContactCallMenu.prototype.highlight = function(obj) {
	this.miniContactCallMenuView.setCurrenHighlight(obj);

}

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

	var currentHighlight = this.miniContactCallMenuView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.MenuItemBtn[1]:
			this.highlight(this.MenuItemBtn[0]);
			break;
		case this.MenuItemBtn[2]:
			this.highlight(this.MenuItemBtn[1]);
			break;
		case this.CancelBtn:
			if(this.EnableVideoCall())
				this.highlight(this.MenuItemBtn[2]);
			else
				this.highlight(this.MenuItemBtn[1]);
			break;
	}
}

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

	var currentHighlight = this.miniContactCallMenuView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.MenuItemBtn[0]:
			this.highlight(this.MenuItemBtn[1]);
			break;
		case this.MenuItemBtn[1]:
			if(this.EnableVideoCall())
				this.highlight(this.MenuItemBtn[2]);
			else
				this.highlight(this.CancelBtn);
			break;
		case this.MenuItemBtn[2]:
			this.highlight(this.CancelBtn);
			break;
	}
}

SceneminiContactCallMenu.prototype.processEnterKey = function() {
	alert("SceneminiContactCallMenu.processEnterKey() ");

	var currentHighlight = this.miniContactCallMenuView.getCurrentHighlight();
	var widgetAPI = new Common.API.Widget();

	switch(currentHighlight) {
		case this.MenuItemBtn[0]:
			if(this.EnableVideoCall()){
				$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).LC_addEvent("EV016", "VIDEOCALL");
				
				ProcMgr.CreateCall(this.SkypeId ,1);	// go video call
			}else{
				$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).LC_addEvent("EV017", "VOICECALL");
				StateMgr.Start_Mini_Phone_Number_List(this.CurrentIndex,this.SkypeId);
			}
			break;
		case this.MenuItemBtn[1]:
			if(this.EnableVideoCall()){
				$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).LC_addEvent("EV017", "VOICECALL");
				StateMgr.Start_Mini_Phone_Number_List(this.CurrentIndex,this.SkypeId);
			}
			else{
				WndMgr.StartCallConfirmPopup(MINI_CALL_CONFIRM_POPUP.GO_TO_SKYPE);
				this.stopTimer();
			}
			break;
		case this.MenuItemBtn[2]:
			if(this.EnableVideoCall()){
				StateMgr.Stop_Mini_Contact_Call_Menu(true);
				WndMgr.StartCallConfirmPopup(MINI_CALL_CONFIRM_POPUP.GO_TO_SKYPE);
			}
			break;
		case this.CancelBtn:
			this.processReturnKey();
			break;
	}
}

SceneminiContactCallMenu.prototype.processReturnKey = function() {
	alert("SceneminiContactCallMenu.processReturnKey() ");
	StateMgr.Stop_Mini_Contact_Call_Menu(true);

}

SceneminiContactCallMenu.prototype.runSkypeWidget=function()
{
    alert("SceneminiContactCallMenu.runSkypeWidget() ");
	var widgetAPI = new Common.API.Widget();

	widgetAPI.runSearchWidget(WIDGET.id);
}

SceneminiContactCallMenu.prototype.startTimer = function() {
	alert("SceneminiContactCallMenu.startTimer() ");

	this.CloseTimer = true;
	var this_ = this;
	PluginAPIMgr.StartOSDTimer("60000", function() {
	   this_.popupTimerCallback();
	}, ENUM_TIMER_TYPE.POPUP_WND);
}

SceneminiContactCallMenu.prototype.resetTimer = function() {
	alert("SceneminiContactCallMenu.resetTimer() ");

	if(this.CloseTimer == true) {
		PluginAPIMgr.RestartOSDTimer("60000", ENUM_TIMER_TYPE.POPUP_WND);
	}
}

SceneminiContactCallMenu.prototype.stopTimer = function() {
	alert("SceneminiContactCallMenu.stopTimer() ");

	this.CloseTimer = false;
	PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
}

SceneminiContactCallMenu.prototype.popupTimerCallback = function() {
	alert("SceneminiContactCallMenu.popupTimerCallback() ");
	if(this.CloseTimer == false) {
		return
	}
	this.CloseTimer = false;
	/////////////////////
	StateMgr.Stop_Mini_Contact_Call_Menu(true);
}
SceneminiContactCallMenu.prototype.processMouseOver = function(obj) {
    alert("SceneminiContactCallMenu.processMouseOver() ");

    var currentHighlight = this.miniContactCallMenuView.getCurrentHighlight();
    if(currentHighlight != obj) {
        this.highlight(obj);
    }

    this.resetTimer();
}
SceneminiContactCallMenu.prototype.processClickEvent = function(obj) {
	alert("SceneminiContactCallMenu.processClickEvent() ");

	var currentHighlight = this.miniContactCallMenuView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}

	this.processEnterKey();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneminiContactCallMenu.prototype.create = function() {
	alert("SceneminiContactCallMenu.create()");
	this.miniContactCallMenuView = new View("miniContactCallMenu");
	

	var this_ = this;
	var clickCF = function(obj) {
		this_.processClickEvent(obj);
	};
	for(var i = 0; i < 3; i++) {
		this.MenuItemBtn[i] = new Button();
		this.MenuItemBtn[i].SetImageObjId("contactcallmenu_item" + i);
		this.MenuItemBtn[i].SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, null);
		this.MenuItemBtn[i].SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CONTACT_CALL_MENU_VOICELIST_FOCUS);
		this.MenuItemBtn[i].SetTextObjId("contactcallmenu_item" + i + "_text");
	//	this.MenuItemBtn[i].SetText(i);
		this.MenuItemBtn[i].SetOnClickCallbackFunc(clickCF);
		this.MenuItemBtn[i].SetOnMouseOverCallbackFunc(function(obj){
            this_.processMouseOver(obj);
        });
	}
	this.CancelBtn = new Button();
	this.CancelBtn.SetImageObjId("contactcallmenu_cancel_btn", 20);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_NEW_BUTTON_NORMAL);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_NEW_BUTTON_HIGHLIGHT);

	this.CancelBtn.SetTextObjId("contactcallmenu_cancel_btn_text");
	this.CancelBtn.SetText(SID_CANCEL);
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "list_btn_text_normal_style");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "list_btn_text_highlight_style");
	
	this.CancelBtn.setTextKPILog(KPI_LOG_ITEM_ID.CANCEL_BTN);
	this.CancelBtn.SetOnClickCallbackFunc(clickCF);
	this.CancelBtn.SetOnMouseOverCallbackFunc(function(obj){
            this_.processMouseOver(obj);
        });

}

SceneminiContactCallMenu.prototype.EnableVideoCall = function() {
	alert("SceneminiContactCallMenu.EnableVideoCall");

	var Availability = null;
	
	if(this.IsEnableVideo == false) {
		alert("EnableVideoCall -- IsEnableVideo == false");
		return false;
	}
	else if(this.SkypeId == "echo123") {
		alert("EnableVideoCall -- this.SkypeId == echo123");
		return false;
	}
	else if(PluginAPIMgr.GetContactPropWithName(this.SkypeId,ENUM_CONTACT_PROPERTY.P_PSTNNUMBER)) {
		alert("EnableVideoCall -- Is PSTN");
		return false;
	} 
	else {
		
		if(this.SkypeId && this.SkypeId.length > 0) {
			Availability = parseInt(PluginAPIMgr.GetContactAvailabilityWithName(this.SkypeId));		

			if(Availability == ENUM_CONTACT_AVAILABILITY.SKYPEOUT || Availability == ENUM_CONTACT_AVAILABILITY.BLOCKED_SKYPEOUT	) {
				alert("EnableVideoCall -- SKYPEOUT or BLOCKED_SKYPEOUT");
				return false;
			}
		}
	}

	return true;
}

SceneminiContactCallMenu.prototype.SetInit = function(itemIndex, skypeId,enableVideo) {
	alert("SceneminiContactCallMenu.SetInit");
	
	this.SkypeId = skypeId;
	this.IsEnableVideo = enableVideo;
	this.CurrentIndex = itemIndex;
	this.ModifyUI();
	
}
SceneminiContactCallMenu.prototype.ModifyUI = function() {
	alert("SceneminiContactCallMenu.SetInit");
	var itemSize = 74;
	var baseTop = 100;
	var MaxSize = 494;
	var fixedTop1 = 260;
	var fixedTop2 = 298;
	var mainContact = $.sfScene.get({id:"miniMainContact",scope:WIDGET.id});
	if(this.CurrentIndex!=mainContact.list.CurrentItemIndex)
		this.CurrentIndex = mainContact.list.CurrentItemIndex;
		
	var posTop = baseTop+itemSize*this.CurrentIndex;
	this.MenuItemBtn[2].visibleObj();
	var Camera_State = PluginAPIMgr.GetCameraState();
	if(!(Camera_State == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || Camera_State == ENUM_CAM_STATE.CAM_STATE_CONNECTING)) {
		this.IsEnableVideo = true;
	} else {
		this.IsEnableVideo = false;
	}
	if(this.EnableVideoCall()) {
		if(posTop>=fixedTop1)
			posTop=fixedTop1;
		$("#miniContactCallMenu").css("top", posTop + "px");
		this.MenuItemBtn[0].SetText(IDWS_MOIP_VIDEO_CALL_KR_VOICE);
		this.MenuItemBtn[1].SetText(IDWS_MOIP_VOICE_CALL_KR_VOICE);
		this.MenuItemBtn[2].SetText(TV_SID_GO_TO_SKYPE);
		this.MenuItemBtn[0].setTextKPILog(KPI_LOG_ITEM_ID.VIDEO_CALL_BTN);
		this.MenuItemBtn[1].setTextKPILog(KPI_LOG_ITEM_ID.VOICE_CALL_BTN);
		this.MenuItemBtn[2].setTextKPILog(KPI_LOG_ITEM_ID.GO_TO_SKYPE_BTN);
		$("#contactcallmenu_cancel_btn").css("top","125px");		/*last item's top size +47px*/
		$("#miniContactCallMenu").css("height","182px");
		this.miniContactCallMenuView.SetBgImage(g_Image.IMAGE_CONTACT_CALL_MENU_BG);
		
	} else {
		if(posTop>=fixedTop2)
			posTop=fixedTop2;
		$("#miniContactCallMenu").css("top", posTop + "px");
		this.MenuItemBtn[0].SetText(IDWS_MOIP_VOICE_CALL_KR_VOICE);
		this.MenuItemBtn[1].SetText(TV_SID_GO_TO_SKYPE);
		this.MenuItemBtn[2].hiddenObj();
		this.MenuItemBtn[0].setTextKPILog(KPI_LOG_ITEM_ID.VOICE_CALL_BTN);
		this.MenuItemBtn[1].setTextKPILog(KPI_LOG_ITEM_ID.GO_TO_SKYPE_BTN);
		$("#contactcallmenu_cancel_btn").css("top","87px");	/*last item's top size +47px*/
		$("#miniContactCallMenu").css("height","144px");
		this.miniContactCallMenuView.SetBgImage(g_Image.IMAGE_CONTACT_CALL_MENU_BG_1);
	}
}
