class HideRefDetails extends SqRootScript
{
	function OnContained()
	{
		ShowHideDetails(message().event);
	}
	
	function ScanAndHide(ls,event)
	{
		foreach(l in ls)
		{
			if(event == 2)
			{
				if(Property.Possessed(LinkDest(l),"HasRefs"))
					if(!(Property.Get(LinkDest(l),"HasRefs")))
						SetData(("obj_" + (LinkDest(l).tostring())),LinkDest(l));
				Property.SetSimple(LinkDest(l),"HasRefs",false);
			}
			else
			{
				if(!IsDataSet(("obj_" + (LinkDest(l).tostring()))))
					Property.SetSimple(LinkDest(l),"HasRefs",true);
			}
		}
	}
	
	function ShowHideDetails(event)
	{
		if(Link.AnyExist("~DetailAttachement",self))
		{
			local ls = Link.GetAll("~DetailAttachement",self);
			ScanAndHide(ls,event);
			
		}
		if(Link.AnyExist("CreatureAttachment",self))
		{
			local ls = Link.GetAll("CreatureAttachment",self);
			ScanAndHide(ls,event);
		}
	}
}