
	// --- list_item_class ---

	function list_item_class(parent, container) {
		this.parent = parent;
		this.container = container;
		
		this.productID = null;
		this.productName = null;
		this.productNameAlt = null;
		this.productUrl = null;
		this.productSpecial = null;
		this.imageSource = null;
		this.price = null;
		this.link_prefix = null;
	}
	
	list_item_class.prototype.loc_href = function(input, offset) {
		var pos, rpos, lpos;
		
		if ((pos = input.indexOf("/", 8)) != -1) {
		
	        var lang = false;
	        if ((lpos = input.indexOf("/", pos + 1)) != -1 && lpos - pos == 3) {
	            var tmp = input.substr(pos + 1, lpos - pos - 1);
	            
	            switch (tmp) {
	                case 'sk' :
	                case 'cs' :
	                case 'en' :
	                case 'de' :
	                    lang = tmp;
	                    input = input.substr(0, pos) + input.substr(lpos);
	                    break;
                }
            }
    		
			if ((rpos = input.lastIndexOf("/")) != -1) {
				offset--;
				
				while (offset > 0 && rpos != -1) {
					rpos = input.substr(0, rpos - 1).lastIndexOf("/");
					offset--;
				}
			    
				if (rpos != -1)
					return input.substr(0, pos + 1) + (lang != false ? (lang + "/") : "") + input.substr(rpos + 1) + "?shop_loc=" + input.substr(pos + 1, rpos - pos - 1).replace('?', '&');
			}
		} 
		
		return input;
	}
	
	list_item_class.prototype.construct = function() {
		if (this.container == null) {
			this.container = document.createElement("DIV");
			this.container.className = "item_list_node";
			
			var img_href = document.createElement("A");
			
			if (this.link_prefix != null) img_href.href = this.loc_href(this.link_prefix + this.productUrl + (this.parent.link_suffix != null ? this.parent.link_suffix : ""), this.parent.shop_loc_offset) + (this.parent.link_leaf_suffix != null ? this.parent.link_leaf_suffix : "");
			else if (this.parent.add_suffix) img_href.href = this.loc_href(this.parent.link_prefix + this.productUrl + (this.parent.link_suffix != null ? this.parent.link_suffix : ""), this.parent.shop_loc_offset) + (this.parent.link_leaf_suffix != null ? this.parent.link_leaf_suffix : "");
			else img_href.href = this.loc_href(this.parent.link_prefix.substr(0, this.parent.link_prefix.length - 1) + (this.parent.link_suffix != null ? this.parent.link_suffix : ""), this.parent.shop_loc_offset) + (this.parent.link_leaf_suffix != null ? this.parent.link_leaf_suffix : "");
			img_href.title = this.productNameAlt == null ? this.productName : this.productNameAlt;
			
			var img = document.createElement("IMG");
			img.src = "/" + (this.imageSource == "" ? "data/bg_normal.jpg" : this.imageSource);
			img.alt = this.productNameAlt == null ? this.productName : this.productNameAlt;
			
			var info = document.createElement("DIV");
			info.className = "info";
			
			img_href.appendChild(img);
			
			this.container.appendChild(img_href);
			this.container.appendChild(info);
			
			if (this.productSpecial != "" && this.productSpecial != false) {
			    var f, specs = this.productSpecial.split("|");
			    
			    for (f = 0; f < specs.length; f++) {
			        switch (specs[f]) {
				        case "action" :
					        var special = document.createElement("SPAN");
					        special.className = "product_ico product_icosm_action";
					        this.container.appendChild(special);
					
					        make_bubble(context.trans("Akční nabídka"), special, null, "deflist_box deflist_box_small");
					        break;
					
				        case "dop" :
					        var special = document.createElement("SPAN");
					        special.className = "product_ico product_icosm_dop";
					        this.container.appendChild(special);
					
					        make_bubble(context.trans("Doporučujeme"), special, null, "deflist_box deflist_box_small");
					        break;
					
				        case "tip" :
					        var special = document.createElement("SPAN");
					        special.className = "product_ico product_icosm_tip";
					        this.container.appendChild(special);
					
					        make_bubble(context.trans("Náš tip"), special, null, "deflist_box deflist_box_small");
					        break;
			        }
			    }
			}
			
			var href = document.createElement("A");
			if (this.link_prefix != null) href.href = this.loc_href(this.link_prefix + this.productUrl + (this.parent.link_suffix != null ? this.parent.link_suffix : ""), this.parent.shop_loc_offset) + (this.parent.link_leaf_suffix != null ? this.parent.link_leaf_suffix : "");
			else if (this.parent.add_suffix) href.href = this.loc_href(this.parent.link_prefix + this.productUrl + (this.parent.link_suffix != null ? this.parent.link_suffix : ""), this.parent.shop_loc_offset) + (this.parent.link_leaf_suffix != null ? this.parent.link_leaf_suffix : "");
			else href.href = this.loc_href(this.parent.link_prefix.substr(0, this.parent.link_prefix.length - 1) + (this.parent.link_suffix != null ? this.parent.link_suffix : ""), this.parent.shop_loc_offset) + (this.parent.link_leaf_suffix != null ? this.parent.link_leaf_suffix : "");
			href.title = this.productNameAlt == null ? this.productName : this.productNameAlt;
			href.innerHTML = this.productName;
			
			var par = document.createElement("P");
			par.innerHTML = this.price;
			
			info.appendChild(href);
			info.appendChild(par);
			
		} else {
			var f, current, stack = new Array();
			stack[0] = this.container;

			while (stack.length > 0) {
				current = stack.pop();
				
				switch (current.tagName.toUpperCase()) {
					case "INPUT" :
						if (current.type == "hidden") this.productID = current.value;
						break;
						
					case "SPAN" :
						switch (current.className) {
							case "product_ico product_icosm_action" :
								make_bubble(context.trans("Akční nabídka"), current, null, "deflist_box deflist_box_small");
								break;
								
							case "product_ico product_icosm_tip" :
								make_bubble(context.trans("Náš tip"), current, null, "deflist_box deflist_box_small");
								break;
								
							case "product_ico product_icosm_dop" :
								make_bubble(context.trans("Doporučujeme"), current, null, "deflist_box deflist_box_small");
								break;
						}
						break;
				}
				
				for (f = 0; f < current.childNodes.length; f++)
					if (current.childNodes[f].nodeType == 1) stack[stack.length] = current.childNodes[f];
			}
		}
	}
	
	list_item_class.prototype.destroy = function() {
		context.structure_destroy(this.container);
		context.object_destroy(this);
	}

	// --- list_class ---
	
	function list_class(container) {
		this.container = container;
		
		this.sub_container = null;
		this.move_container = null;
		
		this.arrow_left = null;
		this.arrow_right = null;
		
		this.step_width = 145;
		
		this.current = 0;
		this.target = 0;
		this.num = 0;
		this.moving = false;
		this.lock = false;
		
		this.pos = 0;
		
		this.items = new Array();
		
		this.link_prefix = null;
		this.link_suffix = null;
		this.link_leaf_suffix = null;
		this.add_suffix = true;
		this.shop_loc_offset = 1;
		
		this.dt = new Array();
		/*
		this.class_type = null;
		this.shop_category = null;
		this.shop_param = null;
		this.shop_param_value = null;
		this.cart_product = null;
		this.shop_action = null;
		this.search_category = null;
		this.to_search = null;
		this.fav_category = null;
		this.pnc_language = null;
		this.comp_album = null;
		this.position_product = null;
		this.filter = "";
		this.list_section = "";
		*/
		
		this.list_length = null;
	}
	
	list_class.prototype.construct = function() {
		var self = this;
		var f, cur;
		for (f = 0; f < this.container.childNodes.length; f++) {
			cur = this.container.childNodes[f];
			
			if (cur.nodeType == 1 && (
				(cur.className.substr(0, 14) == "item_list_node")
			)) {
				this.add(new list_item_class(this, cur));
			}
		}
		
		if (this.items.length == this.list_length) {
			this.sub_container = document.createElement("DIV");
			
			var wX = context.get_elementWidth(this.container);
			var wY = context.get_elementHeight(this.container);
			
			if (wX < 0) wX = 0;
			if (wY < 0) wY = 0;
			
			this.sub_container.style.width = wX + "px";
			this.sub_container.style.height = wY + "px";
			this.sub_container.style.overflow = "hidden";
			this.sub_container.style.position = "relative";
			
			this.move_container = document.createElement("DIV");
			this.move_container.style.position = "relative";
			this.move_container.style.top = "0";
			this.move_container.style.left = "0";
			this.move_container.style.width = (context.get_elementWidth(this.container) * 10) + "px";
			
			this.sort();
			
			this.sub_container.appendChild(this.move_container);
			this.container.appendChild(this.sub_container);
			
			this.arrow_left = document.createElement("IMG");
			this.arrow_left.className = "arrow_left";
			this.arrow_left.style.display = "none";
			this.arrow_left.src = "/web/perfecto/gfx/arrow_left.gif";
			this.arrow_left.onclick = function() {
				self.do_left();
			}
			this.arrow_left.onmousedown = function() { this.style.top = "66px"; }
			this.arrow_left.onmouseup = function() { this.style.top = "65px"; }
			
			this.arrow_right = document.createElement("IMG");
			this.arrow_right.className = "arrow_right";
			this.arrow_right.style.display = "none";
			this.arrow_right.src = "/web/perfecto/gfx/arrow_right.gif";
			this.arrow_right.onclick = function() {
				self.do_right();
			}
			this.arrow_right.onmousedown = function() { this.style.top = "66px"; }
			this.arrow_right.onmouseup = function() { this.style.top = "65px"; }
			
			this.container.appendChild(this.arrow_left);
			this.container.appendChild(this.arrow_right);

            var init_request = true;
            var init_left = false;
            var init_right = false;

            var cur, pos = 0;
            while (pos < this.container.childNodes.length) {
                cur = this.container.childNodes[pos];
                if (cur.nodeType == 1 && cur.tagName.toUpperCase() == "SPAN") {
                    switch (cur.className) {
                        case "may_left" :
                            init_left = true;
                            init_request = false;
                            break;

                        case "may_right" :
                            init_right = true;
                            init_request = false;
                            break;

                        case "no_left" :
                            init_request = false;
                            break;

                        case "no_right" :
                            init_request = false;
                            break;
                    }
                }
                pos++;
            }

            if (init_request) {
                var struct = this.get_structure();
                struct.map("head/shop_product", this.dt["position_product"]);
                //struct.map("head/pos", this.pos = (this.list_length - 1));
                struct.map("head/inc", 0);
                struct.map("head/list_length", this.list_length);

                context.request("shop_list", null, function(data, request) {
                    if (self != null) self.evt_request(data, request);
                }, struct);

            } else {
                if (init_right) this.arrow_right.style.display = "block";
                if (init_left) this.arrow_left.style.display = "block";
            }
		}
	}
	
	list_class.prototype.get_structure = function() {
		var struct = new structure_class();
		struct.map("head/major", "shop_list");
		struct.map("head/link_prefix", this.link_prefix);
		
		var key;
		for (key in this.dt)
			struct.map("head/" + key, this.dt[key]);
		
		/*
		struct.map("head/class_type", this.class_type);
		struct.map("head/link_prefix", this.link_prefix);
		struct.map("head/shop_category", this.shop_category);
		struct.map("head/shop_param", this.shop_param);
		struct.map("head/shop_param_value", this.shop_param_value);
		struct.map("head/cart_product", this.cart_product);
		struct.map("head/shop_action", this.shop_action);
		struct.map("head/search_category", this.search_category);
		struct.map("head/to_search", this.to_search);
		struct.map("head/fav_category", this.fav_category);
		struct.map("head/pnc_language", this.pnc_language);
		struct.map("head/comp_album", this.comp_album);
		struct.map("head/filter", this.filter);
		struct.map("head/list_section", this.list_section);
		*/
		
		struct.map("head/frame", "size_x:145,size_y:145,bg:data/bg_normal.jpg");
		
		return struct;
	}
	
	list_class.prototype.do_left = function() {
		if (this.moving == 0 && !this.lock) {
			this.lock = true;
			
			var self = this;
			var struct = this.get_structure();
			//struct.map("head/shop_product", this.items[0].productID);
			//struct.map("head/pos", this.pos);
			//struct.map("head/inc", this.list_length * -1 + 1);
			struct.map("head/inc", this.list_length * -1 + 1);
			struct.map("head/list_length", this.list_length);
			
			context.request("shop_list", null, function(data, request) {
				if (self != null) self.evt_request(data, request);
			}, struct);
		}
	}
	
	list_class.prototype.do_right = function() {
		if (this.moving == 0 && !this.lock) {
			this.lock = true;
			
			var self = this;
			var struct = this.get_structure();
			//struct.map("head/shop_product", this.items[this.items.length - 1].productID);
			//struct.map("head/pos", this.pos);
			//struct.map("head/inc", this.list_length - 1);
			struct.map("head/inc", this.list_length - 1);
			struct.map("head/list_length", this.list_length);
			
			context.request("shop_list", null, function(data, request) {
				if (self != null) self.evt_request(data, request);
			}, struct);
		}
	}
	
	list_class.prototype.evt_request = function(data, request) {
		var res, f;
		if ((res = request.get_response()) != null) {
			
			var head = res[0];
			var body = res[1];
			
			this.pos = parseInt(context.sub_element_value(head, "pos"));
			var pnew = parseInt(context.sub_element_value(head, "new"));
			var total = parseInt(context.sub_element_value(head, "total"));
			if (isNaN(pnew)) pnew = 0;
			
			// skryti/odkryti sipek
			this.arrow_left.style.display = pnew == 0 ? "none" : "block";
			this.arrow_right.style.display = pnew + this.list_length >= total ? "none" : "block";
			
			// nacteni produktu a posun
			var inc = parseInt(context.sub_element_value(head, "inc"));
			
			if (inc != 0) {
				// bezny stav koncovych prvku
				this.items[0].container.className = "item_list_node";
				this.items[this.items.length - 1].container.className = "item_list_node";
				
				var el = body.getElementsByTagName("product");
				if (el.length > 0) {
					var item = null, pfx;
					var pos = inc > 0 ? 0 : (el.length - 1);
				
					while ((inc > 0 && pos < el.length) || (inc < 0 && pos >= 0)) {
						pfx = context.sub_element_value(el[pos], "link_prefix");
						
						item = new list_item_class(this, null);
						item.productID = context.sub_element_value(el[pos], "shop_product_ID");
						item.productName = context.sub_element_value(el[pos], "productNameShort");
						item.productNameAlt = context.sub_element_value(el[pos], "productName");
						item.productUrl = context.sub_element_value(el[pos], "productUrl");
						item.productSpecial = context.sub_element_value(el[pos], "productSpecial");
						item.imageSource = context.sub_element_value(el[pos], "imageSource");
						item.price = context.sub_element_value(el[pos], "price");
						item.link_prefix = this.link_prefix != "" || pfx == null || pfx == "" ? this.link_prefix : pfx;
						
						if (inc > 0) {
							this.move_add(item);
						} else {
							this.move_insert(item);
						}
						
						pos += inc > 0 ? 1 : -1;
					}
				}
			}
			
			this.lock = false;
		}
	}
	
	list_class.prototype.remove = function(item) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.items.length)
			if (this.items[pos] == item) founded = true;
			else pos++;
			
		if (founded) {
			var f, item = this.items[pos];
			for (f = pos; f < this.items.length - 1; f++)
				this.items[f] = this.items[f + 1];
			this.items.pop();
			
			item.destroy();
			
			return true;
		}
		return false;
	}
	
	list_class.prototype.add = function(item) {
		this.items[this.items.length] = item;
		item.construct();
	}
	
	list_class.prototype.insert = function(item) {
		this.items[this.items.length] = item;
		var f;
		for (f = this.items.length - 1; f > 0; f--)
			this.items[f] = this.items[f - 1];
		this.items[0] = item;
		item.construct();
	}
	
	list_class.prototype.sort = function() {
		var f;
		for (f = 0; f < this.items.length; f++) {
			if (this.items[f].container.parentNode != null)
				this.items[f].container.parentNode.removeChild(this.items[f].container);
		}
		
		for (f = 0; f < this.items.length; f++) {
			this.move_container.appendChild(this.items[f].container);
		}
	}
	
	list_class.prototype.move_add = function(item) {
		this.add(item);
		this.sort();
		
		this.current = 0;
		this.target += - this.step_width;
		this.moving = -1;
		this.num++;
		this.move_container.style.left = this.current + "px";
	}
	
	list_class.prototype.move_insert = function(item) {
		this.insert(item);
		this.sort();
		
		this.target = 0;
		this.current += - this.step_width;
		this.moving = 1;
		this.num++;
		this.move_container.style.left = this.current + "px";
	}
	
	list_class.prototype.motion = function() {
		if (this.moving != 0) {
			var dist = this.target - this.current;
			if (dist >= -1 && dist <= 1) {
				var f;
				this.current = this.target;
				
				switch (this.moving) {
					case 1 :
						for (f = 0; f < this.num; f++)
							this.remove(this.items[this.items.length - 1]);
						this.sort();
						break;
						
					case -1 :
						for (f = 0; f < this.num; f++)
							this.remove(this.items[0]);
						this.sort();
						break;
				}
				
				this.move_container.style.left = "0";
				this.moving = 0;
				this.current = 0;
				this.target = 0;
				this.num = 0;
				
				this.items[0].container.className = "item_list_node item_list_node_left";
				this.items[this.items.length - 1].container.className = "item_list_node item_list_node_right";
				
			} else {
				var step = (dist / 4) + this.moving;
				this.current += step;
				this.move_container.style.left = Math.round(this.current) + "px";
			}
		}
	}
	

