	
	// --- image_swap_node_class ---
	
	function image_swap_node_class(container, input, img, href) {
		this.parent = null;
		
		this.container = container;
		this.view = null;
		
		this.input = input;
		this.img = img;
		this.href = href;
		this.zoom = false;
		
		this.area_width = 0;
		this.area_height = 0;
		
		this.area_left = 0;
		this.area_top = 0;
		
		this.self_width = 0;
		this.self_height = 0;
	}
	
	image_swap_node_class.prototype.construct = function() {
		var self = this;
		this.img.onmouseover = function(trgEvent) { if (self.o_ds == null) self.evt_onmouseover(trgEvent == null ? event : trgEvent); }
		this.img.onmouseout = function(trgEvent) { if (self.o_ds == null) self.evt_onmouseout(trgEvent == null ? event : trgEvent); }
		this.img.onmousemove = function(trgEvent) { if (self.o_ds == null) self.evt_onmousemove(trgEvent == null ? event : trgEvent); }
		this.img.onclick = function(trgEvent) { if (self.o_ds == null) self.evt_onclick(trgEvent == null ? event : trgEvent); }
		
		this.href.parentNode.appendChild(this.img);
		context.structure_destroy(this.href);
		
		this.view = document.createElement("DIV");
		this.view.className = "view";
		this.view.style.cursor = "pointer";
		this.view.style.display = "none";
		this.view.onmousemove = function(trgEvent) { if (self.o_ds == null) self.evt_onmousemove(trgEvent == null ? event : trgEvent); }
		this.view.onclick = function(trgEvent) { if (self.o_ds == null) self.evt_onclick(trgEvent == null ? event : trgEvent); }
		
		this.self_width = context.get_elementWidth(this.img) - 4;
		this.self_height = context.get_elementHeight(this.img) - 4;
		
		this.container.appendChild(this.view);
	}
	
	image_swap_node_class.prototype.get_image_path = function() {
		return this.input.value;
	}
	
	image_swap_node_class.prototype.touch = function() {
		this.container.className = this.parent.active == this ? "active" : "";
		if (this.parent.active != this) this.view.style.display = "none";
	}
	
	image_swap_node_class.prototype.fix_view = function() {
		if (this.parent.is_oversize()) {
			var koef = this.self_width / this.parent.self_width;
			
			this.area_width = koef * this.parent.area_width;
			this.area_height = koef * this.parent.area_height;
			
			if (this.area_width > this.self_width) this.area_width = this.self_width;
			if (this.area_height > this.self_height) this.area_height = this.self_height;
			
			this.view.style.left = Math.round(context.get_elementX(this.img) + this.area_left - context.get_elementX(this.container.parentNode) + (document.all ? 2 : 1)) + "px";
			this.view.style.top = Math.round(context.get_elementY(this.img) + this.area_top - context.get_elementY(this.container.parentNode) + 2) + "px";
			
			this.view.style.width = Math.round(this.area_width) + "px";
			this.view.style.height = Math.round(this.area_height) + "px";
			
		} else {
			this.view.style.left = Math.round(context.get_elementX(this.img) - context.get_elementX(this.container.parentNode) + (document.all ? 2 : 1)) + "px";
			this.view.style.top = Math.round(context.get_elementY(this.img) - context.get_elementY(this.container.parentNode) + 2) + "px";
			
			this.view.style.width = "45px";
			this.view.style.height = "40px";
		}
	}
	
	image_swap_node_class.prototype.touch_view = function() {
		if (this.parent.is_orig_oversize()) {
			if (this.parent.active == this) {
				if (this.parent.is_oversize()) {
					this.fix_view();
					this.view.style.display = "block";
				} else {
					this.fix_view();
					this.view.style.display = "block";
				}
				
			} else {
				this.view.style.display = "none";
			}
			
		} else {
			this.view.style.display = "none";
		}
	}
	
	image_swap_node_class.prototype.evt_onmouseover = function(trgEvent) {
		//this.container.className = "active";
	}
	
	image_swap_node_class.prototype.evt_onmouseout = function(trgEvent) {
		//this.container.className = "";
	}
	
	image_swap_node_class.prototype.evt_onmousemove = function(trgEvent) {
		if (this.parent.is_oversize()) {
			var px = trgEvent.clientX - context.get_elementX(this.img) - this.area_width / 2;
			var py = trgEvent.clientY - context.get_elementY(this.img) + this.parent.image_line.scrollTop - this.area_height / 2;
			
			if (px + this.area_width > this.self_width) px = this.self_width - this.area_width;
			if (px < 0) px = 0;
			if (py + this.area_height > this.self_height) py = this.self_height - this.area_height;
			if (py < 0) py = 0;
			
			if (px != this.area_left || py != this.area_top) {
				this.area_left = px;
				this.area_top = py;
				
				this.fix_view();
				this.parent.set_image_position(this.area_left, this.area_top);
			}
		}
	}
	
	image_swap_node_class.prototype.evt_onclick = function(trgEvent) {
		if (this.parent.active == this) {
			if (this.parent.is_orig_oversize()) this.zoom = !this.zoom;
			
			this.parent.zoom();
			this.touch_view();
			this.evt_onmousemove(trgEvent);
			
		} else {
			this.parent.activate(this);
		}
	}
	
	image_swap_node_class.prototype.evt_load = function() {
		this.touch_view();
	}
	
	// --- image_swap_class ---
	
	function image_swap_class(image_line, image_content) {
		this.items = new Array();
		this.active = null;
		this.move_flag = 0;
		this.move_koef = 0;
		this.move_point = 0;
		
		this.area_width = 680;
		this.area_height = 625;
		
		this.self_width = 0;
		this.self_height = 0;
		
		this.orig_width = 0;
		this.orig_height = 0;
		
		this.image_line = image_line;
		this.image_content = image_content;
		
		this.loader_info = null;
		this.loader_area = null;
		this.loader_image = null;
		
		this.arrow_up = null;
		this.arrow_down = null;
	}
	
	image_swap_class.prototype.construct = function() {
		var self = this;
		var current, f, stack = new Array();
		stack[0] = this.image_line;
		
		var last_div = null;
		var last_input = null;
		var last_img = null;
		var last_href = null;
		
		while (stack.length > 0) {
			current = stack.pop();
			
			switch (current.tagName.toUpperCase()) {
				case "DIV" :
					last_div = current;
					break;
					
				case "INPUT" :
					last_input = current;
					break;
					
				case "IMG" :
					last_img = current;
					break;
					
				case "A" :
					last_href = current;
					break;
			}
			
			if (last_div != null && last_input != null && last_img != null && last_href != null) {
				var ref = new image_swap_node_class(last_div, last_input, last_img, last_href);
				this.items[this.items.length] = ref;
				ref.parent = this;
				ref.construct();
				
				last_div = null;
				last_input = null;
				last_img = null;
			}
			
			if (current.childNodes.length > 0) {
				for (f = current.childNodes.length - 1; f >= 0; f--)
					if (current.childNodes[f].nodeType == 1) stack[stack.length] = current.childNodes[f];
			}
		}
		
		this.loader_info = document.createElement("DIV");
		this.loader_info.className = "info";
		this.loader_info.innerHTML = "probíhá načítání obrázku ...";
		
		this.loader_area = document.createElement("DIV");
		this.loader_area.className = "area";
		this.loader_area.style.display = "none";
		this.loader_area.style.width = this.area_width + "px";
		this.loader_area.style.height = this.area_height + "px";
		
		this.loader_image = document.createElement("IMG");
		
		this.loader_area.appendChild(this.loader_image);
		this.image_content.appendChild(this.loader_info);
		this.image_content.appendChild(this.loader_area);
		
		var total = 0;
		for (f = 0; f < this.items.length; f++)
			total += context.get_elementHeight(this.items[f].container);
			
		if (total > 700) {
			this.arrow_up = document.createElement("DIV");
			this.arrow_up.className = "arrow_up";
			
			this.arrow_down = document.createElement("DIV");
			this.arrow_down.className = "arrow_down";
			
			this.image_line.parentNode.appendChild(this.arrow_up);
			this.image_line.parentNode.appendChild(this.arrow_down);
			
			this.arrow_up.onmousedown = function() { self.move_flag = -1;self.move_koef = 0;self.move_point = parseInt(self.image_line.scrollTop); }
			this.arrow_up.onmouseup = function() { self.move_flag = 0;self.move_koef = 0; }
			this.arrow_up.onmouseout = function() { self.move_flag = 0;self.move_koef = 0; }
			
			this.arrow_down.onmousedown = function() { self.move_flag = 1;self.move_koef = 0;self.move_point = parseInt(self.image_line.scrollTop); }
			this.arrow_down.onmouseup = function() { self.move_flag = 0;self.move_koef = 0; }
			this.arrow_down.onmouseout = function() { self.move_flag = 0;self.move_koef = 0; }
		}
		
		if (this.items.length > 0) this.activate(this.items[0]);
	}
	
	image_swap_class.prototype.do_motion = function() {
		if (this.move_flag == 1) this.move_koef += 2.1;
		else if (this.move_flag == -1) this.move_koef += -2.1;
		
		if (this.move_koef != 0) {
			this.move_point += this.move_koef;
			this.image_line.scrollTop = parseInt(this.move_point);
			
			if (this.active != null) this.active.fix_view();
		}
	}
	
	image_swap_class.prototype.is_oversize = function() { return this.self_width > this.area_width || this.self_height > this.area_height; }
	image_swap_class.prototype.is_orig_oversize = function() { return this.orig_width > this.area_width || this.orig_height > this.area_height; }
	
	image_swap_class.prototype.set_image_position = function(x, y) {
		if (this.is_oversize()) {
			var koef = this.self_width / this.active.self_width;
			
			this.loader_image.style.left = (koef * -x) + "px";
			this.loader_image.style.top = (koef * -y) + "px";
			
		} else {
			var diff_x = (this.area_width - this.self_width) / 2;
			var diff_y = (this.area_height - this.self_height) / 2;
			
			this.loader_image.style.left = diff_x + "px";
			this.loader_image.style.top = diff_y + "px";
		}
	}
	
	image_swap_class.prototype.assign_image = function(src) {
		var self = this;
		
		this.loader_info.style.display = "block";
		this.loader_area.style.display = "none";
		
		this.loader_image.style.width = "";
		this.loader_image.style.height = "";
		
		this.loader_image.onload = function() {
			self.evt_load();
		}
		this.loader_image.src = src;
	}
	
	image_swap_class.prototype.zoom = function() {
		if (this.active.zoom) {
			this.self_width = this.orig_width;
			this.self_height = this.orig_height;
			
			this.loader_image.style.width = this.self_width + "px";
			this.loader_image.style.height = this.self_height + "px";
			
			this.set_image_position(0, 0);
			this.active.touch_view();
			
		} else {
			var ratio_area = this.area_width / this.area_height;
			var ratio_image = this.self_width / this.self_height;
			
			var tx, ty;
			
			if (ratio_area > 1) { // na sirku
				if (ratio_image > 1) { // stejne - na sirku
					var tx = this.area_width;
					var ty = this.area_width / ratio_image;
					
				} else { // rozdilne - na vysku
					var ty = this.area_height;
					var tx = this.area_height * ratio_image;
				}
				
			} else { // na vysku
				if (ratio_image <= 1) {  // stejne - na vysku
					
					
				} else { // rozdilne - na sirku
					
				}
				
			}
			
			this.self_width = tx;
			this.self_height = ty;
			
			this.loader_image.style.width = this.self_width + "px";
			this.loader_image.style.height = this.self_height + "px";
			
			this.set_image_position(0, 0);
			this.active.touch_view();
			
		}
	}
	
	image_swap_class.prototype.activate = function(ref) {
		if (ref != this.active) {
			if (this.active != null) {
				var bef = this.active;
				this.active = null;
				bef.touch();
			}
			
			this.active = ref;
			ref.touch();
			ref.zoom = false;
			this.assign_image(ref.get_image_path());
		}
	}
	
	image_swap_class.prototype.evt_load = function() {
		this.loader_info.style.display = "none";
		this.loader_area.style.display = "block";
		
		this.self_width = (this.orig_width = context.get_elementWidth(this.loader_image));
		this.self_height = (this.orig_height = context.get_elementHeight(this.loader_image));
		
		this.zoom();
		
		this.active.evt_load();
	}
	