	
	// --- ic_range_box_class --
	
	function ic_range_box(parent, type) {
		this.parent = parent;
		this.type = type;
		
		this.container = null;
		this.info = null;
		this.before_position = -1;
		this.position = 0;
	}
	
	ic_range_box.prototype.construct = function() {
		var self = this;
		this.container = document.createElement("DIV");
		this.container.className = this.type == 0 ? "slide_left" : "slide_right";
		this.container.ondragstart = function(trgEvent) { return false; }
		this.container.onselectstart = function(trgEvent) { return false; }
		this.container.onmousedown = function(trgEvent) { self.evt_mousedown(trgEvent == null ? event : trgEvent); }
		this.container.onmouseup = function(trgEvent) { self.evt_mouseup(trgEvent == null ? event : trgEvent); }
		this.container.onmousemove = function(trgEvent) { self.evt_motion(trgEvent == null ? event : trgEvent); }
		
		this.container.onmouseover = function() { self.evt_over(); }
		this.container.onmouseout = function() { self.evt_out(); }
		
		this.info = document.createElement("DIV");
		this.info.innerHTML = "blabla";
		this.info.onmousemove = function(trgEvent) { self.evt_motion(trgEvent == null ? event : trgEvent); }
		
		this.container.appendChild(this.info);
		
		this.parent.area.appendChild(this.container);
	}
	
	ic_range_box.prototype.is_active = function() {
		return this.parent.slide_motion == this;
	}
	
	ic_range_box.prototype.activate = function() {
		//this.info.style.display = "block";
	}
	
	ic_range_box.prototype.deactivate = function() {
		//this.info.style.display = "none";
	}
	
	ic_range_box.prototype.evt_over = function() {
		if (!this.is_active()) {
			this.update_info();
			//this.info.style.display = "block";
		}
	}
	
	ic_range_box.prototype.evt_out = function() {
		if (!this.is_active()) {
			//this.info.style.display = "none";
		}
	}
	
	ic_range_box.prototype.evt_mousedown = function(trgEvent) {
		this.parent.slide_drag_x = context.layerX(trgEvent, context.get_elementX(this.container));
		this.parent.slide_motion = this;
		this.touch();
		this.activate();
		
		cancelEvent(trgEvent, true);
	}
	
	ic_range_box.prototype.evt_mouseup = function(trgEvent) {
		this.parent.evt_mouseup(trgEvent);
	}
	
	ic_range_box.prototype.evt_motion = function(trgEvent) {
		this.parent.evt_motion(trgEvent);
	}
	
	ic_range_box.prototype.set_position = function(pos, drag) {
		this.position = pos - drag + (this.type == 1 ? -this.parent.slide_size : 0);
		this.touch();
	}
	
	ic_range_box.prototype.update_info = function() {
		if (this.type == 1) {
			this.info.innerHTML = this.parent.get_value(this.parent.slide_right.position);
		} else {
			this.info.innerHTML = this.parent.get_value(this.parent.slide_left.position);
		}
		//this.info.innerHTML = this.parent.info_container.innerHTML + "<br/>" + this.parent.get_value(this.parent.slide_left.position) + " - " + this.parent.get_value(this.parent.slide_right.position);
	}
	
	ic_range_box.prototype.touch = function() {
		if (this.position < 0) this.position = 0;
		else if (this.position > this.parent.area_size) this.position = this.parent.area_size;
		
		if (this.type == 0) {
			if (this.position > this.parent.slide_right.position) this.position = this.parent.slide_right.position;
		} else {
			if (this.position < this.parent.slide_left.position) this.position = this.parent.slide_left.position;
		}
		
		this.update_info();
		
		if (this.position != this.before_position) {
			this.before_position = this.position;
			
			this.container.style.left = (this.position + (this.type == 0 ? 0 : this.parent.slide_size)) + "px";
			this.parent.touch();
		}
	}
	
	// --- ic_range_class ---
	
	function ic_range(base, area_size, slide_min, slide_max, slide_step) {
	
		this.inheritFrom = shadow_block_class;
		this.inheritFrom();
	
		this.reg_ident = null;
		this.base = base;
		this.change_event = null;
		
		this.field_from = null;
		this.field_to = null;
		
		this.info_container = null;
		
		this.area_container = null;
		this.area_left = null;
		this.area_right = null;
		this.area_bg = null;
		this.area = null;
		this.area_btw = null;
		this.area_size = area_size;
		
		this.slide_size = 56;
		this.slide_min = slide_min
		this.slide_max = slide_max;
		this.slide_step = slide_step;
		
		this.slide_left = null;
		this.slide_right = null;
		
		this.slide_motion = null;
		this.slide_drag_x = null;
		
		this.construct();
	}
	
	ic_range.prototype.construct = function() {
		
		var self = this;
		this.reg_ident = context.ic_collector.register(this);
		
		var td_num = 0, f, current, stack = new Array();
		stack[0] = this.base;
		
		while (stack.length > 0) {
			current = stack.pop();
			
			switch (current.tagName.toUpperCase()) {
				case "INPUT" :
					if (current.type == "text") {
						if (this.field_from == null) this.field_from = current;
						else if (this.field_to == null) this.field_to = current;
					}
					break;
					
				case "TD" :
					td_num++;
					if (td_num == 1) this.info_container = current;
					else if (td_num == 3) this.area_container = current;
					break;
			}
			
			for (f = current.childNodes.length - 1; f >= 0; f--)
				if (current.childNodes[f].nodeType == 1) stack[stack.length] = current.childNodes[f];
		}
		
		var tmp = document.createElement("INPUT");
		tmp.type = "hidden";
		tmp.name = this.field_from.name;
		tmp.value = this.field_from.value;
		this.field_from.parentNode.appendChild(tmp);
		
		context.structure_destroy(this.field_from);
		this.field_from = tmp;
		
		var tmp = document.createElement("INPUT");
		tmp.type = "hidden";
		tmp.name = this.field_to.name;
		tmp.value = this.field_to.value;
		this.field_to.parentNode.appendChild(tmp);
		
		
		context.structure_destroy(this.field_to);
		this.field_to = tmp;
		
		this.area_container.innerHTML = "";
		
		this.area = document.createElement("DIV");
		this.area.innerHTML = "";
		this.area.style.width = (this.area_size + 2 * this.slide_size) + "px";
		this.area.className = "ic_range";
		this.area.ondragstart = function(trgEvent) { return false; }
		this.area.onselectstart = function(trgEvent) { return false; }
		this.area.onmouseup = function(trgEvent) { self.evt_mouseup(trgEvent == null ? event : trgEvent); }
		this.area.onmousemove = function(trgEvent) { self.evt_motion(trgEvent == null ? event : trgEvent); }
		
		this.area_left = document.createElement("SPAN");
		this.area_left.className = "ic_area_left";
		
		this.area_right = document.createElement("SPAN");
		this.area_right.className = "ic_area_right";
		
		this.area_bg = document.createElement("DIV");
		this.area_bg.className = "ic_area_bg";
		
		this.area.appendChild(this.area_left);
		this.area.appendChild(this.area_right);
		this.area.appendChild(this.area_bg);
		
		this.area_container.appendChild(this.area);
		
		this.area_btw = document.createElement("DIV");
		this.area_btw.className = "btw";
		
		this.area.appendChild(this.area_btw);
		
		this.slide_left = new ic_range_box(this, 0);
		this.slide_right = new ic_range_box(this, 1);
		
		this.slide_left.construct();
		this.slide_right.construct();
		
		var num_left = this.get_num(this.field_from);
		var num_right = this.get_num(this.field_to);
		this.slide_left.position = this.get_position(num_left == null ? this.slide_min : num_left);
		this.slide_right.position = this.get_position(num_right == null ? this.slide_max : num_right)
		
		this.slide_left.touch();
		this.slide_right.touch();
	}
	
	ic_range.prototype.get_num = function(field) {
		var val = parseInt(field.value);
		return isNaN(val) ? null : val;
	}
	
	ic_range.prototype.get_value = function(position) {
		if (position <= 0) return this.slide_min;
		else if (position >= this.area_size) return this.slide_max;
	
		var value = (position / this.area_size) * (this.slide_max - this.slide_min) + this.slide_min;
		return Math.round(value / this.slide_step) * this.slide_step;
	}
	
	ic_range.prototype.get_position = function(value) {
		if (value <= this.slide_min) return 0;
		else if (value >= this.slide_max) return this.area_size;
		
		var pos = ((value - this.slide_min) / (this.slide_max - this.slide_min)) * this.area_size;
		return Math.round(pos);
	}
	
	ic_range.prototype.touch = function() {
		var diff = this.slide_right.position - this.slide_left.position;
		this.area_btw.style.width = diff + "px";
		this.area_btw.style.left = (this.slide_left.position + this.slide_size) + "px";
		
		this.field_from.value = this.get_value(this.slide_left.position);
		this.field_to.value = this.get_value(this.slide_right.position);
	}
	
	ic_range.prototype.get_values = function() {
		return new Array(
			this.field_from.value,
			this.field_to.value
		);
	}
	
	ic_range.prototype.global_evt_mouseup = function(trgEvent) { this.evt_mouseup(trgEvent); }
	ic_range.prototype.global_evt_motion = function(trgEvent) { this.evt_motion(trgEvent); }
	
	ic_range.prototype.evt_mouseup = function(trgEvent) {
		if (this.slide_motion != null) {
			var tmp = this.slide_motion;
			this.slide_motion = null;
			tmp.deactivate();
			this.evt_change();
		}
	}
	
	ic_range.prototype.evt_motion = function(trgEvent) {
		if (this.slide_motion != null) {
			//var pos = context.layerX(trgEvent, context.get_elementX(this.area));
			var pos = trgEvent.clientX - context.get_elementX(this.area);
			this.slide_motion.set_position(pos, this.slide_drag_x);
			
			cancelEvent(trgEvent, true);
		}
	}
	
	ic_range.prototype.evt_change = function(ref) {
		if (this.change_event != null)
			this.change_event(this, ref);
	}
	
