	
	// --- ic_variant_list_box ---
	
	function ic_variant_list_box(parent, base, index) {
		this.parent = parent;
		this.base = base;
		this.index = index;
		
		this.nodes = new Array();
	}
	
	ic_variant_list_box.prototype.construct = function() {
		var f, add, id, pos, founded, left, right, price;
		for (f = 0; f < this.base.options.length; f++) {
			var id = this.base.options[f].id.substr(5);
			
			founded = false;
			pos = 0;
			
			while (!founded && pos < id.length)
				if (id.substr(pos, 1) == "|") founded = true;
				else pos++;
				
			left = id.substr(0, pos);
			right = id.substr(pos + 1);
			
			founded = false;
			pos = 0;
			
			while (!founded && pos < right.length)
				if (right.substr(pos, 1) == "|") founded = true;
				else pos++;
				
			price = right.substr(pos + 1);
			right = right.substr(0, pos);
				
			this.nodes[this.nodes.length] = {
				value: this.base.options[f].value,
				text: this.base.options[f].text,
				id: this.base.options[f].id,
				self: left,
				parent: right,
				price: price
			};
		}
		
		var self = this;
		this.base.onchange = function() {
			self.start_build_chain(null);
		}
		
		this.base = new ic_select(this.base);
	}
	
	ic_variant_list_box.prototype.start_build_chain = function(parent) {
		var founded, pos;
		
		if (parent != null && this.index > 0) {
			
			var f;
			for (f = this.base.options.length - 1; f >= 0; f--) {
				this.base.options[f].destroy();
				this.base.options[f] = null;
			}
			
			this.base.reset_options();
			
			var op;
			for (f = 0; f < this.nodes.length; f++) {
				if (this.nodes[f].parent == parent || this.nodes[f].self == false) {
					op = document.createElement("OPTION");
					op.value = this.nodes[f].value;
					op.text = this.nodes[f].text;
					op.id = this.nodes[f].id;
					
					this.base.options.add(op);
				}
			}
			
			if (this.base.options.length > 0) {
				founded = false;
				pos = 0;
				
				while (!founded && pos < this.base.options.length)
					if (this.base.options[pos].text == this.parent.texts[this.index]) founded = true;
					else pos++;
				
				this.base.selectedIndex = founded ? pos : 0;
				if (this.base.refresh != null) this.base.refresh();
			}
		}
		
		founded = false;
		pos = 0;
		
		while (!founded && pos < this.nodes.length)
			if (this.nodes[pos].id == this.base.options[this.base.selectedIndex].id) founded = true;
			else pos++;
			
		if (founded) {
			this.parent.texts[this.index] = this.nodes[pos].text;
			
			if (this.index + 1 < this.parent.boxes.length) {
				this.parent.boxes[this.index + 1].start_build_chain(this.nodes[pos].self);
				
			} else {
				// final
				if (this.nodes[pos].value != null && this.nodes[pos].value != "") {
					this.parent.layer_push(this.nodes[pos]);
				}
			}
		}
	}
	
	// --- ic_variant_list ---
	
	function ic_variant_list() {
	
		this.inheritFrom = shadow_block_class;
		this.inheritFrom();
		
		this.boxes = new Array();
		this.texts = new Array();
		
		this.lang = null;
		this.before_print_product_ID = null;
		this.product_layer_ID = null;
		this.product_before_layer_ID = null;
	}
	
	ic_variant_list.prototype.construct = function() {
		var self = this;
		this.reg_ident = context.ic_collector.register(this);
		
		this.boxes[0].start_build_chain();
	}
	
	ic_variant_list.prototype.add_box = function(element) {
		var ref = new ic_variant_list_box(this, element, this.boxes.length);
		this.boxes[this.boxes.length] = ref;
		this.texts[this.texts.length] = "";
		ref.construct();
		return ref;
	}
	
	ic_variant_list.prototype.cancel = function() {
	}
	
	ic_variant_list.prototype.set_layer = function(product_layer_ID, product_before_layer_ID) {
		this.product_layer_ID = product_layer_ID;
		this.product_before_layer_ID = product_before_layer_ID;
		
		alert(this.product_layer_ID + " | " + this.product_before_layer_ID);
	}
	
	ic_variant_list.prototype.set_layer_element = function(id_a, id_b) {
		tmp = document.getElementById(id_a);
		if (tmp != null && !isNaN(parseInt(tmp.value))) this.product_layer_ID = parseInt(tmp.value);
		tmp = document.getElementById(id_b);
		if (tmp != null && !isNaN(parseInt(tmp.value))) this.product_before_layer_ID = parseInt(tmp.value);
	}
	
	ic_variant_list.prototype.layer_push = function(node) {
		query_struct = new structure_class();
		query_struct.map("head/major", "shop_price");
		query_struct.map("head/lang", this.lang);
		query_struct.map("head/code_self", node.value);
		query_struct.map("head/shop_layerID", this.product_layer_ID);
		query_struct.map("head/shop_before_layerID", this.product_before_layer_ID);
		
		var self = this;
		context.request("shop_price", null, function(data, request) {
			if (self != null) self.evt_layer_push(data, request);
		}, query_struct);
	}
	
	ic_variant_list.prototype.evt_layer_push = function(data, request) {
		var res;
		if ((res = request.get_response()) != null) {
			
			var head = res[0];
			var body = res[1];
			
			var tmp, product = body.getElementsByTagName("shop_product");
			if (product.length > 0) {
				if (this.before_print_product_ID != null) document.getElementById("product_print_variant" + this.before_print_product_ID + "no").style.textDecoration = "none";
				document.getElementById("product_print_variant" + (this.before_print_product_ID = context.sub_element_value(product[0], "shop_product_ID")) + "no").style.textDecoration = "underline";
				
				tmp = document.getElementById("product_code");
				if (tmp != null) tmp.innerHTML = context.sub_element_value(product[0], "code_self");
				
				tmp = document.getElementById("product_warranty");
				if (tmp != null) tmp.innerHTML = context.sub_element_value(product[0], "productWarranty");
				
				tmp = document.getElementById("product_comment");
				if (tmp != null) {
					var cmt = context.sub_element_value(product[0], "productComment");
					tmp.innerHTML = cmt == "" ? context.sub_element_value(product[0], "productName") : cmt;
				}
				
				tmp = document.getElementById("product_store_state_simple");
				if (tmp != null) tmp.innerHTML = context.sub_element_value(product[0], "store_data");
				
				var f, ref, readable;
				for (f = 0; f < body.childNodes.length; f++) {
					if (body.childNodes[f].nodeType == 1) {
						if ((readable = context.sub_element_value(body.childNodes[f], "readable")) != null && readable != "") {
							if ((ref = document.getElementById("product_" + body.childNodes[f].nodeName)) != null)
								ref.innerHTML = readable;
						}
					}
				}
				
				var ref, image = body.getElementsByTagName("image"), pref = null;
				
				if ((ref = document.getElementById("shop_product_href_prefix")) != null) 
					pref = ref.value;
				
				for (f = 0; f < image.length; f++) {
					var key = context.sub_element_value(image[f], "key");
					var have = parseInt(context.sub_element_value(image[f], "have")) == 1;
					
					switch (key) {
						case "default" :
							ref = document.getElementById("product_image_container");
							if (ref != null) {
								ref.innerHTML = context.sub_element_value(image[f], "output_data");
							}
							break;
							
						case "other" :
							ref = document.getElementById("product_button_other");
							if (ref != null) {
								ref.style.display = have ? "block" : "none";
								ref.href = "javascript:open_window('" + pref + "/code/" + context.sub_element_value(product[0], "code_self") + "/dalsi-fotografie', 'photos" + context.sub_element_value(product[0], "shop_product_ID") + "no')";
							}
							ref = document.getElementById("product_button_zoom");
							if (ref != null) {
								ref.style.display = have ? "block" : "none";
								ref.href = "javascript:open_window('" + pref + "/code/" + context.sub_element_value(product[0], "code_self") + "/dalsi-fotografie', 'photos" + context.sub_element_value(product[0], "shop_product_ID") + "no')";
							}
							break;
							
						case "tech" :
							ref = document.getElementById("product_button_tech");
							if (ref != null) {
								ref.style.display = have ? "block" : "none";
								ref.href = "javascript:open_window('" + pref + "/code/" + context.sub_element_value(product[0], "code_self") + "/technicke-udaje', 'tech" + context.sub_element_value(product[0], "shop_product_ID") + "no')";
							}
							break;
					}
				}
			}
			
		}
	}
	