
	function flist_swapper_item(parent, uid, fid, name, lang, version, date, type, size, path, sub_name, sub_comment) {
		this.parent = parent;
	
		this.uid = uid;
		this.fid = fid;
		this.name = name;
		this.lang = lang;
		this.version = version;
		this.date = date;
		this.type = type;
		this.size = size;
		this.path = path;
		this.sub_name = sub_name;
		this.sub_comment = sub_comment;
		
		this.mount = function() {
			var res = this.parent.get_elms(this.uid);
			
			// odkaz
			var founded = false;
			var pos = 0;
			
			while (!founded && pos < res[0].childNodes.length)
				if (res[0].childNodes[pos].nodeType == 1 && res[0].childNodes[pos].nodeName.toLowerCase() == "a") founded = true;
				else pos++;
				
			if (founded) {
				var www_path = this.path;
				
				res[0].childNodes[pos].innerHTML = this.name;
				res[0].childNodes[pos].href = "javascript:file_download('" + www_path + "')";
				
				res[2].innerHTML = this.version;
				
				//res[3].innerHTML = this.date;
				
				res[3].innerHTML = this.type;
				
				res[4].innerHTML = this.size;
				
				founded = false;
				pos = 0;
				
				while (!founded && pos < res[5].childNodes.length)
					if (res[5].childNodes[pos].nodeType == 1 && res[5].childNodes[pos].nodeName.toLowerCase() == "input") founded = true;
					else pos++;
				
				if (founded) {
					res[5].childNodes[pos].onclick = function() {
						file_download(www_path);
					}
				} // if
				
				document.getElementById(this.uid + "_sub_name").innerHTML = this.sub_name;
				document.getElementById(this.uid + "_sub_comment").innerHTML = this.sub_comment;
				document.getElementById(this.uid + "_sub_date").innerHTML = this.date;
			} // if
		}
	} // function
	
	function flist_swapper() {
		var self = this;
	
		this.items = new Array();
		this.uids = new Array();
		
		this.map = function(uid, fid, name, lang, version, date, type, size, path, sub_name, sub_comment) {
			var ref = new flist_swapper_item(this, uid, fid, name, lang, version, date, type, size, path, sub_name, sub_comment);
			
			var pos = 0;
			var founded = false;
			
			while (!founded && pos < this.uids.length)
				if (this.uids[pos][0] == uid) founded = true;
				else pos++;
				
			if (!founded) {
				pos = this.uids.length;
				this.uids[pos] = new Array();
				this.uids[pos][0] = uid;
				this.uids[pos][1] = null;
				this.uids[pos][2] = ref;
			} else {
				this.uids[pos][this.uids[pos].length] = ref;
			}
			
			this.items[this.items.length] = ref;
		}
		
		this.get_elms = function(uid) {
			var node = document.getElementById("version" + uid + "no");
			
			founded = false;
			pos = 0;
			
			while (!founded && pos < node.childNodes.length) 
				if (node.childNodes[pos].nodeType == 1 && node.childNodes[pos].nodeName.toLowerCase() == "tbody") founded = true;
				else pos++;
				
			if (founded) {
				node = node.childNodes[pos];
			
				founded = false;
				pos = 0;
				
				while (!founded && pos < node.childNodes.length)
					if (node.childNodes[pos].nodeType == 1 && node.childNodes[pos].nodeName.toLowerCase() == "tr") founded = true;
					else pos++;
				
				if (founded) {
					var ret = new Array();
					node = node.childNodes[pos];
					
					pos = 0;
					while (pos < node.childNodes.length) {
						if (node.childNodes[pos].nodeType == 1 && node.childNodes[pos].nodeName.toLowerCase() == "td") ret[ret.length] = node.childNodes[pos];
						pos++;
					}
					
					return ret;
				}
			} // if
			
			return null;
		}
		
		this.evt_change = function(sel) {
			var founded = false;
			var pos = 0;
			
			while (!founded && pos < this.uids.length)
				if (this.uids[pos][1] == sel) founded = true;
				else pos++;
				
			if (founded) {
				var target = sel.options[sel.selectedIndex].value;
				
				founded = false;
				var s_pos = 2;
				
				while (!founded && s_pos < this.uids[pos].length)
					if (this.uids[pos][s_pos].fid == target) founded = true;
					else s_pos++;
					
				if (founded) {
					this.uids[pos][s_pos].mount();
				}
			} // if
		}
		
		this.initialize = function() {
			var f, sf, res;
			for (f = 0; f < this.uids.length; f++) {
				res = this.get_elms(this.uids[f][0]);
				this.uids[f][1] = res[1].childNodes[0];
				
				for (sf = this.uids[f][1].options.length - 1; sf >= 0; sf--) {
					this.uids[f][1].options[sf] = null;
				}
				
				// update selectu
				for (sf = 2; sf < this.uids[f].length; sf++) {
					var opt = document.createElement("OPTION");
					
					opt.value = this.uids[f][sf].fid;
					opt.text = this.uids[f][sf].lang;
					
					this.uids[f][1].options.add(opt);
				}
				
				this.uids[f][1].onchange = function() {
					self.evt_change(this);
				}
				
				this.uids[f][2].mount();
			} // for
		}
	} // function

