public void AddToLibrary(VitalsBehavior behavior){
		// replace or add new behavior
    	if (FindBehaviorInLibrary(behavior.name)!= null){ // was ExistInBehaviors, behaviors was empty.
			for (int i = 0;i<library.Length; i++){
				if (library[i].name == behavior.name){
					library[i] = behavior;
					break;
				}
			}
		}
		else
		{
			VitalsBehavior[] newLib = new VitalsBehavior[library.Length+1];
			for (int i = 0;i<library.Length; i++)
				newLib[i] = library[i];
			newLib[library.Length] = behavior;
			library = newLib;
		}
	}
    public VitalsBehavior AddBehavior(VitalsBehavior behavior)
    {
        if (!behavior.stackable && ExistInBehaviors(behavior.name))
            return null;
		actionString += "Add "+behavior.name+":";
		VitalsBehaviorLogItem logItem = new VitalsBehaviorLogItem(Time.time,"ADD:"+this.name);
		LogMgr.GetInstance ().GetCurrent().Add (logItem);
		if (!addingByTrigger && behavior.triggered != null && behavior.triggered != ""){
			// emit the 'triggered' message if it wasn't the cause of this add
			InteractStatusMsg msg = new InteractStatusMsg( behavior.triggered );
			sendingTrigger = true; // flag so we don't respond to our own message
            Brain.GetInstance().PutMessage(msg);
			sendingTrigger = false;
		}
		
		VitalsBehavior newBehavior = behavior.Copy().Init(patient);
        behaviors.Add(newBehavior);
		return newBehavior;
    }
    public VitalsBehavior Copy()
    {
        VitalsBehavior vb = new VitalsBehavior();

        vb.name = name;
        vb.timeOfEffect = vb.duration = timeOfEffect;
        vb.stackable = stackable;
		vb.effectUntilTarget = effectUntilTarget;
        vb.type = type;
        vb.HR = HR;
        vb.BPDIA = BPDIA;
        vb.BPSYS = BPSYS;
        vb.SP = SP;
		vb.TEMP = TEMP;
		vb.RESP = RESP;
        vb.STOP_HR = STOP_HR;
        vb.STOP_BPDIA = STOP_BPDIA;
        vb.STOP_BPSYS = STOP_BPSYS;
        vb.STOP_SP = STOP_SP;
		vb.STOP_TEMP = STOP_TEMP;
		vb.STOP_RESP = STOP_RESP;
        vb.heartbeatMod = heartbeatMod;
        vb.heartbeatModStopAt = heartbeatModStopAt;
        vb.diastolicMod = diastolicMod;
        vb.diastolicModStopAt = diastolicModStopAt;
        vb.systolicMod = systolicMod;
        vb.systolicModStopAt = systolicModStopAt;
        vb.spo2Mod = spo2Mod;
        vb.spo2ModStopAt = spo2ModStopAt;
        vb.tempMod = tempMod;
        vb.tempModStopAt = tempModStopAt;
		vb.respirationMod = respirationMod;
		vb.respirationModStopAt = respirationModStopAt;
        vb.triggered = triggered;
		vb.heartbeatType = heartbeatType;
		vb.OnCreateCallback = OnCreateCallback;
		vb.OnRemoveCallback = OnRemoveCallback;
        vb.createEffects = new List<VBEffectLogic>();
        foreach (VBEffectLogic el in createEffects)
            vb.createEffects.Add(el);
        vb.removeEffects = new List<VBEffectLogic>();
        foreach (VBEffectLogic el in removeEffects)
            vb.removeEffects.Add(el);

        return vb;
    }