	
	// --- cart_panel_item_class ---
	
	function cart_panel_item_class(title, param, code, price, count, image, href) {
		this.parent = null;
		this.title = title;
		this.param = param;
		this.code = code;
		this.price = price;
		this.count = count;
		this.image = image;
		this.href = href;
		
		this.container = null;
		this.img_container = null;
		this.img_href = null;
		this.img = null;
		this.table = null;
		this.tbody = null;
		this.params = new Array();
	}
	
	cart_panel_item_class.prototype.construct = function() {
		
		this.container = document.createElement("DIV");
		this.container.className = "iblock";
		
		this.img_container = document.createElement("DIV");
		this.img_container.className = "img";
		
		if (this.image != "") {
			this.img_href = document.createElement("A");
			this.img_href.href = this.href;
		
			this.img = document.createElement("IMG");
			this.img.src = "/" + this.image;
			
			this.img_href.appendChild(this.img);
			this.img_container.appendChild(this.img_href);
		}
		
		this.table = document.createElement("TABLE");
		this.tbody = document.createElement("TBODY");
		
		this.table.appendChild(this.tbody);
		
		if (this.title != "") this.add_param("<a href=\"" + this.href + "\">" + this.title + "</a>");
		if (this.param != null && this.param != "") this.add_param("Design", this.param);
		this.add_param("Kód", this.code, true);
		this.add_param("Cena", this.price);
		this.add_param("Kusů", this.count);
		
		this.container.appendChild(this.img_container);
		this.container.appendChild(this.table);
		
		this.parent.container_content.appendChild(this.container);
	}
	
	cart_panel_item_class.prototype.destroy = function() {
		context.structure_destroy(this.container);
		context.object_destroy(this);
	}
	
	cart_panel_item_class.prototype.add_param = function(first, sec, bold) {
		var tr = document.createElement("TR");
		
		if (sec == null) {
			var td = document.createElement("TD");
			td.className = "main";
			td.colSpan = 2;
			td.innerHTML = "<strong>" + first + "</strong>";
			
			tr.appendChild(td);
			
		} else {
			var tdA = document.createElement("TD");
			var tdB = document.createElement("TD");
			
			tdA.innerHTML = first;
			tdA.className = "first";
			tdB.innerHTML = sec;
			if (bold) tdB.className = "sec";
			
			tr.appendChild(tdA);
			tr.appendChild(tdB);
		}
		
		this.params[this.params.length] = tr;
		this.tbody.appendChild(tr);
		return tr;
	}
	
	// --- cart_panel_class --- 
	
	function cart_panel_class() {
		this.container = null;
		this.container_content = null;
		
		this.items = new Array();
		this.lang = null;
		
		this.opened = false;
		this.active = false;
		this.mousetoggle = false;
		this.lock = false;
		this.position = 0;
		this.counter_top = 65;
		this.counter = 0;
		this.button = null;
		
		this.cart_button = null;
		this.cart_code = null;
		this.cart_count = null;
		
		this.cart_panel_title = null;
		this.cart_panel_info = null;
		this.cart_panel_info2 = null;
		this.cart_panel_price = null;
		this.cart_panel_price2 = null;
	}
	
	cart_panel_class.prototype.construct = function(container, container_content, cart_button, cart_code, cart_count, cart_panel_title, cart_panel_info, cart_panel_info2, cart_panel_price, cart_panel_price2) {
		var self = this;
		
		this.cart_panel_title = cart_panel_title;
		this.cart_panel_info = cart_panel_info;
		this.cart_panel_info2 = cart_panel_info2;
		this.cart_panel_price = cart_panel_price;
		this.cart_panel_price2 = cart_panel_price2;
		
		this.container = container;
		this.container.style.height = "28px";
		
		this.container_content = container_content;
		
		this.button = document.createElement("INPUT");
		this.button.type = "button";
		this.button.value = context.trans("Dokončit nákup");
		this.button.className = "button_high";
		this.button.style.display = "none";
		
		this.container.appendChild(this.button);
		
		this.container.onmouseover = function(trgEvent) { if (self.o_ds == null) self.evt_onmouseover(trgEvent == null ? event : trgEvent); }
		this.container.onmouseout = function(trgEvent) { if (self.o_ds == null) self.evt_onmouseout(trgEvent == null ? event : trgEvent); }
		this.button.onclick = function(trgEvent) { if (self.o_ds == null) self.evt_click(trgEvent == null ? event : trgEvent); }
		
		if (cart_button != null && cart_code != null && cart_count != null) {
			this.cart_button = cart_button;
			this.cart_code = cart_code;
			this.cart_count = cart_count;
			
			var loop = cart_button.parentNode;
			while (loop != null && loop.tagName.toUpperCase() != "FORM") loop = loop.parentNode;
			
			if (loop != null) {
				loop.onsubmit = function(trgEvent) {
					if (self.o_ds == null) {
						cancelEvent(trgEvent == null ? event : trgEvent, true);
						return false;
					}
					return true;
				}
				this.cart_button.onclick = function(trgEvent) {
					if (self.o_ds == null) self.evt_cart_click(trgEvent == null ? event : trgEvent);
				}
				
			} else this.cart_button = null;
		}
	}
	
	cart_panel_class.prototype.cleanup = function() {
		var f;
		for (f = 0; f < this.items.length; f++)
			this.items[f].destroy();
		this.items = new Array();
	}
	
	cart_panel_class.prototype.add = function(ref) {
		this.items[this.items.length] = ref;
		ref.parent = this;
		ref.construct();
		if (this.items.length == 1) ref.container.style.marginTop = "10px";
		return ref;
	}
	
	cart_panel_class.prototype.evt_onmouseover = function(trgEvent) {
		if (!this.active) {
			this.active = true;
			this.opened = true;
			this.counter = 0;
			this.mousetoggle = true;
			
			if (this.items.length == 0) this.request(null, null, false);
		}
	}
	
	cart_panel_class.prototype.evt_onmouseout = 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) {
			this.active = false;
			this.counter = this.mousetoggle ? 1 : 50;
		}
	}
	
	cart_panel_class.prototype.evt_click = function(trgEvent) {
		var founded = false;
		var pos = 0;
		
		while (!founded && this.cart_panel_title.childNodes.length)
			if (this.cart_panel_title.childNodes[pos].tagName.toUpperCase() == "A") founded = true;
			else pos++;
		
		if (founded) {
			this.counter = 0;
			document.location.href = this.cart_panel_title.childNodes[pos].href;
		}
	}
	
	cart_panel_class.prototype.evt_cart_click = function(trgEvent) {
		var t_code = null;
		
		if (this.cart_code.tagName.toUpperCase() == "SELECT") t_code = this.cart_code.options[this.cart_code.selectedIndex].value;
		else t_code = this.cart_code.value;
		
		window.scrollTo(0, 0);
		
		if (t_code != "" && t_code != null) this.request(t_code, this.cart_count.value, true);
		else {
			var e_cnt = document.createElement("DIV");
			var e_wnd = new error_wnd();
			e_wnd.construct(e_cnt, "pokračovat", "<ul><li><strong>Produkt se nezdařilo vložit do košíku!</strong></li><li>Vyberte nejdříve variantu produktu.</li></ul>");
		}
	}
	
	cart_panel_class.prototype.request = function(code_self, count, force) {
		if (!this.lock || force) {
			this.lock = true;
			var self = this;
			var struct = new structure_class();
			
			if (this.cart_button != null) this.cart_button.disabled = true;
			if (this.cart_count != null) this.cart_count.disabled = true;
			
			struct.map("head/major", "shop_cart");
			struct.map("head/pnc_language", this.lang);
			
			if (code_self != null && count != null) {
				struct.map("head/method", "set");
				struct.map("head/code_self", code_self);
				struct.map("head/count", count);
			} else {
				struct.map("head/method", "get");
			}
			
			context.request("shop_cart", null, function(data, request) {
				if (self.o_ds == null) self.evt_request(data, request);
			}, struct);
		}
	}
	
	cart_panel_class.prototype.evt_request = function(data, request) {
		
		var res;
		if ((res = request.get_response()) != null) {
			
			var head = res[0];
			var body = res[1];
			
			var ref, f, method, el = head.getElementsByTagName("method");
			if (el.length > 0) {
				method = context.element_value(el[0]);
			}
			
			switch (method) {
				case "set" :
				case "get" :
					if (method == "set") this.cleanup();
					
					el = body.getElementsByTagName("shop_product");
					
					if (el.length > 0) {
						var p_design, p_serie;
						
						for (f = 0; f < el.length; f++) {
							p_design = context.sub_element_value(el[f], "param_design");
							p_serie = context.sub_element_value(el[f], "param_serie");
							
							ref = new cart_panel_item_class(
								method == "set" ? "Poslední vložený produkt" : context.sub_element_value(el[f], "productName"),
								p_design == "" ? p_serie : p_design,
								context.sub_element_value(el[f], "code_self"),
								context.sub_element_value(el[f], "price_readable"),
								context.sub_element_value(el[f], "count"),
								context.sub_element_value(el[f], "imageSource"),
								context.sub_element_value(el[f], "href")
							);
							this.add(ref);
						}
						
						this.open();
					}
					
					el = body.getElementsByTagName("cart");
					
					if (el.length > 0) {
						this.cart_panel_info.style.display = "block";
						this.cart_panel_info2.style.display = "block";
						this.cart_panel_price.style.display = "block";
						this.cart_panel_price2.style.display = "block";
						
						var tmp = this.get_strong(this.cart_panel_price);
						if (tmp != null) tmp.innerHTML = context.sub_element_value(el[0], "cart_count_total");
						
						var tmp = this.get_strong(this.cart_panel_price2);
						if (tmp != null) tmp.innerHTML = context.sub_element_value(el[0], "price_readable");
					}
					
					if (this.cart_button != null) this.cart_button.disabled = false;
					if (this.cart_count != null) this.cart_count.disabled = false;
					
					this.lock = false;
					break;
					
				default :
					context.error("Unknown method `" + method + "`");
					break;
			}
		}
		
	}
	
	cart_panel_class.prototype.get_strong = function(el) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < el.childNodes.length)
			if (el.childNodes[pos].nodeType == 1 && el.childNodes[pos].tagName.toUpperCase() == "STRONG") founded = true;
			else pos++;
		
		return founded ? el.childNodes[pos] : null;
		//if (founded) el.childNodes[pos].innerHTML = count;
	}
	
	cart_panel_class.prototype.open = function() {
		this.opened = true;
		this.counter = this.counter_top;
	}
	
	cart_panel_class.prototype.close = function() {
		if (this.opened) {
			this.opened = false;
			this.mousetoggle = false;
		}
	}
	
	cart_panel_class.prototype.do_motion = function() {
		var reach, inc;
		
		reach = this.opened ? (this.items.length * 143 + (this.items.length > 0 ? 25 : 0) + (this.items.length > 0 ? 10 : 0)) : 0;
		
		if (this.position != reach) {
			if (this.opened) inc = ((reach - this.position) / 6) + 0.5;
			else inc = ((reach - this.position) / 10) - 0.5;
			
			this.position += inc;
			if (this.position < 0) this.position = 0;
			else if (this.opened && this.position > reach) this.position = reach;
			this.container.style.height = (28 + this.position) + "px";
			this.container_content.style.height = this.position + "px";
			this.container_content.style.display = this.position != 0 ? "block" : "none";
			this.button.style.display = this.position > 40 ? "block" : "none";
		}
		
		if (this.opened) {
			this.counter--;
			if (this.counter == 0) this.close();
		}
	}
	
