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

	this.miniContactAddMenuView = null;

	this.MenuItemBtn = new Array(3);
	
	this.SkypeId = null;
	
	this.CancelBtn = null;

	this.CloseTimer = false;

}

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

SceneminiContactAddMenu.prototype.handleShow = function() {
	alert("SceneminiContactAddMenu.handleShow()");
	// this function will be called when the scene manager show this scene
	
	this.startTimer();
	this.ShowKeyHelpbar();
	$("#skype_popup_background").show();
}

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

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

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

SceneminiContactAddMenu.prototype.handleKeyDown = function(keyCode) {
	alert("SceneminiContactAddMenu.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();
			break;
		case $.sfKey.RETURN:
		case $.sfKey.EXIT:
			this.processReturnKey();
			$.sfKey.block(event);
			break;

		case 147:
		//infolink
		case 261:
		//contents
		case 115:
			//wiselink
			break;
	}
	if(Flag_Hidden_State==false)
		event.stopPropagation();
}
SceneminiContactAddMenu.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
		});	
	}
}
SceneminiContactAddMenu.prototype.highlight = function(obj) {
	this.miniContactAddMenuView.setCurrenHighlight(obj);

}

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

	var currentHighlight = this.miniContactAddMenuView.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:
			this.highlight(this.MenuItemBtn[2]);
			break;
	}
}

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

	var currentHighlight = this.miniContactAddMenuView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.MenuItemBtn[0]:
			this.highlight(this.MenuItemBtn[1]);
			break;

		case this.MenuItemBtn[1]:
			this.highlight(this.MenuItemBtn[2]);
			break;

		case this.MenuItemBtn[2]:
			this.highlight(this.CancelBtn);
			break;
	}
}

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

	var currentHighlight = this.miniContactAddMenuView.getCurrentHighlight();
	var IsInCall = ProcMgr.GetIsInCall();
	
	switch(currentHighlight) {
		case this.MenuItemBtn[0]:
			if(IsInCall){
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_IN_CONTACT_LIST);
			}
			else{
				ProcMgr.AuthorizeContact(this.SkypeId);
			}	
			break;

		case this.MenuItemBtn[1]:
			if(IsInCall){
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_IN_CONTACT_LIST);
			}
			else{
				ProcMgr.IgnoreAuthReqContact(this.SkypeId);
			}
			break;
		case this.MenuItemBtn[2]:
			if(IsInCall){
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_IN_CONTACT_LIST);
			}
			else{
				ProcMgr.BlockAuthReqContact(this.SkypeId);
			}	
			break;
		case this.CancelBtn:
			this.processReturnKey();
			break;
	}
	StateMgr.Stop_Mini_Contact_Add_Menu(false);
	
}

SceneminiContactAddMenu.prototype.processReturnKey = function() {
	alert("SceneminiContactAddMenu.processReturnKey() ");
	StateMgr.Stop_Mini_Contact_Add_Menu(true);

}

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

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

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

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

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

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

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

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

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

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

SceneminiContactAddMenu.prototype.create = function() {
	alert("SceneminiContactAddMenu.create()");
	this.miniContactAddMenuView = new View("miniContactAddMenu");
	this.miniContactAddMenuView.SetBgImage(g_Image.IMAGE_CONTACT_ADD_MENU_BG );


	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("contactaddmenu_item"+i);
		this.MenuItemBtn[i].SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, null);
		this.MenuItemBtn[i].SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_PHONE_NUMBER_LIST_SELECT_CALL_FOCUS);
		this.MenuItemBtn[i].SetTextObjId("contactaddmenu_item"+i+"_text");
		this.MenuItemBtn[i].SetOnClickCallbackFunc(clickCF);
		this.MenuItemBtn[i].SetOnMouseOverCallbackFunc(function(obj){
            this_.processMouseOver(obj);
        });
	}
	this.MenuItemBtn[0].SetText(IDWS_MOIP_ADD_TO_CONTACTS);
	this.MenuItemBtn[1].SetText(SID_IGNORE_KR_SHORT);
	this.MenuItemBtn[2].SetText(IDWS_MOIP_SKYPE_BLOCK);
	this.MenuItemBtn[0].setTextKPILog(KPI_LOG_ITEM_ID.ADD_TO_CONTACTS_BTN);
	this.MenuItemBtn[1].setTextKPILog(KPI_LOG_ITEM_ID.IGNORE_BTN);
	this.MenuItemBtn[2].setTextKPILog(KPI_LOG_ITEM_ID.BLOCK_BTN);
	
	
	this.CancelBtn = new Button();
	this.CancelBtn.SetImageObjId("contactaddmenu_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("contactaddmenu_cancel_btn_text");
	this.CancelBtn.SetText(SID_CANCEL);
	this.CancelBtn.setTextKPILog(KPI_LOG_ITEM_ID.CANCEL_BTN);
	
	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.SetOnClickCallbackFunc(clickCF);
	this.CancelBtn.SetOnMouseOverCallbackFunc(function(obj){
       this_.processMouseOver(obj);
    });
}

SceneminiContactAddMenu.prototype.SetInit = function(itemIndex,skypeId) {
	alert("SceneminiContactAddMenu.SetInit");

	this.SkypeId = skypeId;
	this.itemIndex = itemIndex;
	this.ModifyUI();
}
SceneminiContactAddMenu.prototype.ModifyUI = function() {
	alert("SceneminiContactAddMenu.ModifyUI");
	var itemSize = 74;
	var baseTop = 100;
	var mainContact = $.sfScene.get({id:"miniMainContact",scope:WIDGET.id});
	if(this.itemIndex!=mainContact.list.CurrentItemIndex)
		this.itemIndex = mainContact.list.CurrentItemIndex;
		
	var posTop = baseTop+itemSize*this.itemIndex;
	$("#miniContactAddMenu").css("top",posTop+"px");
}
	
