int nCurScroll;

//int lngFileID;

object objNewItemsEquip;

void InitInterface_I(string iniName, int item)
{
	//remove all skill modifiers
	ref pch;
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { pch = CharacterFromId(characters[GetMainCharacterIndex()].Interface.Fellow); }
	else { pch = GetMainCharacter(); }

    // JRH fix oct 06: remove the ghost gp --> 
	if(ENABLE_AMMOMOD == 1)
	{
		int gp = GetCharacterItem(pch, "gunpowder");
		if(gp == 0)
		{
			TakenItems(pch, "gunpowder", 1); TakenItems(pch, "gunpowder", -1);
		}
	}
    // <-- JRH

	pch.skiprecalcskill = true;
	DeleteAttribute(&pch,"skill.Leadership.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Fencing.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Sailing.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Accuracy.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Cannons.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Grappling.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Repair.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Defence.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Commerce.mod"); // NK/GZ items mod
	DeleteAttribute(&pch,"skill.Sneak.mod"); // NK/GZ items mod
//	GameInterface.title = "titleItems";

	//lngFileID = LanguageOpenFile(GetStorylineDir(FindCurrentStoryline()) + "ItemsDescribe.txt"); // KK

	nCurScroll=-1;
	SetUsedItems();
//	FillScroll();
	string selection = GUN_ITEM_TYPE;
	if (item > -1 && item < ITEMS_QUANTITY && CheckAttribute(&Items[item], "groupID") == true) selection = Items[item].groupID; // KK
	if (selection == BLADE_ITEM_TYPE || selection == ARMOR_ITEM_TYPE || selection == AMMUNITION_ITEM_TYPE) selection = GUN_ITEM_TYPE;
	if (selection == SPYGLASS_ITEM_TYPE || selection == FLASK_ITEM_TYPE || selection == POUCH_ITEM_TYPE || selection == LOCKPICK_ITEM_TYPE || selection == CLOCK_ITEM_TYPE || selection == COMPASS_ITEM_TYPE) selection = OBJECT_ITEM_TYPE;
	FillSelectedScroll(selection);
	SendMessage(&GameInterface,"ls",MSG_INTERFACE_INIT,iniName);
	CreateExitString();//MAXIMUS: standard exit-string for exit-button
	CreateString(true, "ItemName", "", FONT_NORMAL, COLOR_YELLOW, 320, 200, SCRIPT_ALIGN_CENTER, 1.1); // KK

// MAXIMUS interface MOD -->
	SetSelectable("I_SHIPHOLD",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	SetSelectable("I_NATIONS",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	SetSelectable("I_TRADEBOOK",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	SetSelectable("I_QUESTBOOK",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	//SetSelectable("I_SHIPLOG",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	SetSelectable("I_SHIPLOG",false);
	SetSelectable("EXIT_BUTTON",true);
// MAXIMUS interface MOD <--

	SetEventHandler("InterfaceBreak","ProcessCancelExit",0);
	SetEventHandler("frame","FrameProcess",1);
	SetEventHandler("exitCancel","ProcessCancelExit",0);
	//SetEventHandler("EquipPress","ProcEquipPress",0);
	SetEventHandler("ievnt_command","ProcessCommandExecute",0);

	FrameProcess();
	UpdateItemData();

// KK -->
	switch (selection)
	{
		case GUN_ITEM_TYPE: SetSelectable("B_WEAPON",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntWeapon"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
		case POTION_ITEM_TYPE: SetSelectable("B_POTION",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntMedicine"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
		case OBJECT_ITEM_TYPE: SetSelectable("B_ITEMS",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntItems"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
		case MAP_ITEM_TYPE: SetSelectable("B_MAP",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntMap"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
		case QUEST_ITEM_TYPE: SetSelectable("B_QUEST",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntQuest"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
	}
// <-- KK
}

void FrameProcess()
{
	if(nCurScroll!=sti(GameInterface.itemslist.current))
	{
		nCurScroll = sti(GameInterface.itemslist.current);
		UpdateItemData();
	}
}

void ProcessCommandExecute()
{
	string comName = GetEventData();
	string nodName = GetEventData();

// MAXIMUS interface MOD -->
	int x;ref tmpch;string tmpstr;
        if(nodName=="I_CHARACTER")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
        if(nodName=="I_SHIP")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
        if(nodName=="I_SHIPHOLD")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
        if(nodName=="I_PASSENGER")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
        if(nodName=="I_QUESTBOOK")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
        if(nodName=="I_TRADEBOOK")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
        if(nodName=="I_SHIPLOG")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
        if(nodName=="I_NATIONS")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
		ProcessCancelExit();
		EndCancelInterface(false);

	}
}
// MAXIMUS interface MOD <--

	switch(nodName)
	{
	case "EQUIP_BUTTON":
		if(comName=="activate" || comName=="click")
		{
			I_EquipItem();
		}
		if(comName=="upstep" || comName=="deactivate")
		{
			SetCurrentNode("ITEMSLIST");
		}
	break;
// KK -->
	case "EXAMINE_BUTTON":
		if(comName=="activate" || comName=="click")
		{
			I_ExamineItem();
		}
		if(comName=="upstep" || comName=="deactivate")
		{
			SetCurrentNode("ITEMSLIST");
		}
	break;
// <-- KK
	case "ITEMSLIST":
		if(comName=="activate")
		{
			if(GetSelectable("EQUIP_BUTTON"))
			{
				SetCurrentNode("EQUIP_BUTTON");
			}
			if (GetSelectable("EXAMINE_BUTTON"))
			{
				SetCurrentNode("EXAMINE_BUTTON");
			}
		}
		if(comName=="upstep")
		{
			if( SendMessage(&GameInterface,"lsll",MSG_INTERFACE_MSG_TO_NODE,"TEXTWINDOW",6, true) )
			{	SendMessage(&GameInterface,"lslls",MSG_INTERFACE_MSG_TO_NODE,"TEXTWINDOW",-1,3, comName);
			}
		}
		if(comName=="downstep")
		{
			if( SendMessage(&GameInterface,"lsll",MSG_INTERFACE_MSG_TO_NODE,"TEXTWINDOW",6, false) )
			{	SendMessage(&GameInterface,"lslls",MSG_INTERFACE_MSG_TO_NODE,"TEXTWINDOW", -1,3, comName);
			}
		}
	break;
	case "B_WEAPON": if(comName=="activate" || comName=="click") { ChangeSelectedScroll(GUN_ITEM_TYPE); UpdateItemData(); } break;
	case "B_POTION": if(comName=="activate" || comName=="click") { ChangeSelectedScroll(POTION_ITEM_TYPE); UpdateItemData(); } break;
	case "B_ITEMS": if(comName=="activate" || comName=="click") { ChangeSelectedScroll(OBJECT_ITEM_TYPE); UpdateItemData(); } break;
	case "B_MAP": if(comName=="activate" || comName=="click") { ChangeSelectedScroll(MAP_ITEM_TYPE); UpdateItemData(); } break;
	case "B_QUEST": if(comName=="activate" || comName=="click") { ChangeSelectedScroll(QUEST_ITEM_TYPE); UpdateItemData(); } break;
	}
}

void I_EquipItem()
{
	int currentitem = nCurScroll; // KK
	ProcEquipPress();
	DeleteAttribute(&GameInterface,"itemslist");
	string curItemGroup = OBJECT_ITEM_TYPE;
	if(!GetSelectable("B_WEAPON")) { curItemGroup = GUN_ITEM_TYPE; }
	if(!GetSelectable("B_POTION")) { curItemGroup = POTION_ITEM_TYPE; }
	if(!GetSelectable("B_ITEMS")) { curItemGroup = OBJECT_ITEM_TYPE; }
	if(!GetSelectable("B_MAP")) { curItemGroup = MAP_ITEM_TYPE; } // KK
	if(!GetSelectable("B_QUEST")) { curItemGroup = QUEST_ITEM_TYPE; }
	FillSelectedScroll(curItemGroup);
// KK -->
	nCurScroll = currentitem;
	GameInterface.itemslist.current = nCurScroll;
	SendMessage(&GameInterface,"lsl",MSG_INTERFACE_SCROLL_CHANGE,"ITEMSLIST",nCurScroll);
	UpdateItemData();
// <-- KK
	SetCurrentNode("ITEMSLIST");
}

// KK -->
void I_ExamineItem()
{
	string itmName = GetItemIDByOrder(nCurScroll);
	aref itmRef;
	if (Items_FindItem(itmName, &itmRef) >= 0 && CheckAttribute(itmRef, "index")) GameInterface.ItemIdx = itmRef.index;
	PostEvent("LaunchIAfterFrame",1,"sl", "I_MAP", 2);
	InterfaceStack.SelectMenu_node = "I_MAP";
	interfaceResultCommand = RC_INTERFACE_ITEMS_EXIT;
	EndCancelInterface(false);
}
// <-- KK

void ChangeSelectedScroll(string curItemGroup)
{
	DeleteAttribute(&GameInterface,"itemslist");
	FillSelectedScroll(curItemGroup);
	SendMessage(&GameInterface,"lsl",MSG_INTERFACE_SCROLL_CHANGE,"ITEMSLIST",-1);
	SetCurrentNode("ITEMSLIST");
	SetSelectable("B_WEAPON",true);
	SetSelectable("B_POTION",true);
	SetSelectable("B_ITEMS",true);
	SetSelectable("B_MAP",true); // KK
	SetSelectable("B_QUEST",true);
	switch(curItemGroup)
	{
		case GUN_ITEM_TYPE: SetSelectable("B_WEAPON",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntWeapon"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
		case POTION_ITEM_TYPE: SetSelectable("B_POTION",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntMedicine"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
		case OBJECT_ITEM_TYPE: SetSelectable("B_ITEMS",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntItems"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
		case MAP_ITEM_TYPE: SetSelectable("B_MAP",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntMap"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break; // KK
		case QUEST_ITEM_TYPE: SetSelectable("B_QUEST",false); CreateStringCheckCase(true,"fakeTitle",XI_ConvertString("IntQuest"),"interface_title",COLOR_NORMAL,320,5,SCRIPT_ALIGN_CENTER,1.0,true); break;
	}
}

void UpdateItemData()
{
//	SendMessage(&GameInterface,"lsl",MSG_INTERFACE_MSG_TO_NODE,"CONTEXTHELP",0);

	string attributeName = "pic" + (nCurScroll+1);
	if( !CheckAttribute(&GameInterface,"itemslist."+attributeName+".itemID") )
	{
		GameInterface.strings.ItemName = ""; // KK
		SetFormatedText("TEXTWINDOW","");
		return;
	}

	aref itemARef;
	if( Items_FindItem(GameInterface.itemslist.(attributeName).itemID,&itemARef)<0 )
	{
		GameInterface.strings.ItemName = ""; // KK
		SetFormatedText("TEXTWINDOW","");
		return;
	}

	// int tmpLangFileID = LanguageOpenFile("interface_strings.txt"); // KK
	string newLineStr = TranslateString("","new_string");
	string itmDescribe = "";
	string strTmp;
	string Quality = "";
	if( CheckAttribute(itemARef,"name") ) // NK, was checking attr "describe"
	{	// KK itmDescribe = LanguageConvertString(lngFileID,itemARef.name) + newLineStr;
		GameInterface.strings.ItemName = GetAssembledString(TranslateString("", itemARef.name), itemARef); // KK
	}
	if( CheckAttribute(itemARef,"groupID") )
	{
        // scheffnow - weaponsmod -->
  	    // NK moved above if
        // scheffnow - weaponsmod <--
		switch(itemARef.groupID)
		{
			case GUN_ITEM_TYPE:
				// scheffnow - weaponsmod -->
				if (CheckAttribute(itemARef,"QualityName"))
				{
					Quality = itemARef.QualityName;
				}
				GameInterface.strings.ItemName = TranslateString("", Quality) + " " + GameInterface.strings.ItemName; // KK
				// scheffnow - weaponsmod <--
				itmDescribe = GetAssembledString(TranslateString("", "weapon gun parameters"), itemARef) + newLineStr;
			break;
			case BLADE_ITEM_TYPE:
				// scheffnow - weaponsmod -->
				if (CheckAttribute(itemARef,"QualityName"))
				{
					Quality = itemARef.QualityName;
				}
				GameInterface.strings.ItemName = TranslateString("", Quality) + " " + GameInterface.strings.ItemName; // KK
				// scheffnow - weaponsmod <--
				itmDescribe = GetAssembledString(TranslateString("", "weapon blade parameters"), itemARef) + newLineStr; // KK
			break;
			// GreatZen -->
			case ARMOR_ITEM_TYPE:
				itmDescribe = GetAssembledString(TranslateString("", "weapon armor parameters"),itemARef) + newLineStr;
			break;
			// GreatZen <--
		}
	}
	else
	{	if( CheckAttribute(itemARef,"potion") )
		{
			itmDescribe = TranslateString("", "Potion parameters")+":";
			if( CheckAttribute(itemARef,"potion.health") )
			{
				itmDescribe += " "+TranslateString("", "health value");
				if(stf(itemARef.potion.health)>=0)
				{	itmDescribe += "+" + sti(itemARef.potion.health) + ".";
				} else
				{	itmDescribe += sti(itemARef.potion.health) + ".";
				}
			}
			itmDescribe += newLineStr;
		}
	}
	// KK itmDescribe += newLineStr;
	if( CheckAttribute(itemARef,"describe") )	itmDescribe = itmDescribe + GetAssembledString(TranslateString("", itemARef.describe), itemARef) + GetItemBonuses(itemARef.id); // NK
	SetFormatedText("TEXTWINDOW",itmDescribe);

	SetNodeUsing("EXAMINE_BUTTON", false); // KK
	if( CheckAttribute(itemARef,"groupID") )
	{
// KK -->
		if (itemARef.groupID == MAP_ITEM_TYPE) {
			SetNodeUsing("EQUIP_BUTTON", false);
			SetNodeUsing("EXAMINE_BUTTON", true);
			return;
		}
// <-- KK
		if (itemARef.groupID!=BLADE_ITEM_TYPE && itemARef.groupID!=GUN_ITEM_TYPE && itemARef.groupID!=ARMOR_ITEM_TYPE && itemARef.groupID!=SPYGLASS_ITEM_TYPE && itemARef.groupID!=FLASK_ITEM_TYPE && itemARef.groupID!=POUCH_ITEM_TYPE && itemARef.groupID!=LOCKPICK_ITEM_TYPE && itemARef.groupID!=CLOCK_ITEM_TYPE && itemARef.groupID!=COMPASS_ITEM_TYPE) {
			SetNodeUsing("EQUIP_BUTTON",false);
			SetNodeUsing("EXAMINE_BUTTON", false);
			return;
		}
		SetNodeUsing("EQUIP_BUTTON",true);
		SetSelectable("EQUIP_BUTTON",ThisItemCanBeEquip(itemARef));

		if(IsEquipedItem(itemARef.id))
		{
			SendMessage(&GameInterface,"lsls",MSG_INTERFACE_MSG_TO_NODE,"EQUIP_BUTTON",0, XI_ConvertString("Release that"));
			if(itemARef.groupID==GUN_ITEM_TYPE || itemARef.groupID==BLADE_ITEM_TYPE || itemARef.groupID==ARMOR_ITEM_TYPE || itemARef.groupID==SPYGLASS_ITEM_TYPE || itemARef.groupID==FLASK_ITEM_TYPE || itemARef.groupID==POUCH_ITEM_TYPE || itemARef.groupID==LOCKPICK_ITEM_TYPE || itemARef.groupID==CLOCK_ITEM_TYPE || itemARef.groupID==COMPASS_ITEM_TYPE)
			{
				SetSelectable("EQUIP_BUTTON",true);
			}
		}
		else
		{
			SendMessage(&GameInterface,"lsls",MSG_INTERFACE_MSG_TO_NODE,"EQUIP_BUTTON",0, XI_ConvertString("Equip that"));
		}
	} else {
		SetNodeUsing("EQUIP_BUTTON",false);
		SetNodeUsing("EXAMINE_BUTTON", false); // KK
	}
}
/*
void FillScroll()
{
    int i,j;
    string attributeName;

	if(nCurScroll<0)	nCurScroll = 0;
	GameInterface.itemslist.current = nCurScroll;
	nCurScroll = -1;
	GameInterface.itemslist.ImagesGroup.t0 = "usedflag";
	GameInterface.itemslist.ImagesGroup.t1 = "ICONS";
	aref arImgGrp;
	makearef(arImgGrp,GameInterface.itemslist.ImagesGroup);
	FillImagesGroupForItems(arImgGrp);
	GameInterface.itemslist.NotUsed = 5;

	GameInterface.itemslist.BadTex1 = GetItemPictureTexture("itemslist.ImagesGroup","");
	GameInterface.itemslist.BadPic1 = GetItemPictureName("");

	aref curItem,arItem;
	aref rootItems; makearef(rootItems,Characters[GetMainCharacterIndex()].Items);
    for(i=0; i<GetAttributesNum(rootItems); i++)
    {
		attributeName = "pic" + (i+1);
		curItem = GetAttributeN(rootItems,i);
		j = sti(GetAttributeValue(curItem));

		if( Items_FindItem(GetAttributeName(curItem),&arItem) >= 0 )
		{
			GameInterface.itemslist.(attributeName).img1 = GetItemPictureName(arItem.id);
			GameInterface.itemslist.(attributeName).tex1 = GetItemPictureTexture("itemslist.ImagesGroup",arItem.id);
			if(j>1)	GameInterface.itemslist.(attributeName).str1 = "#"+j;
			GameInterface.itemslist.(attributeName).itemID = arItem.id;
			if(IsEquipedItem(arItem.id))
			{
				GameInterface.itemslist.(attributeName).img2 = "usedflag";
				GameInterface.itemslist.(attributeName).tex2 = 0;
			}
		}
		else
		{
			GameInterface.itemslist.(attributeName).img1 = GameInterface.itemslist.BadPic1;
			GameInterface.itemslist.(attributeName).tex1 = GameInterface.itemslist.BadTex1;
		}
    }
	GameInterface.itemslist.ListSize = i;
	//DumpAttributes(&GameInterface);
}
*/
void ProcessCancelExit()
{
	IDoExit(RC_INTERFACE_ITEMS_EXIT);
}

void IDoExit(int exitCode)
{
	DelEventHandler("InterfaceBreak","ProcessCancelExit");
	DelEventHandler("frame","FrameProcess");
	DelEventHandler("exitCancel","ProcessCancelExit");
	//DelEventHandler("EquipPress","ProcEquipPress");
	DelEventHandler("ievnt_command","ProcessCommandExecute");

	//LanguageCloseFile(lngFileID);

	RefreshUsedItems();
	ref chref;
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { chref = CharacterFromId(characters[GetMainCharacterIndex()].Interface.Fellow); }
	else { chref = GetMainCharacter(); }
	for(int s = 0; s < 10; s++) GetCharacterSkill(chref, GetSkillName(s)); // NK/GZ items mod to force refresh of modifiers.
	if(CheckAttribute(chref,"skiprecalcskill")) { DeleteAttribute(chref, "skiprecalcskill"); }
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { DeleteAttribute(GetMainCharacter(),"Interface.Fellow"); }
    interfaceResultCommand = exitCode;
// MAXIMUS interface MOD -->
/*
	if( CheckAttribute(&InterfaceStates,"InstantExit") && sti(InterfaceStates.InstantExit)==true )
	{
		EndCancelInterface(true);
	}
	else
	{
		PostEvent("LaunchIAfterFrame",1,"sl", "I_SELECTMENU", 1);
		EndCancelInterface(false);
	}*/
	EndCancelInterface(true);
// MAXIMUS interface MOD <--
}

void ProcEquipPress()
{
	ref chref;
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { chref = CharacterFromId(characters[GetMainCharacterIndex()].Interface.Fellow); }
	else { chref = GetMainCharacter(); }
	string itmName = GetItemIDByOrder(nCurScroll);
	aref itmRef;
	if( Items_FindItem(itmName,&itmRef)>=0 && CheckAttribute(itmRef,"groupID") )
	{
		string itmGroup = itmRef.groupID;
		if( IsEquipedItem(itmName) )
		{
			objNewItemsEquip.(itmGroup) = "";
		}
		else
		{
			objNewItemsEquip.(itmGroup) = itmName;
		}
	}
}

string GetItemIDByOrder(int num)
{
	string attrName = "pic"+(num+1);
	if( CheckAttribute(&GameInterface,"itemslist."+attrName+".itemID") )
		return GameInterface.itemslist.(attrName).itemID;
	return "";
}

void SetUsedItems()
{
	ref mchref;
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { mchref = CharacterFromId(characters[GetMainCharacterIndex()].Interface.Fellow); }
	else { mchref = GetMainCharacter(); }
	DeleteAttribute(&objNewItemsEquip,"");
	aref arEquip;
	makearef(arEquip,mchref.equip);
	CopyAttributes(&objNewItemsEquip,arEquip);
}

bool IsEquipedItem(string itemID)
{
	int q = GetAttributesNum(&objNewItemsEquip);

	aref arEquip;
	for(int i=0; i<q; i++)
	{
		arEquip = GetAttributeN(&objNewItemsEquip,i);
		if( GetAttributeValue(arEquip)==itemID ) return true;
	}

	return false;
}

void RefreshUsedItems()
{
	ref mchref;
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { mchref = CharacterFromId(characters[GetMainCharacterIndex()].Interface.Fellow); }
	else { mchref = GetMainCharacter(); }
	aref arItm;

	string sItemName;
	string sGroupName;
	aref arEquip;
	int q = GetAttributesNum(&objNewItemsEquip);

	for(int i=0; i<q; i++)
	{
		arEquip = GetAttributeN(&objNewItemsEquip,i);
		sGroupName = GetAttributeName(arEquip);
		sItemName = GetAttributeValue(arEquip);
		if(sItemName=="")
		{	RemoveCharacterEquip(mchref,sGroupName);
		}
		else
		{	EquipCharacterByItem(mchref,sItemName);
		}
	}
}

bool ThisItemCanBeEquip( aref arItem )
{
	ref mchref;
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { mchref = CharacterFromId(characters[GetMainCharacterIndex()].Interface.Fellow); }
	else { mchref = GetMainCharacter(); }

	if( !CheckAttribute(arItem,"groupID") )
	{
		trace("WARNING!!! item "+arItem.id+" hav`t attr. groupID");
		return false;
	}
	if( !IsCanEquiping(mchref,arItem.groupID) )
	{
		ShowHelpString("chelp_items#10");
		return false;
	}
	if(arItem.groupID!=GUN_ITEM_TYPE) return true;

	if( !CheckAttribute(arItem,"chargeQ") )
	{
		trace("WARNING!!! item "+arItem.id+" hav`t attr. chargeQ");
		return false;
	}
	int chrgQ = sti(arItem.chargeQ);

	if(chrgQ<2) return true;
	if( !IsCharacterPerkOn(mchref,"Gunman") )
	{
		ShowHelpString("chelp_items#11");
		return false;
	}

	if(chrgQ<4) return true;
	if( !IsCharacterPerkOn(mchref,"GunProfessional") )
	{
		ShowHelpString("chelp_items#11");
		return false;
	}

	return true;
}

void FillSelectedScroll(string itemsID)
{
	SetNodeUsing("EQUIP_BUTTON", false); // KK
	SetNodeUsing("EXAMINE_BUTTON", false); // KK

	ref pch;
	if(CheckAttribute(GetMainCharacter(),"Interface.Fellow")) { pch = CharacterFromId(characters[GetMainCharacterIndex()].Interface.Fellow); }
	else { pch = GetMainCharacter(); }

	int i,j,allItems;
	string attributeName;

	if(nCurScroll<0)	nCurScroll = 0;
	GameInterface.itemslist.current = nCurScroll;
	nCurScroll = -1;
	GameInterface.itemslist.ImagesGroup.t0 = "usedflag";
	GameInterface.itemslist.ImagesGroup.t1 = "ICONS";
	aref arImgGrp;
	makearef(arImgGrp,GameInterface.itemslist.ImagesGroup);
	FillImagesGroupForItems(arImgGrp);
	GameInterface.itemslist.NotUsed = 5;

	GameInterface.itemslist.BadTex1 = GetItemPictureTexture("itemslist.ImagesGroup","");
	GameInterface.itemslist.BadPic1 = GetItemPictureName("");

	aref curItem,arItem;
	aref rootItems; makearef(rootItems,pch.Items);
	int loaded = 0;
	string curItemID = OBJECT_ITEM_TYPE;
	for(i=0; i<GetAttributesNum(rootItems); i++)
	{
		curItemID = OBJECT_ITEM_TYPE;
		attributeName = "pic" + (i+1);
		curItem = GetAttributeN(rootItems,i);
		j = sti(GetAttributeValue(curItem));

		if(Items_FindItem(GetAttributeName(curItem),&arItem)>=0)
		{
			if(CheckAttribute(arItem,"groupID"))
			{
				curItemID = OBJECT_ITEM_TYPE;
				if(arItem.groupID==GUN_ITEM_TYPE || arItem.groupID==BLADE_ITEM_TYPE || arItem.groupID==ARMOR_ITEM_TYPE || arItem.groupID==AMMUNITION_ITEM_TYPE) { curItemID = GUN_ITEM_TYPE; }
				if(arItem.groupID==POTION_ITEM_TYPE) curItemID = POTION_ITEM_TYPE;
				//if(arItem.groupID==SPYGLASS_ITEM_TYPE || arItem.groupID==FLASK_ITEM_TYPE || arItem.groupID==POUCH_ITEM_TYPE || arItem.groupID==LOCKPICK_ITEM_TYPE || arItem.groupID==CLOCK_ITEM_TYPE || arItem.groupID==COMPASS_ITEM_TYPE) { curItemID = OBJECT_ITEM_TYPE; }
				if (arItem.groupID == MAP_ITEM_TYPE) curItemID = MAP_ITEM_TYPE; // KK
				if(arItem.groupID==QUEST_ITEM_TYPE) curItemID = QUEST_ITEM_TYPE;
				if(curItemID==itemsID)
				{
					if(curItemID==GUN_ITEM_TYPE && arItem.id=="bladeX4") continue;//MAXIMUS
					attributeName = "pic" + (loaded+1);
					GameInterface.itemslist.(attributeName).img1 = GetItemPictureName(arItem.id);
					GameInterface.itemslist.(attributeName).tex1 = GetItemPictureTexture("itemslist.ImagesGroup",arItem.id);
					if(j>1)	GameInterface.itemslist.(attributeName).str1 = "#"+j;
					GameInterface.itemslist.(attributeName).itemID = arItem.id;
					if(IsEquipedItem(arItem.id))
					{
						GameInterface.itemslist.(attributeName).img2 = "usedflag";
						GameInterface.itemslist.(attributeName).tex2 = 0;
					}
					loaded++;
				}
				else
				{
					attributeName = "pic" + (loaded+1);
					GameInterface.itemslist.(attributeName).img1 = GameInterface.itemslist.BadPic1;
					GameInterface.itemslist.(attributeName).tex1 = GameInterface.itemslist.BadTex1;
				}
			}
			else
			{
				if(curItemID==itemsID)
				{
					if(curItemID==GUN_ITEM_TYPE && arItem.id=="bladeX4") continue;//MAXIMUS
					attributeName = "pic" + (loaded+1);
					GameInterface.itemslist.(attributeName).img1 = GetItemPictureName(arItem.id);
					GameInterface.itemslist.(attributeName).tex1 = GetItemPictureTexture("itemslist.ImagesGroup",arItem.id);
					if(j>1)	GameInterface.itemslist.(attributeName).str1 = "#"+j;
					GameInterface.itemslist.(attributeName).itemID = arItem.id;
					if(IsEquipedItem(arItem.id))
					{
						GameInterface.itemslist.(attributeName).img2 = "usedflag";
						GameInterface.itemslist.(attributeName).tex2 = 0;
					}
					loaded++;
				}
				else
				{
					attributeName = "pic" + (loaded+1);
					GameInterface.itemslist.(attributeName).img1 = GameInterface.itemslist.BadPic1;
					GameInterface.itemslist.(attributeName).tex1 = GameInterface.itemslist.BadTex1;
				}
			}
		}
		else
		{
			attributeName = "pic" + (loaded+1);
			GameInterface.itemslist.(attributeName).img1 = GameInterface.itemslist.BadPic1;
			GameInterface.itemslist.(attributeName).tex1 = GameInterface.itemslist.BadTex1;
		}
    }
	GameInterface.itemslist.ListSize = loaded-1;
	if(nCurScroll<0 || nCurScroll>=sti(GameInterface.itemslist.ListSize)) { nCurScroll = 0; }
	GameInterface.itemslist.current = nCurScroll;
}
