function ConditionTimer(items, conditions, actions, timer_interval, max_num_tries) {
	this.items = (isArray(items))? items: new Array(items);
	this.conditions = (isArray(conditions))? conditions: new Array(conditions);
	this.actions = actions
	this.timer_interval = timer_interval;
	this.max_num_tries = max_num_tries; // * = forever
	
	this.id = ConditionTimer.getConditionTimerID();
	ConditionTimer.timers[this.id] = this;
	
	this.timer_obj;
	this.num_tries = 0;
	this.startTimeout();
}

ConditionTimer.timers = new Array();

ConditionTimer.getConditionTimerID = function() {
	ConditionTimer.id = ++ConditionTimer.id  ||  1;
	return ConditionTimer.id;
}

ConditionTimer.prototype.startTimeout = function() {
	this.num_tries++;
	if (this.max_num_tries == -1 || this.num_tries <= this.max_num_tries) {
		this.timer_obj = setTimeout("ConditionTimer.timers["+this.id+"].checkConditions()", this.timer_interval);
	} else {
		this.destroyConditionTimer();
	}
}

ConditionTimer.prototype.checkConditions = function() {
	var num_conditions_met = 0;
	for (var i in this.items) {
		if (eval(this.items[i]) == eval(this.conditions[i])) num_conditions_met++;
	}
	if (num_conditions_met == this.items.length) {
		this.executeActions();
		this.destroyConditionTimer();
	} else {
		this.startTimeout();
	}
}

ConditionTimer.prototype.executeActions = function() {
	if (isArray(this.actions)) {
		for (var i in this.actions) {
			eval(this.actions[i]);
		}
	} else {
		eval(this.actions);
	}
}

ConditionTimer.prototype.destroyConditionTimer = function() {
	if (this.timer_obj) clearTimeout(this.timer_obj);
	ConditionTimer.timers[this.id] = null;
}

