
	// --- ic_color_class --
	
	function ic_color_class(base, info) {
		this.inheritFrom = shadow_block_class;
		this.inheritFrom();
	
		this.parent_form = null;
		this.base = base;
		this.info = info
		this.container = null;
		this.info_container = 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.whole_select = null;
	
		this.construct();
	}

	clone_add(ic_color_class.prototype, shadow_block_class.prototype); // inherit
	
	ic_color_class.prototype.construct = function() {
		this.parent_form = this.base.parentNode;
	
		this.container = document.createElement("DIV");
		this.container.className = "ic_color";
		this.container.appendChild(this.base);
		
		this.base.style.display = "block";
		this.base.className = this.base.className + " ic_color_content";
		
		this.info_container = document.createElement("DIV");
		this.info_container.className = "ic_select ic_color_list";
		
		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.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_arrow.onclick = function(trgEvent) { self.open_options();cancelEvent(trgEvent == null ? event : trgEvent, true); }
		this.a_arrow.onmousedown = function() { self.a_arrow.style.top = "6px"; }
		this.a_arrow.onmouseup = function() { self.a_arrow.style.top = "7px"; }
		this.a_arrow.onmouseout = function() { self.a_arrow.style.top = "7px"; }

		this.info_container.appendChild(this.a_middle);
		this.info.appendChild(this.info_container);
		
		this.container.onmouseover = function(trgEvent) { self.cancel_close(); }
		this.container.onmouseout = function(trgEvent) { self.close_options(trgEvent == null ? event : trgEvent); }
		
		this.parent_form.appendChild(this.container);
		
		this.a_middle.style.width = (context.get_elementWidth(this.info_container)) + "px";
		this.a_info.style.width = (context.get_elementWidth(this.info_container) - 28) + "px";
		
		var self = this;
		this.loop_trought(function(checkbox, image, col) { 
			if (checkbox.value == "#") {
				self.whole_select = checkbox;
				self.whole_select.onclick = function() {
					self.toggle_whole();
				}
				
			} else checkbox.onclick = function() {
				self.whole_select.checked = false;
				self.refresh_state();
			}
		});
		this.refresh_state();
	}
	
	ic_color_class.prototype.toggle_whole = function() {
		if (this.whole_select.checked) {
			this.loop_trought(function(checkbox, image, col) {
				if (checkbox.value != "#") checkbox.checked = false;
			});
			this.refresh_state();
		}
	}
	
	ic_color_class.prototype.refresh_state = function() {
		var self = this;
		var composed = "";
		
		if (self.whole_select.checked) composed = "všechny barvy";
		else {
			this.loop_trought(function(checkbox, image, col) {
				if (checkbox.value != "#" && checkbox.checked) {
					composed += "<img src=\"" + image.src + "\"/>";
				}
			});
		}
		
		this.a_info.innerHTML = composed;
	}
	
	ic_color_class.prototype.loop_trought = function(checkbox_func, button_func) {
		var f, current, stack = new Array();
		stack[0] = this.base;
		
		while (stack.length > 0) {
			current = stack.pop();
			
			if (checkbox_func != null && current.tagName.toUpperCase() == "INPUT" && current.type == "checkbox") {
				var first, sec, loop = current.parentNode.nextSibling;
				
				first = null;
				sec = null;
				
				while (loop != null && (first == null || sec == null)) {
					if (loop.nodeType == 1 && loop.tagName.toUpperCase() == "TD") {
						if (first == null) first = loop;
						else sec = loop;
					}
					loop = loop.nextSibling;
				}
				
				first = first.childNodes.length > 0 ? first.childNodes[0] : null;
				while (first != null && !(first.nodeType == 1 && first.tagName.toUpperCase() == "IMG"))
					first = first.nextSibling;
				
				checkbox_func(current, first, sec);
			}
			
			if (button_func != null && current.tagName.toUpperCase() == "INPUT" && current.type == "submit") {
				button_func(current);
			}
			
			if (current.childNodes.length > 0) {
				for (f = 0; f < current.childNodes.length; f++) {
					if (current.childNodes[f].nodeType == 1)
						stack[stack.length] = current.childNodes[f];
				}
			}
		}
	}
	
	ic_color_class.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_color_class.prototype.open_options = function() {
		var f, self = this;
		
		this.container.style.left = context.get_elementX(this.a_middle) + "px";
		this.container.style.top = (context.get_elementY(this.a_middle) + 24) + "px";
		this.container.style.display = "block";
		
		this.cancel_close();
		this.close_timeout = context.ic_collector.timeout(function() { self.close_options(null); }, 2000)
	}
	
	ic_color_class.prototype.close_options = function(trgEvent) {
		var target = trgEvent != null ? (trgEvent.toElement == null ? trgEvent.relatedTarget : trgEvent.toElement) : null;
		
		while (target != null && target != this.container)
			target = target.parentNode;
		
		if (target == null) {
			if (trgEvent == null) {
				// okamzite zavreni
				this.cancel_close();
				this.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_color_class.prototype.shadow_container = function() { return this.base; }
	
	ic_color_class.prototype.shadow_width = function() { return context.get_elementWidth(this.base) - 2; }
	ic_color_class.prototype.shadow_height = function() { return context.get_elementHeight(this.base) - 2; }
	
	
