
	if (typeof addEvent != 'function')
	{
	 var addEvent = function(o, t, f, l)
	 {
	  var d = 'addEventListener', n = 'on' + t, rO = o, rT = t, rF = f, rL = l;
	  if (o[d] && !l) return o[d](t, f, false);
	  if (!o._evts) o._evts = {};
	  if (!o._evts[t])
	  {
	   o._evts[t] = o[n] ? { b: o[n] } : {};
	   o[n] = new Function('e',
		'var r = true, o = this, a = o._evts["' + t + '"], i; for (i in a) {' +
		 'o._f = a[i]; r = o._f(e||window.event) != false && r; o._f = null;' +
		 '} return r');
	   if (t != 'unload') addEvent(window, 'unload', function() {
		removeEvent(rO, rT, rF, rL);
	   });
	  }
	  if (!f._i) f._i = addEvent._i++;
	  o._evts[t][f._i] = f;
	 };
	 addEvent._i = 1;
	 var removeEvent = function(o, t, f, l)
	 {
	  var d = 'removeEventListener';
	  if (o[d] && !l) return o[d](t, f, false);
	  if (o._evts && o._evts[t] && f._i) delete o._evts[t][f._i];
	 };
	}

	function cancelEvent(e, c)
	{
	 e.returnValue = false;
	 if (e.preventDefault) e.preventDefault();
	 if (c)
	 {
	  e.cancelBubble = true;
	  if (e.stopPropagation) e.stopPropagation();
	 }
	}
	
	function context_class() {
		this.document_ref = null;
		this.window_ref = null;
	}
	
	context_class.prototype.layerX = function(evt, pos) {
		if (evt.layerX) return evt.layerX;
		else return evt.clientX - pos;
	}

	context_class.prototype.layerY = function(evt, pos) {
		if (evt.layerY) return evt.layerY;
		else return evt.clientY - pos;
	}

	context_class.prototype.wnd_x = function() {
		var result = 0;
		
		if (typeof(this.window_ref.innerWidth) == 'number') result = this.window_ref.innerWidth;
		else if (this.document_ref.documentElement && (this.document_ref.documentElement.clientWidth || this.document_ref.documentElement.clientHeight)) result = this.document_ref.documentElement.clientWidth;
		else if (this.document_ref.body && (this.document_ref.body.clientWidth || this.document_ref.body.clientHeight)) result = this.document_ref.body.clientWidth;

		return result;
	}

	context_class.prototype.wnd_y = function() {
		var result = 0;
		
		if (typeof(this.window_ref.innerWidth) == 'number') result = this.window_ref.innerHeight;
		else if (this.document_ref.documentElement && (this.document_ref.documentElement.clientWidth || this.document_ref.documentElement.clientHeight)) result = this.document_ref.documentElement.clientHeight;
		else if (this.document_ref.body && (this.document_ref.body.clientWidth || this.document_ref.body.clientHeight)) result = this.document_ref.body.clientHeight;

		return result;
	}

	context_class.prototype.get_scX = function() {
		var a = this.document_ref.body.scrollLeft;
		var b = this.document_ref.documentElement.scrollLeft;
		
		return a != 0 ? a : b;
	}

	context_class.prototype.get_scY = function() {
		var a = this.document_ref.body.scrollTop;
		var b = this.document_ref.documentElement.scrollTop;
		
		return a != 0 ? a : b;
	}

	context_class.prototype.get_elementX = function(ref) {
		var loop = ref;
		var out = 0;
		
		while (loop != null) {
			out += loop.offsetLeft;
			loop = loop.offsetParent;
		}
		
		return out;
	}

	context_class.prototype.get_elementY = function(ref) {
		var loop = ref;
		var out = 0;
		
		while (loop != null) {
			out += loop.offsetTop;
			loop = loop.offsetParent;
		}
		
		return out;
	}

	context_class.prototype.get_elementWidth = function(ref) {
		return ref.offsetWidth;
	}

	context_class.prototype.get_elementHeight = function(ref) {
		return ref.offsetHeight;
	}

	function search_submit() {
		document.getElementById("search_button").disabled = true;
		document.getElementById("search_box").style.display = "block";
	}
	
	function send_submit() {
		document.getElementById("send_button").disabled = true;
		document.getElementById("send_box").style.display = "block";
	}
	
	function preview(prev_path) {
		window.open("preview.php?prev_path=" + prev_path, "prev_wnd", "toolbar=0,menubar=0,statusbar=0,width=640,height=480");
	}
	
	function buy_click(ref) {
		var loop = ref;
		
		while (loop != null && loop.tagName.toUpperCase() != "FORM") loop = loop.parentNode;
		
		if (loop != null) {
			var a = document.body.scrollTop;
			var b = document.documentElement != null ? document.documentElement.scrollTop : 0;
			
			loop.action = loop.action + "&scroll=" + (a != 0 ? a : b);
		}
	}
	
	function cart_keydown(ref, link, keyCode) {
		if (keyCode == 13) {
			document.location.href = link + ref.value;
			return false;
		}
		
		return true;
	}
	
	function buy_item(parent, hf, node) {
		this.parent = parent;
		this.href = null;
		this.hf = hf;
		this.node = node;
		this.wnd = null;
		this.cont = null;
		//this.overlay = null;
		
		this.href_close = null;
		this.input_count = null;
		this.butt_detail = null;
		this.butt_buy = null;
		this.butt_buysec = null;
		
		this.p_comment = null;
		this.p_title = null;
		this.p_img = null;
		this.p_img_el = null;
		this.p_store_info = null;
		this.p_price = null;
		this.p_code = null;
		this.p_unit = null;
	}
	
	buy_item.prototype.open_inst = null;
	
	buy_item.prototype.construct = function() {
		var self = this;
	
		this.href = this.hf.href;
		this.hf.href = "javascript:void(0)";
		this.hf.onclick = function() {
			self.open();
		}
		
		var current, f, stack = new Array();
		stack[0] = this.node;
		
		while (stack.length > 0) {
			current = stack.pop();
			
			switch (current.tagName.toUpperCase()) {
				case "P" :
					if (current.className == "comment") this.p_comment = current;
					else if (current.className == "title") this.p_title = current;
					else if (current.className == "store_info") this.p_store_info = current;
					else if (current.className == "price") this.p_price = current;
					break;
					
				case "IMG" :
					if ((current.parentNode.tagName.toUpperCase() == "DIV" && current.parentNode.className == "img") || 
						(current.parentNode.parentNode.tagName.toUpperCase() == "DIV" && current.parentNode.parentNode.className == "img")) {
						this.p_img = current.src;
					}
					break;
					
				case "DIV" :
					break;
					
				case "INPUT" :
					if (current.type == "hidden" && current.name == "code") this.p_code = current;
					else if (current.type == "hidden" && current.name == "unit") this.p_unit = current;
					break;
			}
			
			for (f = 0; f < current.childNodes.length; f++)
				if (current.childNodes[f].nodeType == 1) stack[stack.length] = current.childNodes[f];
		}
	}
	
	buy_item.prototype.open = function() {
		if (this.cont == null) {
			var self = this;
			buy_item.open_inst = this;
			
			/*
			this.overlay = document.createElement("DIV");
			this.overlay.className = "overlay";
			this.overlay.onclick = function() {
				self.close();
			}
			*/
			
			this.wnd = document.createElement("DIV");
			this.wnd.className = "product_node_window";
			
			this.cont = document.createElement("DIV");
			this.cont.className = "product_node product_node_float";
			
			var dt = "";
			dt += "<p class=\"title\">" + (this.p_title.innerHTML) + "</p>";
			dt += "<p class=\"code\">Kód:&nbsp;&nbsp;<strong>" + this.p_code.value + "</strong></p>";
			if (this.p_comment != null) dt += "<p class=\"comment\">" + (this.p_comment.innerHTML) + "</p>";
			if (this.p_store_info != null) dt += "<p class=\"store_info\">" + (this.p_store_info.innerHTML) + "</p>";
			if (this.p_price != null) {
				dt += "<p class=\"price_info\">Cena / " + this.p_unit.value + ":</p>";
				dt += "<p class=\"price\">" + (this.p_price.innerHTML) + "</p>";
			}
			dt += "<p class=\"count_info\">Počet jednotek: </p>";
			
			this.cont.innerHTML = dt;
			
			this.butt_detail = document.createElement("IMG");
			this.butt_detail.className = "butt_detail";
			this.butt_detail.onclick = function() {
				document.location.href = self.href;
			}
			
			this.butt_buy = document.createElement("IMG");
			this.butt_buy.className = "butt_buy";
			this.butt_buy.onclick = function() {
				self.evt_buy(false);
			}
			
			this.butt_buysec = document.createElement("A");
			this.butt_buysec.className = "butt_buysec";
			this.butt_buysec.href = "javascript:void(0)";
			this.butt_buysec.innerHTML = "Koupit a otevřít košík";
			this.butt_buysec.onclick = function(trgEvent) {
				var evt = trgEvent == null ? window.event : trgEvent;
				self.evt_buy(true);
				cancelEvent(evt, true);
				return false;
			}
			
			this.input_count = document.createElement("INPUT");
			this.input_count.className = "input_count";
			this.input_count.value = 1;
			this.input_count.onkeyup = function(trgEvent) {
				var evt = trgEvent == null ? window.event : trgEvent;
				switch (evt.keyCode) {
					case 13 :
						self.evt_buy();
						break;
						
					case 27 :
						self.close();
						break;
				}
			}
			
			this.href_close = document.createElement("A");
			this.href_close.href = "javascript:void(0)";
			this.href_close.className = "href_close";
			this.href_close.innerHTML = "zavřít okno";
			this.href_close.onclick = function() {
				self.close();
			}
			
			this.cont.appendChild(this.butt_detail);
			this.cont.appendChild(this.butt_buy);
			this.cont.appendChild(this.butt_buysec);
			this.cont.appendChild(this.input_count);
			this.cont.appendChild(this.href_close);
			
			//document.body.appendChild(this.overlay);
			document.body.appendChild(this.cont);
			document.body.appendChild(this.wnd);
			
			//document.body.style.overflow = "hidden";
			
			this.position();
			
			this.input_count.focus();
			this.input_count.select();
			
			this.p_img_el = document.createElement("IMG");
			this.p_img_el.style.display = "none";
			this.p_img_el.onload = function() {
				this.style.display = "inline";
			}
			
			var dv = document.createElement("DIV");
			dv.className = "img";
			
			dv.appendChild(this.p_img_el);
			this.cont.appendChild(dv);
			
			setTimeout("buy_item.open_inst.do_image_load()", 50);
			
			/*
			var self = this;
			this.cont.onmouseout = function(trgEvent) {
				var evt = trgEvent == null ? window.event : trgEvent;
				var trg = evt.toElement == null ? evt.relatedTarget : evt.toElement;
				
				while (trg != null && trg != self.cont)
					trg = trg.parentNode;
					
				if (trg == null) self.close();
			}
			*/
		}
	}
	
	buy_item.prototype.do_image_load = function() {
		this.butt_detail.src = "gfx/dettail.jpg";
		this.butt_buy.src = "gfx/dokosikku.jpg";
		
		if (this.p_img.indexOf(".php") >= 0) {
			this.p_img_el.src = this.p_img;
			//+ "&rnd=" + Math.round(Math.random() * 1000000);
		} else {
			this.p_img_el.src = this.p_img;
		}
	}
	
	buy_item.prototype.evt_buy = function(open_cart) {
		var cnt = parseInt(this.input_count.value);
		if (isNaN(cnt)) cnt = 0;
		else if (cnt < 0) cnt = 0;
		this.parent.buy(this, this.p_code.value, cnt, open_cart);
	}
	
	buy_item.prototype.position = function() {
		if (this.cont != null) {
			var off_width = document.body.offsetWidth;
			var off_height = document.body.offsetHeight;
			
			var width = context.get_elementWidth(this.cont);
			var height = context.get_elementHeight(this.cont);
			
			var left = Math.round((off_width - width) / 2);
			var top = Math.round((context.wnd_y() - height) / 2) + context.get_scY();
			
			this.wnd.style.left = (left - 30) + "px";
			this.wnd.style.top = (top - 30) + "px";
			
			this.cont.style.left = left + "px";
			this.cont.style.top = top + "px";
			
			//this.overlay.style.width = off_width + "px";
			//this.overlay.style.height = off_height + "px";
		}
	}
	
	buy_item.prototype.close = function() {
		if (this.cont != null) {
			this.cont.onmouseout = null;
			document.body.removeChild(this.wnd);
			document.body.removeChild(this.cont);
			//document.body.removeChild(this.overlay);
			
			this.cont = null;
			this.wnd = null;
			
			//this.overlay = null;
			
			//document.body.style.overflow = "auto";
		}
	}
	
	function buy_handler() {
		this.items = new Array();
		
		this.container = null;
		this.form = null;
		
		this.buy_count = null;
		this.buy_code = null;
	}
	
	buy_handler.prototype.construct = function() {
		var node, hf, ref, f, hrefs = document.getElementsByTagName("A");
		
		for (f = 0; f < hrefs.length; f++) {
			hf = hrefs[f];
			node = hf.parentNode;
			
			if (hf.className == "buy" && node.className == "product_node") {
				ref = new buy_item(this, hf, node);
				this.items[this.items.length] = ref;
				ref.construct();
			}
		}
		
		if (this.items.length > 0) {
			this.container = this.items[0].node.parentNode;
			
			var loop = this.container;
			
			while (loop != null && loop.tagName.toUpperCase() != "FORM") loop = loop.parentNode;
			
			if (loop != null) {
				this.form = loop;
				
				this.buy_count = document.createElement("INPUT");
				this.buy_count.type = "hidden";
				this.buy_count.name = "buy_count";
				
				this.buy_code = document.createElement("INPUT");
				this.buy_code.type = "hidden";
				this.buy_code.name = "buy_code";
				
				this.container.appendChild(this.buy_count);
				this.container.appendChild(this.buy_code);
			}
		}
	}
	
	buy_handler.prototype.buy = function(item, code, count, open_cart) {
		if (this.form != null) {
			this.buy_count.value = count;
			this.buy_code.value = code;
			item.close();
			
			if (open_cart) this.form.action = this.form.action + "&open_cart=1";
			
			// ulozeni stavu rolovani
			var scPn = document.getElementById("product_scroll_panel");
			
			this.form.action = this.form.action + "&scroll_sv=" + context.get_scY() + (scPn == null ? "" : ("|" + scPn.scrollTop));
			
			this.form.submit();
		}
	}
	
	function map_buy_button() {
		var f, elm = document.getElementsByTagName("INPUT");
		for (f = 0; f < elm.length; f++) {
			if (elm[f].type == "submit" && elm[f].className == "second") {
				elm[f].onclick = function() {
					var loop = this;
					
					while (loop != null && loop.tagName.toUpperCase() != "FORM") loop = loop.parentNode;
					
					if (loop != null) {
						var scPn = document.getElementById("product_scroll_panel");
						
						loop.action = loop.action + "&scroll_sv=" + context.get_scY() + (scPn == null ? "" : ("|" + scPn.scrollTop));
					}
				}
			}
		}
	}
	
