	
	// --- ic_select_class ---
	
	function ic_select(base) {
	
		//this.inheritFrom = shadow_block_class;
		//this.inheritFrom();
	
		this.reg_ident = null;
		this.base = base;
		this.container = null;
		this.control = null;
		this.option_container = null;
		this.option_container_content = null;
		
		this.a_left = null;
		this.a_right = null;
		this.a_middle = null;
		this.a_info = null;
		this.a_arrow = null;
		
		this.close_timeout = null;
		this.id = null;
		this.options = null;
		this.selectedIndex = null;
		
		this.onclick = null;
		this.onchange = null;
		
		this.construct();
	}
	
	//clone_add(ic_select.prototype, shadow_block_class.prototype); // inherit
	
	ic_select.prototype.construct = function() {
		var self = this;
		this.reg_ident = context.ic_collector.register(this);
		
		this.container = this.base.parentNode;
		
		this.control = context.createElement("INPUT");
		this.control.type = "hidden";
		this.control.name = this.base.name;
		this.control.id = this.base.id;
		
		this.a_left = context.createElement("DIV");
		this.a_right = context.createElement("DIV");
		this.a_middle = context.createElement("DIV");
		this.a_info = context.createElement("DIV");
		this.a_arrow = context.createElement("DIV");
		
		this.a_left.className = "ic_left";
		this.a_right.className = "ic_right";
		this.a_middle.className = "ic_select";
		this.a_info.className = "ic_info";
		this.a_arrow.className = "ic_arrow";
		
		this.a_middle.style.width = (context.get_elementWidth(this.base) + 25) + "px";
		this.a_info.style.width = (context.get_elementWidth(this.base) - 5) + "px";
		this.a_info.onclick = this.a_arrow.onclick = this.a_right.onclick = this.container.onclick = function(trgEvent) { self.open_options();cancelEvent(trgEvent == null ? event : trgEvent, true); }
		
		this.a_middle.appendChild(this.a_left);
		this.a_middle.appendChild(this.a_right);
		this.a_middle.appendChild(this.a_info);
		this.a_middle.appendChild(this.a_arrow);
		
		this.a_info.onmousedown = this.a_arrow.onmousedown = this.a_right.onmousedown = this.container.onmousedown = function() { self.a_arrow.style.top = "6px"; }
		this.a_info.onmouseup = this.a_arrow.onmouseup = this.a_right.onmouseup = this.container.onmouseup = function() { self.a_arrow.style.top = "7px"; }
		this.a_info.onmouseout = this.a_arrow.onmouseout = this.a_right.onmouseout = this.container.onmouseout = function() { self.a_arrow.style.top = "7px"; }
		
		this.option_container = context.createElement("DIV");
		this.option_container.className = "ic_options";
		
		this.option_container_content = context.createElement("DIV");
		
		var inner = "";
		inner += "<span class=\"ic_left_top\">&nbsp;</span>";
		inner += "<span class=\"ic_right_top\">&nbsp;</span>";
		inner += "<span class=\"ic_left_bottom\">&nbsp;</span>";
		inner += "<span class=\"ic_right_bottom\">&nbsp;</span>";
		
		this.option_container_content.className = "ic_options_content";
		this.option_container_content.innerHTML = inner;
		
		this.option_container.appendChild(this.option_container_content);
		
		this.id = this.base.id;
		this.reset_options();
		this.selectedIndex = this.base.selectedIndex;
		
		var f, opt;
		for (f = 0; f < this.base.options.length; f++) {
			opt = new ic_select_option(this, this.base.options[f].value, this.base.options[f].text, this.base.options[f].id);
			opt.index = f;
			this.options[this.options.length] = opt;
			opt.construct();
		}
		
		this.select(this.options[this.selectedIndex]);
		
		this.onclick = this.base.onclick;
		this.onchange = this.base.onchange;
		
		this.option_container_content.style.width = ((context.get_elementWidth(this.base) + 25) * 2) + "px";
		this.option_container_content.style.height = (this.options.length * 25) + "px";
		
		this.option_container.onmouseover = function(trgEvent) { self.cancel_close(); }
		this.option_container.onmouseout = function(trgEvent) { self.close_options(trgEvent == null ? event : trgEvent); }
		
		this.container.onmouseover = function(trgEvent) { self.cancel_close(); }
		this.container.onmouseout = function(trgEvent) { self.close_options(trgEvent == null ? event : trgEvent); }
		
		this.container.removeChild(this.base);
		this.container.appendChild(this.a_middle);
		this.container.appendChild(this.control);
		context.document_ref.body.appendChild(this.option_container);
	}
	
	ic_select.prototype.reset_options = function() {
		var self = this;
		this.options = new Array();
		this.option_container_content.style.height = (this.options.length * 25) + "px";
		this.selectedIndex = 0;
		
		this.options.add = function(input) {
			var opt = new ic_select_option(self, input.value, input.text, input.id);
			opt.index = self.options.length;
			self.options[self.options.length] = opt;
			opt.construct();
			
			self.refresh();
			self.option_container_content.style.height = (self.options.length * 25) + "px";
		}
	}
	
	ic_select.prototype.cancel = function() {
		// vola ic_collector - zrusi cinnost inputu
		this.close_options(null);
	}
	
	ic_select.prototype.cancel_close = function() {
		var self = this;
		if (this.close_timeout != null) {
			if (context.ic_collector.timeout_stop(this.close_timeout))
				this.close_timeout = null;
		}
	}
	
	ic_select.prototype.open_options = function() {
		var f, self = this;
		
		context.ic_collector.cancel();
		
		this.option_container.style.left = (context.get_elementX(this.a_middle) - 3) + "px";
		this.option_container.style.top = (context.get_elementY(this.a_middle) + 24) + "px";
		this.option_container.style.display = "block";
		
		for (f = 0; f < this.options.length; f++)
			this.options[f].update_style("default");
		
		//this.shadows_build();
		
		this.cancel_close();
	}
	
	ic_select.prototype.close_options = function(trgEvent) {
		var target = trgEvent != null ? (trgEvent.toElement == null ? trgEvent.relatedTarget : trgEvent.toElement) : null;
		
		while (target != null && target != this.option_container)
			target = target.parentNode;
			
		if (target == null) {
			if (trgEvent == null) {
				// okamzite zavreni
				this.cancel_close();
				this.option_container.style.display = "none";
				
			} else {
				// pockani na zavreni
				var self = this;
				this.close_timeout = context.ic_collector.timeout(function() { self.close_options(null); }, 1000);
			}
		}
	}
	
	ic_select.prototype.select = function(ref) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.options.length)
			if (this.options[pos] === ref) founded = true;
			else pos++;
		
		if (founded) {
			var changed = false;
			this.close_options(null);
			
			if (changed = (this.selectedIndex != pos)) {
				this.selectedIndex = pos;
			}
			
			this.refresh();
			
			if (changed && this.onchange != null) this.onchange();
			if (this.onclick != null) this.onclick();
		}
	}
	
	ic_select.prototype.refresh = function() {
		if (this.selectedIndex < 0 || this.selectedIndex >= this.options.length) this.selectedIndex = 0;
		this.a_info.innerHTML = this.options[this.selectedIndex].text;
		this.control.value = this.options[this.selectedIndex].value;
	}
	
	//ic_select.prototype.shadow_container = function() { return this.option_container; }
	
	//ic_select.prototype.shadow_width = function() { return context.get_elementWidth(this.option_container); }
	//ic_select.prototype.shadow_height = function() { return context.get_elementHeight(this.option_container); }
	
	// --- ic_select_option class ---
	
	function ic_select_option(parent, value, text, id) {
		this.parent = parent;
		this.container = null;
		
		this.index = null;
		this.value = value;
		this.text = text;
		this.id = id;
	}
	
	ic_select_option.prototype.construct = function() {
		var self = this;
		this.container = context.createElement("DIV");
		this.container.className = "ic_option";
		this.container.innerHTML = "<span>" + this.text + "</span>";
		
		this.container.onmouseover = function() { self.update_style("hover"); }
		this.container.onmouseout = function() { self.update_style("default"); }
		
		this.container.onmousedown = function() { self.update_style("active"); }
		this.container.onmouseup = function() { self.update_style("hover"); }
		
		this.container.onclick = function(trgEvent) { self.select();cancelEvent(trgEvent == null ? event : trgEvent, true); }
		
		this.parent.option_container_content.appendChild(this.container);
	}
	
	ic_select_option.prototype.destroy = function() {
		context.structure_destroy(this.container);
		context.object_destroy(this);
	}
	
	ic_select_option.prototype.select = function() {
		this.parent.select(this);
	}
	
	ic_select_option.prototype.update_style = function(flag) {
		var put = "ic_option";
		if (this.index == this.parent.selectedIndex) put += " ic_option_current";
		
		switch (flag) {
			case "active" : put += " ic_option_active"; break;
			case "hover" : put += " ic_option_hover"; break;
		}
		
		this.container.className = put;
	}


