
	// --- ic_collector class ---
	
	function ic_collector(context) {
		this.context = context;
		this.items = new Array();
		this.timeouts = new Array();
		
		this.reg_ident_max = 0;
		this.timeout_max = 0;
		
		this.construct();
	}
	
	ic_collector.prototype.construct = function() {
		var self = this;
		addEvent(this.context.document_ref, "click", function() { self.cancel() });
		addEvent(this.context.document_ref, "mousemove", function(trgEvent) { self.motion(trgEvent == null ? event : trgEvent); });
		addEvent(this.context.document_ref, "mouseup", function(trgEvent) { self.mouseup(trgEvent == null ? event : trgEvent); });
	}
	
	ic_collector.prototype.motion = function(trgEvent) {
		var f;
		for (f = 0; f < this.items.length; f++)
			if (this.items[f].global_evt_motion != null) this.items[f].global_evt_motion(trgEvent);
	}
	
	ic_collector.prototype.mouseup = function(trgEvent) {
		var f;
		for (f = 0; f < this.items.length; f++)
			if (this.items[f].global_evt_mouseup != null) this.items[f].global_evt_mouseup(trgEvent);
	}
	
	ic_collector.prototype.cancel = function() {
		var f;
		for (f = 0; f < this.items.length; f++)
			if (this.items[f].cancel != null) this.items[f].cancel();
	}
	
	ic_collector.prototype.timeout = function(func, time) {
		this.timeout_max++;
		var index = this.timeout_max;
	
		this.timeouts[this.timeouts.length] = new Array(
			index,
			func,
			setTimeout("context.ic_collector.timeout_done(" + index + ")", time)
		);
		
		return index;
	}
	
	ic_collector.prototype.timeout_get = function(index) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.timeouts.length)
			if (this.timeouts[pos][0] == index) founded = true;
			else pos++;
			
		return founded ? pos : -1;
	}
	
	ic_collector.prototype.timeout_done = function(index) {
		var pos, f;
		if ((pos = this.timeout_get(index)) != -1) {
			
			var func = this.timeouts[pos][1];
			func();
			
			for (f = pos; f < this.timeouts.length - 1; f++)
				this.timeouts[f] = this.timeouts[f + 1];
			this.timeouts.pop();
		}
		
		return false;
	}
	
	ic_collector.prototype.timeout_stop = function(index) {
		var pos, f;
		if ((pos = this.timeout_get(index)) != -1) {
		
			clearTimeout(this.timeouts[pos][2]);
			
			for (f = pos; f < this.timeouts.length - 1; f++)
				this.timeouts[f] = this.timeouts[f + 1];
			this.timeouts.pop();
			
			return true;
		}
		
		return false;
	}
	
	ic_collector.prototype.register = function(ref) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.items.length)
			if (this.items[pos] === ref) founded = true;
			else pos++;
			
		if (!founded) {
			this.items[this.items.length] = ref;
			this.reg_ident_max++;
			return this.reg_ident_max;
		}
		
		return false;
	}
	
	ic_collector.prototype.unregister = function(ref) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.items.length)
			if (this.items[pos] === ref) founded = true;
			else pos++;
			
		if (founded) {
			var f;
			for (f = pos; f < this.items.length - 1; f++)
				this.items[f] = this.items[f + 1];
			this.items.pop();
			return true;
		}
		
		return false;
	}
