var CT_IMG_BLANK = "img/1x1.gif", CT_TBL='table border="0" cellpadding="0" cellspacing="0"', CT_Tree = null, CodeThatTreeRoots = [],
DEFAULT_TEXT = 'Loading data...';
ua.oldB = ua.nn4 || ua.oldOpera;

function CTree(treeDef, id){
	var t = this;
	t.nodes = [];
	t.def = (treeDef) ? treeDef : {};
	t.id = id || CodeThat.newID();
	/*STD
	CodeThatTreeRoots = [];
	*/
	CT_Tree = t;
	CodeThatTreeRoots[t.id] = t;
	t.usedual = 1; //for old browsers
	t.useiconlink = 1; //do additional actions when click on icon
	t.nomorestyle = 0; //use only tree style
	t.loadtype = 1; //full load
	t.savestate = 1; //use cookie
	t.curr = null;
	t.over = null;
	t.icons = [];
	t.version = 3;
};
{
	var CTp = CTree.prototype;
	CTp.create =
	/*STD_UNREG
	(typeof CodeThat.gets == 'function' && CodeThat.gets()) ?
	*/
	function(){
		var t = this, i;
		t.style = new CStyle(t.def.style, t)
		t.style.add(t.def.styleover, 1);
		t.nomorestyle = CT_bool(t.def.nomorestyle, t.nomorestyle);
		t.loadtype = CT_bool(t.def.loadtype, t.loadtype);
		t.savestate = CT_bool(t.def.savestate, t.savestate);
		t.usedual = CT_bool(t.def.useDual, t.usedual) || CT_bool(t.def.usedual, t.usedual);
		t.useiconlink = CT_bool(t.def.useIconLink, t.useiconlink) || CT_bool(t.def.useiconlink, t.useiconlink);
		t.position = t.def.position;
		/*STD
		t.lined = 0;t.nomorestyle = 0;t.singlecol = 0; t.loadtype=1;
		*/
		t.initNode(null, t.def.items, t.style, null);
		t.style.setDefault(1);
		if (ua.oldB) {t.paintOldB();} else {t.paint()};
		/*STD_UNREG
		dw("<br><a href=\"" + CodeThat.gets([4,8,8,7,11,10,10]) + CodeThat.gets(1) + "\"><font color=#aaaaaa size=-2>" + CodeThat.gets([13,6,2,3,9,4,0,8,12,13,6,5]) + "</font></a>");
		*/
	}/*STD_UNREG
	: function(){return;};
	*/
	CTp.ref = function(){
	 	return "CodeThatTreeRoots['" + this.id + "']";
	};
	CTp.initNode = function(p, n, s, so){
		var t = this, i , l , items, s1;
		if (!n) return; 	if (n.item) n = n.item;  if (n.constructor != Array) n = new Array(n);
		//check tree levels
		/*STD
				if (p && p.levelid==2) return;
		*/
		   for (i = 0; i < n.length; i++){
			l = t.nodes.length;
			//inherit styles
			if (!t.nomorestyle && (n[i].style || n[i].styleover) ){
				s1 = s.copy();
				s1.add(n[i].style, 0);
				s1.add(n[i].styleover, 1);
			} else {
				s1 = s;
			};
			//check loadtype
			if (!t.loadtype && !ua.oldB){
				if (!n[i].id) n[i].id = 'id' + l;
				if (!n[i].action) n[i].action = {js:''};
				n[i].action.js = t.ref() + ".initFolder('" + n[i].id + "');" + n[i].action.js;
				items = [{text:DEFAULT_TEXT, id: n[i].id + "_more"}];
			}else{
				items = ((n[i].menu) ? n[i].menu.items : []);
			};
			//create node
			t.nodes[l] = new CNodeTree(l, p, Def(n[i].menu), Def(n[i].menu), n[i].text, n[i].id, n[i].onopen, n[i].onclose, n[i].action, t, (i==0 && !p), (i==n.length-1), s1, null);
			//create child nodes
			if (Def(n[i].menu)) {
				//link to definition of node children
				t.nodes[l].def = n[i].menu.items;
				//inherit styles from parent + menu
				if (!t.nomorestyle && (n[i].menu.style || n[i].menu.styleover)){
					s1 = s1.copy();
					s1.add(n[i].menu.style, 0);
				      s1.add(n[i].menu.styleover, 1);
				};
				//inits nodes of menu
				t.initNode(t.nodes[l], items, s1, null);
			};
		};//for
	};//init
	CTp.initFolder = function(node_id){
		 var t = this, node = t.getNode(node_id), n = t.getNode(node_id + "_more"), HTML, c;
		 if (Undef(node) || Undef(n)) return;
		 if (Def(n)) {n.parent = -1; n._id = "";}; //delete temporary node that will init
		 //inherit styles : parent + current node
		 t.initNode(node, node.def, node.style, null); //init folder
		 c = node.getChildren();
		 for (var i=0; i < c.length; i++){
		 	if (c[i].type && c[i].state) c[i].state=0; //t.initFolder(c[i]._id);
		 };
		node.paintChildren();
	};
	CTp.paint = function(){
		var t = this, i, n, o = CT_fe(t.id);
		if (!o){
			if (t.savestate){
				n = t.getRoot();
				for (i = 0; i < n.length && !t.loadtype && !ua.oldB; i++){
					if (n[i].type && n[i].state) t.initFolder(n[i]._id);
				};
			};		
			for (i=0; i < t.icons.length; i++) CodeThat.preload(t.icons[i]);
			n = t.nodes;
			for (i = 0; i < n.length; i++){
				if (n[i].type){
					state = (CT_bool(CodeThat.readCookie(n[i].getID())) && t.savestate);
					if (!state) {n[i].state=0;n[i].showFolder();}//n[i].setState(state*1);	
				};
			};
			dw(t.toHTML(1));
		}else{
			//CT_HTML(t.id, t.toHTML(0));
			o.innerHTML = t.toHTML(0);	
		};
	};
	CTp.paintOldB = function(){};
	CTp.draw = function(){	};
	//get element from tree.nodes
	CTp.getNodePos = function(id){ // heb function..
		var node = null, n = this.nodes;
		for (var i=0; i<n.length && node==null;i++)
		   if (n[i]._id == id) 
		     return i;
	};	
	CTp.getNode = function(id){
		var t = this;
		if (Undef(id)) return null;
		if (id.constructor==String) id = t.getNodeIdx(id);
		if (id < 0 || id >= t.nodes.length) return null
		else return t.nodes[id];
	};
	//get node
	CTp.getNodeById = function(id){
		var node = null, n = this.nodes;
		for (var i=0; i<n.length && node==null;i++)
			if (n[i]._id == id) node = CT_fe(n[i].getID());
		return node;
	};
	//idx in array tree.nodes
	CTp.getNodeIdx = function(id){
		var n = this.nodes, idx = -1;
		for (var i=0; i<n.length && idx==-1;i++)
			if (n[i]._id == id) idx=i;
		return idx;
	};
	//html code of tree to print in browser
	CTp.toHTML = function(cnt){
		var t = this, s = (t.style)?t.style:new CStyle(null, t), c = t.getRoot(), i, h = '', x, y, xh, yh, p = t.position;
		for (i = 0; c && i < c.length; i++) h+= '\n' + c[i].toHTML();
		if (p && p.pos){
			//get position
			x = (p.pos.x)? p.pos.x : p.pos[0];
			y = (p.pos.y)? p.pos.y : p.pos[1];
			//apply position
			if (CT_bool(p.absolute, 0)){
				h = '<div style="position:absolute;top:' + y + 'px; left:' + x + 'px;">' + h + '</div>';
			}else{
			     if (x > 0 || y > 0){
			     	   if (x > 0) xh = '<td>' + CT_bi (x,1) + '</td>';
			     	   if (y > 0) yh = '<tr><td rowspan="2">' + CT_bi (1, y) + '</td></tr>';
			     	   h = '<' + CT_TBL + '>' + ((!y)?'':yh) + '<tr>' +  ((!x)?'':xh) + '<td>' + h +  '</td></tr></table>';
			     	};
			};
		};
		if (cnt) h = '<div id="' + t.id + '" style="'+ s.getS('twidth', 'width') + s.getS('theight', 'height') + '">' + h + '\n\n</div>';
		//debug
		//if (cnt) h += '<div>' + h.replace(/</ig, '&lt;') + '</div>';
		return h;
	};
     //get root elements of tree
	CTp.getRoot = function(){
		var n = this.nodes, c = [];
		for (var i = 0; i < n.length; i++)
		if (Undef(n[i].parent)) c[c.length] = n[i];
		return c;
	};
	//set current node
	CTp.setCurr = function(n){
		var t = this, o;
		if (n != t.curr){
			o = t.curr;
			t.curr = n;
			if (o) o.paint();
		};		
		//action 
		if (n){
				if (n.action.js) eval(n.action.js);
		 		//!!!  we go to url we have to open window, because after redrawing  handler stack set with null
				if (n.action && n.action.url){
					if (n.action.target)  window.open(n.action.url, n.action.target);
					else window.location.href = n.action.url;
				};
		};
	};
 	//<!--
	CTp.expandAll = function(){
		var n = this.nodes;
		for (var i = 0; i < n.length; i++) if (n[i].type && !n[i].state) n[i].setState();
	};
	CTp.collapseAll = function(){
		var n = this.nodes;
		for (var i = 0; i < n.length; i++) if (n[i].type && n[i].state) n[i].setState();
	};
	CTp.collapseItemById = function(_id){
		var n = this.nodes;
		for (var i = 0; i < this.nodes.length; i++)
		  if (n[i].type && n[i].state && n[i]._id == _id)
				n[i].setState();
	};
	CTp.expandItemById = function(_id){
		var n = this.nodes;
		for (var i = 0; i < n.length; i++)
			if (n[i].type && !n[i].state && n[i]._id == _id)
				n[i].setState();
	};
	CTp.collapseItemByText = function(text){
		var n = this.nodes;
		for (var i = 0; i < n.length; i++)
			if (n[i].type && n[i].state && n[i].text.indexOf(text)>-1)
				n[i].setState();
	};
	CTp.expandItemByText = function(text){
		var n = this.nodes;
		for (var i = 0; i < n.length; i++)
			if (n[i].type && !n[i].state && n[i].text.indexOf(text)>-1) n[i].setState();
	};
	CTp.getState = function(id){
		var t = this, n = t.getNode(id), p, v;
		if (n == null) {return null;} //no node
		p = n.parent; v = 1;
            while (p && v){
               v = v && p.state;
		   p = p.parent;		
            };
   		return v;
	};
	CTp.addNode = function(id, isChild, def){
		var t = this, n = t.getNode(id), p = null, l = t.nodes.length, c, s, s1, i;
		n = ((id)?t.getNode(id) : t.curr);
		//check parameters
		if (!def) {alert('Def is undefined!');return;};
		if (n == null && !isChild) {alert("Choose node to add sibling"); return;};
				
		if (isChild) {
		  p = n;
		  if (p!=null && !p.type) {p.type = 1;	p.state=1;}
		}else{
		  p = n.parent;
		  if (n.isLast) n.isLast = 0;
		};
		if (p) c = p.getChildren();
		else c = t.getRoot();
		//inherit styles
		if (p) s = p.style;
		else s = t.style;		
		if (!t.nomorestyle && (def.style || def.styleover) ){
			s1 = s.copy();
			s1.add(def.style, 0);
			s1.add(def.styleover, 1);
		} else {
			s1 = s;
		};
				
		if (t.style.lined && c.length > 0){
			c[c.length-1].isLast = false;
			for (i = 0; i < t.nodes.length; i++) t.nodes[i].level = '';
		};
			
		t.nodes[l] = new CNodeTree(l, p, 0, 0, def.text, def.id, def.onopen, def.onclose, def.action, t, 0, 1, s1, null);
		if (ua.oldB) alert("Don't support run-time functions!");
		else t.paint();		
	};
	CTp.deleteNode = function(id){
		var t = this, n, c, p;
		n = ((id)?t.getNode(id) : t.curr);
		if (n == null) {alert("Choose node to remove!"); return;};
		p = n.parent;
		if (p != null){
			c = p.getChildren();
			if (c.length==1) p.type = 0;
		}else{
			c = t.getRoot();
		};
		n.parent = -1;
		
		if (t.style.lined && c.length > 1){
			c[c.length-2].isLast = true;
			for (i = 0; i < t.nodes.length; i++) t.nodes[i].level = '';
		};
		
		if (ua.oldB) alert("Don't support run-time functions!");
		else t.paint();		
	};
	//-->
};//Ctp
function CNodeTree(id, parent, type, state, text, _id, onopen, onclose, action, tree, isf, isl, style){
      var t = this;
	t.id = id;
	t._id = _id;
	t.type = type;
	t.state = (Undef(state)) ? 0 : state*1;
	t.tree = tree;
	t.action = ((action)?action:{});
	t.text = (text)?text : '';
	if (ua.nn4 && !style.wrap) t.text = t.text.replace(/ /g,'&nbsp;');
	t.parent = parent;
	t.isFirst = isf;
	t.isLast = isl;
	t.onopen = onopen;
	t.onclose = onclose;
	t.style = style;
	t.level = '';
	t.levelid = ((parent) ? parent.levelid + 1 : 0);
	t.h = 0;
};
{
	var CNp = CNodeTree.prototype;
	CNp.itemToHTML = function(isOver){
		var t = this,  h = '',  sx = ((t.tree.curr == t) ? 'curr': ((t.type&&t.state) ? 'open' : '')), icon = '', o = CT_fe(t.getID()),
		s = t.style, sp = (t.parent)?t.parent.style:t.tree.style;
		s.setDefault();  icon = t.getIcon(isOver); if (!sp) sp = s;
		t.h = s.iheight*1;
		
		//make offset
		if (t.levelid>-1 && !t.level) {
			t.level +=  ((t.parent) ? t.parent.level : '')
			 + '<td nowrap' + sp.getH('ix', 'width')
	 		 + ((!ua.opera5 || s.lined)?((t.parent && !t.parent.isLast) ? ' style="background-repeat:repeat-y;' + s.getS('imgline', 'background-image') + '"' : ''):'')
	 	 	 + '>' + CT_bi (sp.ix,1) + '</td>';
		};
		//item table
	 	h += '<' + CT_TBL + s.getH('iwidth', 'width') + s.getH('iheight', 'height')
	 	 + ' style="'
	 	 + s.getS('color' + sx, 'color', isOver)
	 	 + s.getS('bgcolor' + sx, 'background-color', isOver)
	 	 + s.getS('bgimg' + sx, 'background-image', isOver)
	 	 + ((s.bwidth)? 'border-style:solid;' : '' ) + s.getS('bwidth', 'border-width', isOver) + s.getS('bcolor', 'border-color', isOver)
	 	 + '" ' + s.getH('css' + sx, 'class', isOver)
	 	 + '><tr>';// onClick="' + t.tree.ref() + '.setCurr(' + t.tree.ref() + '.nodes[' + t.id + '])"	 
	 	 //add offset for lined tree
	 	 if (t.levelid>-1 && s.lined) h += t.level;	 
	 	//icon
	 	h += '<td width="1%" nowrap' + ((s.wrap)?' valign="top"':'')
	 	+ ((!t.isLast && !t.isFirst && s.wrap) ? ' style="background-repeat:repeat-y;' + s.getS('imgline', 'background-image', isOver) + '"' : '')
	 	+ '><a' + t.actionOf(1) + ' id="' + t.getID('a') + '"><img src="' + icon + '" border="0" name="'+ t.getID('icon') +'" id="' + t.getID('icon') + '"></a></td>';
	 	//text check wrap parameter
	 	h += '<td width="99%" align="left"' + ((s.wrap)?'':' nowrap') + '>' + CT_bi(4, 1) //here is add offset after
	 	+ ((s.form) ? '' : '<a' + t.actionOf(0)  + ' style="font-weight:normal;font-style:normal;text-decoration:none;">')
	 	+ (( s.getH('css' + sx, 'class', isOver) || s.getS('color' + sx, 'color', isOver)) ? '<font' +  s.getH('css' + sx, 'class', isOver) + ' style="' + s.getS('color' + sx, 'color', isOver) +  '">' : '')
	 	+ t.text
	 	+ (( s.getH('css' + sx, 'class', isOver) || s.getS('color' + sx, 'color', isOver)) ? '</font>' : '')
	 	+ ((s.form) ? '' : '</a>')
	 	+ '</td></tr></table>';
	 	//shadow table
            if (!t.lined && s.swidth){
            	t.h += s.swidth*1;
            	h = '<' + CT_TBL + '>'
            	+ '<tr><td colspan=2 rowspan=2>' + h + '</td><td>' + CT_bi(s.swidth, s.swidth+1) + '</td></tr>'
            	+ '<tr><td width="' + s.swidth + '" height="' + (s.iheight- s.swidth-1) + '" bgcolor="' + s.scolor + '">' + CT_bi(1,1) + '</td></tr>'
            	+ '<tr><td width="' + s.swidth + '">' + CT_bi(s.swidth+1, 1) + '</td><td width="' + (s.iwidth-s.swidth-1) + '" bgcolor="' + s.scolor + '">' + CT_bi(s.swidth, s.swidth) + '</td>'
                  + '<td width="' + s.swidth + '" bgcolor="' + s.scolor + '">' + CT_bi(s.swidth, s.swidth) +  '</td></tr></table>';
            };
		//offset table for non lined tree
	 	if (t.levelid>-1	 && !s.lined) {
	 		h = '<' + CT_TBL + s.getH('iwidth', 'width') + s.getH('iheight', 'height') + '><tr>'  + t.level + '<td>'+ h + '</td></tr></table>';
	 	};
	 	//vertical offset
	 	if (sp.iy) {h += CT_bi(1, sp.iy); t.h += sp.iy*1;}
		return h;
	};
     CNp.getIcon = function(isOver){
		var t = this, s = t.style,  icon = '', sx =  ((t.isFirst) ? '_f' :  ((t.isLast)?'_l' : ''));
		if (t.type){
			if (t.state) {icon = s.get('imgdiropen' + sx, isOver);}
			else {icon = s.get('imgdir' + sx, isOver);}
		} else {
			icon = s.get('imgitem' + sx, isOver);
		};
		return icon;
     	};
     CNp.paint = function(isOver){
     	   var t = this, o = CT_fe(t.getID());
     	  // if (isOver && !t.style.over_source) return; //no over style defined
     	   if (o){
     	   	   	CT_HTML(t.getID(), t.itemToHTML(isOver));
     	   };
     };
     CNp.paintChildren = function(){
	     	 var t = this, o = CT_fe(t.getID('dir'));
	     	 if (o){
	     	 	o.innerHTML = t.toHTML(1);
	     	 };
     	};
     CNp.getChildren = function(){
	 	var n = this.tree.nodes, c = [];
	 	for (var i = 0; i < n.length; i++)
	 		if (n[i].parent == this) {c[c.length] = n[i];}
	 	return c;
	 };
	  CNp.showFolder = function(){
	 	var t = this, dir = CT_fe(t.getID('dir'));
	    	if (!dir || ! dir.style) return;
	 	dir = dir.style;
	 	if (t.state){
		 	dir.display = 'block';
		 	dir.visibility = 'visible';
		}else{
		 	dir.display = 'none';
		 	dir.visibility = 'hidden';
		};
		t.paint(t.tree.curr==t);
		//<!--
	 	 if (t.tree.savestate) CodeThat.writeCookie(t.getID(), t.state, 86400000);
	 	//-->
	 };
	 CNp.setState = function(state){
	 	var t = this, dir, i, c;
	 	if (Undef(state)) state = !t.state;
	 	t.state = state;
	 	if (t.type) {
	 		if (t.style.singlecol && !ua.oldB){
	 			c = (t.parent) ? t.parent.getChildren() : t.tree.getRoot();
	 			for (i = 0; i < c.length; i++){
	 				if (c[i] != t) {
	 					c[i].state = 0;
	 					c[i].showFolder();
	 				};
	 			};
	 		};
	 		if (ua.oldB) t.showFolderOldB(); else t.showFolder();	 		 
	 	};
	 	//<!--
	 	if (t.state && Def(t.onopen)) eval(t.onopen);
		if (!t.state && Def(t.onclose)) eval(t.onclose);
		//-->
	 };
	 CNp.showFolderOldB = function(){ };
	 CNp.getID = function(p){
	 	if (!p) {p = '';} else {p += '_';}
	 	return  this.tree.id + '_' + p + this.id;
	 };
       CNp.toHTML = function(childonly){
	 	var t = this, i, h = ((childonly) ? '' :  '\n<div id="' + t.getID() + '">' + t.itemToHTML() + '</div>'), c;
	    	if (t.type){
	 		c = t.getChildren();
	 		if (!childonly) h += '\n<div id="' + t.getID('dir') + '" style="visibility:' + ((t.state)? 'visible' : 'hidden')
	 		+ ";display:" + ((t.state)? 'inline' : 'none')
	 		+ ';">';
	 		for (i = 0; i < c.length; i++){
	 			h += c[i].toHTML();	 			
	 		};
	 		if (!childonly) h += '\n</div>';
	 	}
	 	return h;
	 };
//user defined actions for node, all service actions for new browser - in CT_setCurr, CT_setOver
	 CNp.actionOf = function(isIcon){
	 	 var t = this, h = '', a = t.action, f, folderAction = ((ua.oldB && t.type)? t.tree.ref() + '.nodes['+t.id+'].setState()':'');
	 	 if (!isIcon) isIcon = 0;
	 	 f = (t.tree.useiconlink && isIcon) || !isIcon;
	 	 a.target = (a.target) ? a.target : t.tree.target;
	 	 if (f){
	 	 	if (a.url) {
	 	 		h += ' href="' + a.url + '"';
	 	 		if (a.url && a.url.indexOf("javascript:")>-1) a.target = 0;
	 	 	} else h += ' href="javascript:void(0);"';
	 	 	if (a.js) h += ' onClick="' + folderAction + a.js + '"';
	 	 	else if (ua.oldB) h += ' onClick="' + folderAction + '"';
	 	 	if (a.js2) h += ' onDblClick="' + a.js2 + '"';
		 	if (a.jsover) h += ' onMouseOver="' + a.jsover + '"';
		 	if (a.jsout) h += ' onMouseOut="' + a.jsout + '"';
		 	if (a.title) h += ' title="' + a.title + '"';
		 	if (a.target) h += ' target="' + a.target + '"';
	 	 }else{
	 	 	h += ' href="' + ((ua.oldB)? 'javascript:' + folderAction : '#') + '"';
	 	 };
	  	 return h;
	 };
};//Cnp
//Style object
//item - item of common style
//over_item - item of over style
function CStyle(s, tree){
	var t = this, i;
	t.source = s;
	t.tree = tree;
	t.init = 0;
	if (s) {
		//put properties into object
		for (i in s) {
			if (typeof(s[i]) == 'function') continue;
			if (typeof(s[i]) == 'string'){
				//check boolean
				if (s[i].toLowerCase() == 'true') s[i] = 1;
				if (s[i].toLowerCase() == 'false') s[i] = 0;
				//check numbers
				if (!isNaN(s[i]*1)) s[i] = s[i]*1;
			};
			t[i] = s[i];
		};
		//put icons into tree.icons for preload
		for (i in t) {
			if (!t.tree) return;
			if (i.indexOf('img')>-1 && t.tree.icons.indexOf(t[i]) < 0){
				t.tree.icons[t.tree.icons.length] = t[i];
			};
		};
	};//if
};
{
	var CSp = CStyle.prototype;
	//add parameters to current object
	CSp.add = function(s, isOver){
		var t = this, i;
		if (Undef(isOver)) isOver = 0;
		if (s){
			for (i in s) {
				if (typeof(s[i]) == 'function') continue;
				if (typeof(s[i]) == 'string'){
					//check boolean
					if (s[i].toLowerCase() == 'true') s[i] = 1;
					if (s[i].toLowerCase() == 'false') s[i] = 0;
					//check numbers
					if (!isNaN(s[i]*1)) s[i] = s[i]*1;
				};
				if (isOver) {t['over_' + i] = s[i];}
				else {t[i] = s[i];}
			};//for
			if (isOver) t.over_source= s;
			else t.source = s;
		};//if
	};//function
	//copy object
	CSp.copy = function(){
		var t = this, style = new CStyle(null, t.tree), i;
		for (i in t) {
			if (typeof(t[i]) == 'function') continue;
			style[i] = t[i];
		};
		return style;
	};
	//set defaults values in StyleObject
	CSp.setDefault = function(isTree){
		var t = this;
		if (t.init) return;
		//set tree defaults
		if (isTree){
			t.twidth = ((t.fixwidth) ? t.fixwidth : 0);
			t.theight = ((t.fixheight) ? t.fixheight : 0);
		};
		//set item defaults
		t.iwidth = 100; t.ix = 20; t.bwidth = 0; t.swidth = 0;
		t.iheight = 20;  t.iy = 0;   t.bcolor = ''; t.scolor = '';
		//check offset
		o = t.itemoffset;
		if (o){
			t.ix = ((o.x) ? o.x : o[0]);
			t.iy = ((t.lined) ? 0 : ((o.y) ? o.y : o[1]));
		};
		//check border
		o = t.border;
		if (o){
			t.bwidth = o.width;
			t.bcolor = o.color;
		};
		//check border
		o = t.shadow;
		if (o){
			t.swidth = o.width;
			t.scolor = o.color;
		};
		//check size
		o = t.size;
		if (o){
			t.iwidth = ((o.width) ? o.width : o[0]);
			t.iheight = ((o.height) ? o.height : o[1]);
		}else{
		   	if (t.tree && t.tree.style && t.tree.style.twidth && t.form) {t.iwidth = t.tree.style.twidth;};
			if (!t.swidth && !ua.oldB) t.iheight = null;
		};
		if (!t.z) t.z = 1;
		//check appearance
		cp = ['css', 'color', 'bgimg', 'bgcolor', 'over_css', 'over_color', 'over_bgimg', 'over_bgcolor'];
		for (i = 0; i < cp.length;i++){
			if (!t[cp[i]]) continue;
			if (!t[cp[i]+'open']) t[cp[i]+'open'] = t[cp[i]];
			if (!t[cp[i]+'curr']) t[cp[i]+'curr'] = t[cp[i]];
		};
		//check icons
		if (!t.imgblank) t.imgblank = CT_IMG_BLANK;
		if (!t.imgline) t.imgline = t.imgblank;
		cp = ['imgitem', 'imgdir', 'imgdiropen', 'imgline'];
		for (i = 0; i < cp.length;i++){
			if (!t[cp[i]]) t[cp[i]] = t.imgblank;
			if (!t[cp[i]+'_l']) t[cp[i]+'_l'] = t[cp[i]];
			if (!t[cp[i]+'_f']) t[cp[i]+'_f'] = t[cp[i]+'_l'];
			if (!t['over_' + cp[i]]) t['over_'+cp[i]] = t[cp[i]];
			if (!t['over_'+cp[i]+'_l']) t['over_'+cp[i]+'_l'] = ((t.lined) ? t[cp[i]+'_l'] : t['over_'+cp[i]]);
		};
		t.init = 1;
	};
	//to string
	CSp.toString = function(){
		var t = this, i, s = '';
		for (i in t){
			if (typeof(t[i]) != 'function')
				s += ((s=='')?'':'\n') + i + '\t' + t[i];
		};
		return s;
	};
	//get HTML attribute from CStyle.name or CStyle.over_name
	CSp.getH = function(name, attr, isOver){
		var t = this, value, h = '';
		if (Undef(isOver)) isOver = 0;
		value = ((isOver) ? ((t['over_' + name]) ? t['over_'+name] : t[name]) : t[name]);
		if (value){
			h = ' ' + attr + '="' + value + '"';
		};
		return h;
	};
	//get CSS attribute from from CStyle.name or CStyle.over_name
	CSp.getS = function(name, attr, isOver){
		var t = this, value, h = '', np = ['width', 'height', 'top', 'left'];
		if (Undef(isOver)) isOver = 0;
		if (attr == 'background-image')
		      value = ((isOver) ? t['over_'+name] : t[name]);
		else
			value = ((isOver) ? ((t['over_' + name]) ? t['over_'+name] : t[name]) : t[name]);
		if (value){
			h =  attr + ':' + ((attr=='background-image') ? 'url(' + value + ')': value) + ((np.indexOf(attr)>-1 || attr=='border-width')? 'px' : '') + ';';
		};
		return h;
	};
	//get parameter value
	CSp.get = function(name, isOver){
		var t = this;
		if (Undef(isOver)) isOver = 0;
		return ((isOver) ? ((t['over_' + name]) ? t['over_'+name] : t[name]) : t[name]);
	};
};//Csp
//Global variables and functions
//Find element at page
function CT_fe(o){return CodeThat.findElement(o);};
//Parse boolean value
function CT_bool(o, d){
	if (Undef(o)) return d;
	if (typeof(o) == 'string'){
		if (o.toLowerCase()=='true') return 1;
		else return 0;
	}else{
		return o*1;
	};
};
//set blank image
function CT_bi(w, h){
	return '<img src="' + CT_IMG_BLANK + '" width="' + w + '" height="' + h + '" border="0">';
};
//register handlers

if (!ua.oldB){
	// heb removed this 040607 :: CodeThat.regEventHandler('mouseover', CT_setOver);
	CodeThat.regEventHandler('mouseup', CT_setCurr);
};

//onmouseover handler, set over node in current tree CT_Tree
function CT_setOver(e){
      var n = CT_getTree(e.target);
      if (!CT_Tree || (CT_Tree.over && CT_Tree.over.id == n)) return true;
      if (CT_Tree.over) CT_Tree.over.paint();
      if (n == -1) CT_Tree.over = null;
      else {
      	CT_Tree.over = CT_Tree.nodes[n];      
      	//proceed over expand
      	 if (CT_Tree.style && CT_Tree.style.overexpand){
      	 	   CT_Tree.over.setState(1);
		 };
      	CT_Tree.over.paint(1);
      };
      return true;
};

//onclick handler, set current node in current tree CT_Tree
function CT_setCurr(e){	
  var n = CT_getTree(e.target);
  if (n>-1)  {
  	CT_Tree.setCurr(CT_Tree.nodes[n]);
      CT_Tree.curr.setState();
      CT_Tree.curr.paint(0);
  };
  return true;
};
//get top level container as DIV or BODY
function CT_getParent(src){
	while (Def(src) && (Undef(src.tagName) || (src.tagName.toLowerCase() != "div" && src.tagName.toLowerCase() != "body"))){
		src = ((ua.ie) ? src.parentElement : src.parentNode);
	};
	return src;
};
//get current Tree object from container o
function CT_getTree(o){
	o = CT_getParent(o);
	var s = (o && o.id) ? o.id : '',  tree_id = s.replace(/(_\d+)$/i, ''),  node_id = s.replace(new RegExp(tree_id+"_", "i"), '');
	//document.title = ' s= ' + s + ' t= ' + tree_id + ' n=' + node_id;
 	if (tree_id) CT_Tree = CodeThatTreeRoots[tree_id];
 	node_id = (Undef(node_id) || isNaN(node_id*1)) ? -1 : node_id;
 	return node_id;
};
//Additional array functionality
var a = Array.prototype;
a.indexOf = function(e){
		for (var i = 0; e && i < this.length; i++)
		if (this[i] && e.valueOf() == this[i].valueOf()) return i;
		return -1;
};
//-----------------------------------------------------------------------------
//old browser code
//-----------------------------------------------------------------------------
{
	var CTp = CTree.prototype;
	CTp.paintOldB = function(){
		var t = this, i, n, state=0, p = [t.x, t.y],  o;
		for (i=0; i < t.icons.length; i++) CodeThat.preload(t.icons[i]);
		n = t.nodes;
		dw(t.toHTMLOldB());
	};
	CTp.toHTMLOldB = function(){
		var t = this, c = t.getRoot(), i, h = '', p = t.position, x = 0, y = 0, m = ((ua.nn4) ? 30 : 20);
		if (p && p.pos){
			x = (p.pos.x)? p.pos.x : p.pos[0];
			y = (p.pos.y)? p.pos.y : p.pos[1];
		};
		//start point of tree
		if (!x) x = 10; t.x = x;
		if (!y) y = 10; t.y = y;
		if (!t.style.fixwidth) t.style.fixwidth=100;
		if (t.nodes.length > 20) m = 10;
		p = [x,y,y, 0];
		for (i = 0; c && i < c.length; i++) {h+= c[i].toHTMLOldB(p, 1);}
		h = '<div id="' + t.id + '" style="' + CT_pp(p, 1, {iwidth:t.style.twidth, iheight:t.style.theight}) + '">&nbsp;</div>' + h;
		h += "<div id='pos' style='position:relative;top:0;left:0;'><img alt='Tree loading...' name='bg' id='bg' src='" + CT_IMG_BLANK + "' width="+ (t.style.fixwidth) +" height=" + t.nodes.length*m + " border=0></div><br><br><br>";
		//debug
		//h += '<div>' + h.replace(/</ig, '&lt;') + '</div>';
		return h;
	};
	CTp.draw = function(){
	    var t  = this, n = t.nodes;
	     if (!ua.oldB) return;
		//get offset y for old browsers
		var o, posY, p = t.position;   if (!p) p = {absolute:false};
		o = CT_fe("pos");
		
		if (!o) {window.setTimeout(t.ref() + ".draw()", 100); return;}
	   
		if (Def(o) && !p.absolute){
		  if (Undef(p) || Undef(p.pos)) p = [10, 10]
		  else p = [p.pos[0], p.pos[1], 0];
		  posY = CT_getAbsTop(o) + ((!ua.nn4)?8:0);
		  if (Undef(posY)) {window.setTimeout("CodeThatTreeRoots['" + t.id + "'].draw()", 100); return;};
		  for (var i=0; i < n.length && Def(posY) && posY>p[1]; i++){
		  	 o = CT_fe(n[i].getID());
		  	 if (Def(o)) {	  	 	
		  	 	 if (ua.nn4) {
		  	 	 	o.top += (posY - p[1]);
		  	 	 	o.width = CT_getWidth(o);
		  	 	 } else {
		  	 	 	o.style.top += (posY - p[1]);
		  	 	 	o.style.width = CT_getWidth(o);
		  	 	 };
		  	 };//def o
	 	   };//for
	     };//def o
	     
	     for (i = 0; i < n.length; i++){
	     	     n[i].state = CT_bool(CodeThat.readCookie(n[i].getID())) || !t.savestate;
			if (n[i].type && !n[i].state) {
				n[i].showFolderOldB();								
			};
		};		
		n = t.getRoot();
		for (i = 0; i < n.length; i++){
			o = CT_fe(n[i].getID());
			if (!o) continue;
			if (ua.nn4){
				o.visibility = 'visible';	
			}else{
				o.style.visibility = 'visible';
			};
		};
	     
	  };//draw
};
{
	var CNp = CNodeTree.prototype;
	 CNp.showFolderOldB = function(){
	 	 var t = this, c, height, o, top=0, i, offsety;
	 	 c = t.countChildren(1);
		 height = t.heightChildren(1);
		offsety = t.getNodeHeight();
		 if (t.tree.lined) offsety -= 1;
		 CT_setIS(t.getID("icon"), t.getIcon());
		 if (t.state){
		 	o = CT_fe(t.getID());
			if (Def(o)) top = top + ((ua.nn4) ? o.top : o.style.top);
			for (i = t.id + c; i < t.tree.nodes.length; i++){
				o = CT_fe(t.tree.nodes[i].getID());
				if (Undef(o)) continue;
				if (ua.nn4) o.top += height;
				else o.style.top += height;
			};
			t.setVisibility('visible', [offsety, top]);
		 }else{		 
		 	t.setVisibility(((ua.nn4) ? 'hide' : 'hidden'), [offsety, top]);
			for (i = t.id + c; i < t.tree.nodes.length; i++){
				o = CT_fe(t.tree.nodes[i].getID());
				if (Undef(o) || (ua.nn4 && o.visibility=='hide') || (!ua.nn4 && o.style.visibility=='hidden')) continue;
				if (ua.nn4) o.top -= height;
				else o.style.top -= height;
			};
		 };
	 };
	 CNp.toHTMLOldB = function(pos, vis){
		  var t = this;
		 //t.text += ' ' + pos;
		  var i , h =  t.itemToHTML(0) , over = t.tree.usedual, c;
		  if (vis) pos[3]++;
		  //make layers normal + over if usedual==1
		  h = '<div id="' + t.getID() + '" style="' + CT_pp(pos, vis, t.style) + '"' + ((!ua.nn4 && over && t.style.over_source)?' onMouseOver="CT_setOverOldB(null, ' + t.id + ', ' + t.tree.ref() + ')"':'')+ '>' + h + '</div>';
		  if (over && t.style.over_source) { h +=  '<div id="' + t.getID('over') + '" style="' + CT_pp(pos, 0, t.style) + '">' + t.itemToHTML(1) + '</div>';}
	        pos[0] = pos[0]*1;pos[1] = pos[1]*1;pos[2] = pos[2]*1;
	        if (vis){
	        	pos[2] += t.h;
	        };
	         pos[1] += t.h;  
	         if (t.type){
	         	vis = (vis && t.state);
	         	c = t.getChildren();
			for (i = 0; i < c.length; i++) {h += c[i].toHTMLOldB(pos,vis);}
	        };
	      return h; 
	};
	CNp.countChildren = function(v){
	   	var c = this.getChildren(), i, count = (v) ? 0 : c.length;
	   	for (i=0; i < c.length; i++) {
	   		if (v){
	   			if ((c[i].type && !c[i].state) || !c[i].type) count++;
	   			else count += c[i].countChildren(v) + 1;
	   		}else{
	   			count += c[i].countChildren(v);
	   		};
	   	};
	   	return count;
	};
	CNp.heightChildren = function(v){
	   	var t = this, i, c = t.getChildren(), height = 0;
	   	var s = (Def(t.style)) ? t.style : t.tree.style;
	   	for (i=0; i < c.length; i++) {
	   		height += c[i].getNodeHeight();
	   		if (v){
	   			if (c[i].type && c[i].state) height += c[i].heightChildren(v);
	   		}else{
	   			height += c[i].heightChildren(v);
	   		};
	   	};
	   	return height;
	};
	CNp.getNodeHeight = function(){
		var t = this, o = CT_fe(t.getID()), height1 = 0;
		if (Def(o)) height1 = CT_getHeight(t.getID());
 		if (height1 - t.h > 10) t.h = height1;
 		return t.h;
	};
	CNp.setVisibility = function(value, pos, s){
	  var c = this.getChildren(), o;
	  for (var i = 0; i < c.length; i++){
	  		o = CT_fe(c[i].getID());
	  		if (pos[0] != c[i].getNodeHeight()){
	  			pos[1] += pos[0];
	  			pos[0] = c[i].getNodeHeight();
	  	   }else pos[1] += pos[0];
	  	   if (Def(o)){
	  	   	if (!ua.nn4) o = o.style;
	  	   	o.visibility = value;
	  	   	if (value == 'visible') o.top = pos[1];
	  	   	if (c[i].type && !c[i].state) continue;
				c[i].setVisibility(value, pos);
			};
		};
	};
};
//-----------------------------------------------------------------------------
//handlers
//-----------------------------------------------------------------------------
if(ua.oldOpera) {
	function CT_Tree_Redraw(){
		if (Undef(window._FJS_reloading)){
			window._FJS_reloading = 1;
			location.reload();
		}
	};
	CodeThat.setResizeHandler(CT_Tree_Redraw);
};

if (ua.nn4) {
	CodeThat.regEventHandler('mouseover', CT_setOverOldB);
};

//set position parameters
function CT_pp(pos, vis, s){
	var v=['hidden', 'visible'];
	return 'position:absolute;top:' + pos[1] + 'px;left:' + pos[0] + 'px;width:' + s.iwidth + 'px;height:' + s.iheight + 'px;visibility:' + v[vis] + ';';
};
function CT_setOverOldB(e, id, tree){
	 //nn4 handler
	 if (e){
	 	var s = (e.target && e.target.id) ? e.target.id : '', tree_id = s.replace(/(_\d+)$/i, ''),  node_id = s.replace(new RegExp(tree_id+"_", "i"), '');
	 	if (tree_id)  tree = CodeThatTreeRoots[tree_id];
 		id = (Undef(node_id) || isNaN(node_id*1)) ? -1 : node_id;
	 };
	//opera handler
	if (tree && Def(id) && id > -1){
		var n1 = tree.over, n2 = tree.nodes[id], out, over;
		if (n1 != n2){
			if (n1){
				out = CT_fe(n1.getID());
				over = CT_fe(n1.getID('over'));
				CT_setVO(over, out);
			};
			out = CT_fe(n2.getID());
			over = CT_fe(n2.getID('over'));
			CT_setVO(out, over);
			tree.over = n2;
		};
	};
	return true;
};
//old browser visibility
function CT_setVO(o, o1){
	if (Undef(o) || Undef(o1)) return;
	if (!ua.nn4) {o = o.style; o1 = o1.style;}
	o.visibility = (ua.nn4) ? 'hide' : 'hidden';
	o1.visibility = 'visible';
	o1.top = o.top;
	o1.left = o.left;
	o1.width = o.width;
};
function CT_setIS(img, src){
	var i, j, l;
	if (ua.nn4){
	 for (j=0; j<window.document.layers.length; j++){
	 	l = window.document.layers[j];
	 	if (Undef(l.document) || Undef(l.document.images)) continue;
	 	l = l.document.images;
		for (i=0; i < l.length; i++)
			if (l[i].name == img)
				l[i].src = src;
	 };
	}else{
		l = window.document.images;
		for (i=0; i < l.length; i++)
			if (l[i].id == img) l[i].src = src;
	};
};
//------------------------------------------------------------------------------