// Title: Tigra Tree Menu PRO
// URL: http://www.softcomplex.com/products/tigra_menu_tree_pro/
// Version: 1.2
// Date: 05-07-2004 (mm-dd-yyyy)
// Technical Support: support@softcomplex.com (specify product title and order ID)
// Notes: Registration needed to use this script legally.
// Visit official site for details.

// ------------------------------------------------------------------------------------------
// tree constructor
// ------------------------------------------------------------------------------------------
function tree (a_items, a_template, s_name) {
	var i;
	this.a_tpl      = a_template;
	this.a_config   = a_items;
	this.o_root     = this;
	this.a_index    = [];
	this.a_nodes    = [];
	this.o_selected = 0;
	this.n_depth    = -1;
	this.ms = Boolean(a_template['multiselections']);
	this.ce = a_template['cookie_ext']?a_template['cookie_ext']:'';
	this.solid = a_template['b_solid'];
	this.rc = a_template['b_rootcollapse']?0:1;
	this.s_ol = a_template['outerLayer'];
	this.s_il = a_template['innerLayer'];
	
	// preload all images
	var o_icone = new Image(),
		o_iconl = new Image();
	o_icone.src = a_template['icon_e'];
	o_iconl.src = a_template['icon_l'];
	a_template['im_e'] = o_icone;
	a_template['im_l'] = o_iconl;
	for (i = 0; i < 128; i++)
		if (a_template['icon_' + i]) {
			var o_icon = new Image();
			a_template['im_' + i] = o_icon;
			o_icon.src = a_template['icon_' + i];
		} else 
		if (a_template['icon_c' + i]) {
			var o_icon = new Image();
			a_template['im_c' + i] = o_icon;
			o_icon.src = a_template['icon_c' + i];
		}
	
	// item toggle routine
	this.toggle = function (n_id) {
		var o_item = this.a_index[n_id];
		o_item.open(o_item.n_state & 8);
	};
	// on item select handler
	this.select = function (n_id) {
		if(this.ms) {
			var o_item = this.a_index[n_id];
			return o_item.select(o_item.n_state & 4);
		}
		return this.a_index[n_id].select(0,b_cb);
	};
	this.check = function (n_id) {
		var o_item = this.a_index[n_id];
		return o_item.check(o_item.n_state & 4);
	};
	// on mouse over event handler
	this.mover = function (n_id) {
		var o_item = this.a_index[n_id];
		o_item.upstatus();
		o_item.mover(true);
	};
	// on mouse out event handler
	this.mout = function (n_id) {
		var o_item = this.a_index[n_id];
		o_item.upstatus(true);
		o_item.mout(true);
	};
	// find item by caption/link method
	this.find_item = function (s_value, b_link) {
		var a_items = [];
		b_link = b_link?1:0;
		for (var i = 0; i < this.a_index.length; i++)
			if (this.a_index[i].a_config[b_link] == s_value) {
				a_items[a_items.length] = this.a_index[i];
			}
		return a_items;
	};
	this.find_item_by_key = function (s_key, s_value) {
		var a_items = [];
		for (var i = 0; i < this.a_index.length; i++)
			if (this.a_index[i].a_config[2] && this.a_index[i].a_config[2][s_key] == s_value) {
				a_items[a_items.length] = this.a_index[i];
			}
		return a_items;
	};
	this.find_item_by_state = function (n_mask) {
		var a_items = [];
		for (var i = 0; i < this.a_index.length; i++)
			if (this.a_index[i].n_state & n_mask) {
				a_items[a_items.length] = this.a_index[i];
			}
		return a_items;
	};

	// for non-DOM browser updates the tree after batch of commands
	this.b_needreload = false;
	this.ndom_refresh = function () {
	if (!B_DOM && this.b_needreload)
		window.location = window.location;
	};		
	
	// reset persistance information method
	this.reset_state = function () {
		document.cookie = 'tree_' + this.n_id + '_state=;'+this.ce;
		document.cookie = 'tree_' + this.n_id + '_selected=;'+this.ce;
		this.a_states = [];
		this.a_select = [];
	};
	
	this.rewind_selection = function () {		
		this.a_select = 0;
		this.a_select = obj2obj(this.a_reselect);
		for (var i = 0; i < this.a_index.length; i++) {
			var o_item = this.a_index[i],
				n_wordindex = Math.floor(o_item.n_id / 31),
				b_reselect = Boolean(this.o_root.a_select[n_wordindex] & (1 << (o_item.n_id % 31)));
				
			if (b_reselect != Boolean (o_item.n_state & 4)) {
				if(o_item.select) o_item.select(!b_reselect,1);
				else {
					if(b_reselect) o_item.n_state |= 4;
					else o_item.n_state &= ~4;
					if(!o_item.selsave) o_item.selsave = item_selsave;
					o_item.selsave();
				}
			}
		}
	};
	
	this.get_rewind_status = function (){
		return (Boolean(this.a_select.join('') == this.a_reselect.join('')));
	};

	// update global variables
	B_DOM = Boolean(document.body && document.body.innerHTML);
	this.n_id = s_name?s_name:TREES.length;
	TREES[this.n_id] = this;
	
	// read states data from cookies
	this.parse_cookies = function(a_cookies, s_key) {
		var re_cookie = new RegExp('^\\s*(\\S+)\\s*=\\s*(\\S*)\\s*$'),s_value;
		for (var i = 0; i < a_cookies.length; i++) {
			if (!re_cookie.exec(a_cookies[i]) || RegExp.$1 != s_key)
				continue;
			s_value = RegExp.$2;
			return s_value.split('_');
		}
		return [0];
	};
	var a_cookies = document.cookie.split(';'),
		s_key1 = 'tree_' + this.n_id + '_state',
		s_key2 = 'tree_' + this.n_id + '_selected';
	this.a_restates = obj2obj(this.a_states = this.parse_cookies(a_cookies,s_key1));
	this.a_reselect = obj2obj(this.a_select = this.parse_cookies(a_cookies,s_key2));
	if (!this.a_states.length) this.loadfix = true;

	// index all tree items	
	this.a_children = [];
	for (i = 0; i < a_items.length; i++)
		this.a_children[this.a_children.length] = new tree_item(this, i);	
	
	if (a_template['beforeInit']) {
		eval ('var b_result=' + a_template['beforeInit'] + '(this);');
		if (!b_result) return false;
	}
	for (i = 0; i < this.a_children.length; i++) {
		this.a_children[i].init = item_init;
		document.write(this.a_children[i].init());
	}
	if (a_template['afterInit'])
		eval (a_template['afterInit'] + '(this);');
}

// ------------------------------------------------------------------------------------------
// item constructor
//  minimal actions required to index the item, minimal memory allocation
//  this constructor is run for all items of the tree
// ------------------------------------------------------------------------------------------
function tree_item (o_parent, n_order) {

	this.o_root   = o_parent.o_root;
	this.n_depth  = o_parent.n_depth + 1;
	this.a_config = o_parent.a_config[n_order + (this.n_depth ? 3 : 0)];
	this.o_parent = o_parent;
	this.n_order = n_order;

	// ignore commas after the last item of the list
	while (!this.a_config[this.a_config.length - 1])
		this.a_config.length = this.a_config.length - 1;

	// register in items index
	this.n_id = this.o_root.a_index.length;
	this.o_root.a_index[this.n_id] = this;

	this.n_state = 0;

	if (this.a_config[2] && typeof(this.a_config[2]['sl']) == 'number') {
		if (Boolean(this.a_config[2]['sl'])) {
			if(!this.o_root.ms) {
				if(this.o_root.o_selected) this.o_root.o_selected.n_state &= ~4;
				this.o_root.o_selected = this;
			}
			this.n_state |= 4;
		}
	} else {
		var n_wordindex = Math.floor(this.n_id / 31);
		if (Boolean(this.o_root.a_select[n_wordindex] & (1 << (this.n_id % 31))))  {
			if(!this.o_root.ms) {
				if(this.o_root.o_selected) this.o_root.o_selected.n_state &= ~4;
				this.o_root.o_selected = this;
			}
			this.n_state |= 4
		}
	}

	this.b_fnode = (this.a_config[2]?this.a_config[2]['fn']:0);

	// if leaf no more initialization at this stage
	if (this.a_config.length < 4 && !this.b_fnode)
		return;
	// register in nodes index
	this.n_node_id = this.o_root.a_nodes.length;
	this.o_root.a_nodes[this.n_node_id] = this;

	// init items recursively
	this.a_children = [];
	for (var i = 3; i < this.a_config.length; i++) {
		var o_item = this.a_children[this.a_children.length] = new tree_item(this, i - 3);
		o_item.init = item_init;
	}
}

// ------------------------------------------------------------------------------------------
// item open/close routine
// node will be closed if b_close == true
// ------------------------------------------------------------------------------------------
function item_open (b_close, b_noreload, b_nohandlers) {

	// skip if node is already in the requested state
	if (Boolean(this.n_state & 8) != Boolean(b_close)) return;

	// run cusom handler
	var s_hdlr = (this.a_config[2] ? this.a_config[2][b_close ? 'hc' : 'ho'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl[b_close ? 'onItemClose' : 'onItemOpen']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}

	// update state indicator
	this.n_state ^= 8;
	this.o_root.b_needreload = true;

	// update styles and images
	this.state_lookup();
	
	// update status line
	this.upstatus();

	// save state to cookies
	this.save();

	// update child items just on page if modern browser
	if (B_DOM) {
		if(this.a_config.length > 3) {
			var o_idiv = get_element('c' + this.o_root.n_id + '_' + this.n_id);
			if (!o_idiv.innerHTML)
				o_idiv.innerHTML = this.subhtml();
			o_idiv.style.display = (b_close ? 'none' : 'block');
		}
	}
	// run cusom handler
	var s_hdlr = (this.a_config[2] ? this.a_config[2][b_close ? 'hac' : 'hao'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl[b_close ? 'onItemAfterClose' : 'onItemAfterOpen']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}
	// reload page if ancient browser
	else if (!b_noreload && this.a_config.length > 3)
		window.location = window.location;
}

// ------------------------------------------------------------------------------------------
// item select/deselect routine
// node will be deselected if b_deselect == true
// ------------------------------------------------------------------------------------------
function item_select (b_deselect, b_nohandlers) {
	// run cusom handler
	var s_hdlr = (this.a_config[2] ? this.a_config[2][b_deselect ? 'hd' : 'hs'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl[b_deselect ? 'onItemDeselect' : 'onItemSelect']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}
	if (b_deselect) {
		this.n_state &= ~4;
	}
	else {
		if(!this.o_root.ms) {
			var o_olditem = this.o_root.o_selected;
			if (o_olditem) o_olditem.select(true);
			this.o_root.o_selected = this;
		}
		this.n_state |= 4;
	}
	this.selsave();
	// update styles and images
	this.state_lookup();

	// update status line message	
	this.upstatus();
	var s_hdlr = (this.a_config[2] ? this.a_config[2][b_deselect ? 'had' : 'has'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl[b_deselect ? 'onItemAfterDeselect' : 'onItemAfterSelect']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}
	return Boolean(this.a_config[1]);
}

function item_check (b_deselect, b_nohandlers) {
	// run cusom handler
	var s_hdlr = (this.a_config[2] ? this.a_config[2][b_deselect ? 'huc' : 'hck'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl[b_deselect ? 'onItemUncheck' : 'onItemCheck']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}
	if (b_deselect) {
		this.n_state &= ~4;
	}
	else {
		this.n_state |= 4;
	}

	this.selsave();
	// update styles and images
	this.state_lookup();

	// update status line message	
	this.upstatus();
	var s_hdlr = (this.a_config[2] ? this.a_config[2][b_deselect ? 'hach' : 'hauc'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl[b_deselect ? 'onItemAfterUncheck' : 'onItemAfterCheck']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}
}

// ------------------------------------------------------------------------------------------
// item mouseover routine
// ------------------------------------------------------------------------------------------
function item_mover(b_nohandlers) {

	// run cusom handler
	var s_hdlr = (this.a_config[2] ? this.a_config[2]['hv'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl['onItemMover']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}
	this.n_state |= 64;
	// update styles and images
	this.state_lookup();
}

// ------------------------------------------------------------------------------------------
// item mouseout routine
// ------------------------------------------------------------------------------------------
function item_mout(b_nohandlers) {

	// run cusom handler
	var s_hdlr = (this.a_config[2] ? this.a_config[2]['hu'] : null);
		s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl['onItemMout']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}
	this.n_state &= ~64;
	// update styles and images
	this.state_lookup();
}

// ------------------------------------------------------------------------------------------
// focuses browser to the item
// ------------------------------------------------------------------------------------------
function item_focus () {
	function sum (img, o_div) {
		var x = 0;
		for (; img && img != o_div; img = img.offsetParent) {
			x += img.offsetTop;		
		}
		return x;
	};
	var o_div = get_element(this.o_root.s_ol);
	var o_idiv = get_element('fc' + this.o_root.n_id + '_' + this.n_id);
	if(o_idiv) {
//		o_div.scrollTop = sum(o_idiv, o_div);
//		alert(sum(o_idiv, o_div))
		o_idiv.style.display = 'block';
		var n_dif = parseInt(o_div.style.height)-sum(o_idiv, o_div);
		if(o_div.scrollTop+n_dif<0) {
			o_div.scrollTop = -n_dif;
		}
		o_idiv.style.display = 'none';
	}
}

// ------------------------------------------------------------------------------------------
// updates status bar message of the browser
// ------------------------------------------------------------------------------------------
function item_upstatus (b_clear) {
	window.setTimeout("window.status=unescape('" + (b_clear
		? ''
		: (this.a_config[2] && this.a_config[2]['sb']
			? escape(this.a_config[2]['sb'])
			: escape(this.a_config[0]) + (this.a_config[1]
				? ' ('+ escape(this.a_config[1]) + ')'
				: ''))) + "')", 10);
}

// ------------------------------------------------------------------------------------------
// full item initialization routine
// returns HTML for item and opened subitems
// ------------------------------------------------------------------------------------------
function item_init () {

	// calculate missing parameters of the item from those available
	var a_index = this.o_root.a_index, n_id = this.n_id, i;


	// assign methods
	this.state_lookup = item_state_lookup;
	this.mover    = item_mover;
	this.mout     = item_mout;
	this.select   = item_select;
	this.check   = item_check;
	this.selsave =  item_selsave;
	this.load		=  item_load;
	this.upstatus = item_upstatus;
	this.focus = item_focus;
	
	var a_prop=[], re_pattern = new RegExp("o_tree_item","g");
	var b_settings = this.a_config[2]?1:0; 
		a_prop[1] = (b_settings 
			? this.a_config[2]['hie'] || this.o_root.a_tpl['userIconEvent']
			: this.o_root.a_tpl['userIconEvent']);
		a_prop[2] = (b_settings 
			? this.a_config[2]['hte'] || this.o_root.a_tpl['userTextEvent']
			:this.o_root.a_tpl['userTextEvent']);
	if (this.a_config.length > 3 || this.b_fnode) {
		// node related methods	
		a_prop[0] = (b_settings 
			?this.a_config[2]['hje'] || this.o_root.a_tpl['userJoinEvent']
			:this.o_root.a_tpl['userJoinEvent']);

		this.open  = item_open;
		this.save  = item_save;
		this.subhtml = item_subhtml;
	}
	else {	
		// leaf specific methods
		this.open = function () {};
	}

	// store initial state
	this.n_state |= 
		 // bit indicating root item
		(this.n_depth ? 0 : 32) +
		 // bit indicating node
		(this.a_children || this.b_fnode? 16 : 0) +
		 // bit indicating last item
		(this.n_order == this.o_parent.a_children.length - 1 ? 1 : 0);

	// prepare for visualization
	var s_iconstyle = (this.o_root.a_tpl['style_icons']	? ' class="' + this.o_root.a_tpl['style_icons'] + '"' : ''),
		a_offset = [],
		o_current_item = this.o_parent,
		a_opt = this.a_config[2];
	for (i = this.n_depth; i > this.o_root.rc; i--) {
		a_offset[i] = '<img src="' + this.o_root.a_tpl[o_current_item.n_state & 33 ? 'icon_e' : 'icon_l'] + '"' + s_iconstyle + ' border="0">';
		o_current_item = o_current_item.o_parent;
	}
	this.load();
	for(i in a_prop){			
			if(a_prop[i]) {
				a_prop[i] = item_getattrs(a_prop[i]);
				a_prop[i] = a_prop[i].replace(re_pattern, 'TREES[\'' + this.o_root.n_id + '\'].a_index['+this.n_id+']')
			}
			else a_prop[i] = ''
	}

	// get icons and styles for current state
	var a_params = this.state_lookup(true);

	var s_checkbox = a_params[3]
			?  '<a href="#" target="_self" onclick="TREES[\'' + this.o_root.n_id	+ '\'].check(' + this.n_id
				+ ');return false" ondblclick="return false;"><img src="' + a_params[3]
				+ '" border="0" name="cb' + this.o_root.n_id + '_' + this.n_id + '"' + s_iconstyle +'></a>'
			:'';
				// item caption with link
	
	return '<table cellpadding="0" cellspacing="0" border="0"><tr onmouseover="TREES[\'' + this.o_root.n_id + '\'].mover(' + this.n_id
				+ ')" onmouseout="TREES[\'' + this.o_root.n_id + '\'].mout(' + this.n_id
				+ ')"><td nowrap>' + a_offset.join('')
		 + (a_params[1]
			? (this.a_children
				// plus/minus icon with link for nodes
				? '<a href="javascript: TREES[\'' + this.o_root.n_id + '\'].toggle('
					+ this.n_id + ')" onclick = "if(this.blur)this.blur();TREES[\'' + this.o_root.n_id + '\'].toggle('
					+ this.n_id + ');return false;" onmouseover="TREES[\'' + this.o_root.n_id
					+ '\'].mover(' + this.n_id
					+ ')" onmouseout="TREES[\'' + this.o_root.n_id
					+ '\'].mout('	+ this.n_id
					+ ')" '+a_prop[0]+' ><img src="' + a_params[1]
					+ '" border="0" name="j' + this.o_root.n_id + '_' + this.n_id
					+ '"' + s_iconstyle + '></a>'
				// line junction w/o link for leaf
				: '<img src="' + a_params[1] + '" border="0"' + s_iconstyle + '>')
			: '')
		// item icon link with target and title settings
		+ (a_params[0]
			? '<a href="' + this.a_config[1] + '" target="'
				+ (a_opt && a_opt['tw']
					? a_opt['tw']
					: this.o_root.a_tpl['target'])
				+ '" title="' + (a_opt && a_opt['tt']
					? a_opt['tt']
					: '')
				+ '" onclick="if(this.blur)this.blur();return TREES[\'' + this.o_root.n_id	+ '\'].select(' + this.n_id
				+ ')" ondblclick="TREES[\'' + this.o_root.n_id  + '\'].'
				+ (this.a_children
					? 'toggle('
					: 'select(')
				+ this.n_id
				+ ')" '+a_prop[1]+'><img src="' + a_params[0]
				+ '" border="0" name="i' + this.o_root.n_id + '_' + this.n_id
				+ '"' + s_iconstyle	+'></a>'
				// item caption with link
				
			: '')
    	 + s_checkbox
		+ '</td><td nowrap' + (a_params[2]
			? ' class="' + a_params[2]	+ '"'
			: '')
		+ ' id="t' + this.o_root.n_id + '_' + this.n_id
		+ '"><a href="' + this.a_config[1]
		+ '" target="' + (a_opt && a_opt['tw']
			? a_opt['tw']
			: this.o_root.a_tpl['target'])
		+ '" title="' + (a_opt && a_opt['tt']
			? a_opt['tt']
			: '')
		+ '" onclick="if(this.blur)this.blur();return TREES[\'' + this.o_root.n_id + '\'].select(' + this.n_id
		+ ')" ondblclick="TREES[\'' + this.o_root.n_id + '\'].'
		+ (this.a_children
			? 'toggle('
			: 'select(')
		+ this.n_id
		+ ')" '+a_prop[2]+'>' + this.a_config[0]
		+ '</a></td></tr></table><div id="fc' + this.o_root.n_id + '_' + this.n_id +'" style="display:none">&nbsp;</div>' + (this.a_children
			? '<div id="c' + this.o_root.n_id + '_' + this.n_id + '" style="display:' + (this.n_state & 8 
				? 'block">' + this.subhtml()
				: 'none">' + (this.o_root.solid?this.subhtml():'')) + '</div>'
			: '');
}

// ------------------------------------------------------------------------------------------
// returns HTML for children items
// ------------------------------------------------------------------------------------------
function item_subhtml() {
	var a_subhtml = [];
	for (var i = 0; i < this.a_children.length; i++)
		a_subhtml[i] = this.a_children[i].init();
	return a_subhtml.join('');
}

// ------------------------------------------------------------------------------------------
// saves item's state in cookies
// ------------------------------------------------------------------------------------------
function item_save() {
	var n_wordindex = Math.floor(this.n_node_id / 31);
	this.o_root.a_states[n_wordindex] = (this.n_state & 8
			? this.o_root.a_states[n_wordindex] |  (1 << (this.n_node_id % 31))
			: this.o_root.a_states[n_wordindex] & ~(1 << (this.n_node_id % 31))
		);
	document.cookie = 'tree_' + this.o_root.n_id + '_state=' + this.o_root.a_states.join('_')+';'+this.o_root.ce;
}

function item_selsave() {
	var n_wordindex = Math.floor(this.n_id / 31);
	this.o_root.a_select[n_wordindex] = (this.n_state & 4
			? this.o_root.a_select[n_wordindex] |  (1 << (this.n_id % 31))
			: this.o_root.a_select[n_wordindex] & ~(1 << (this.n_id % 31))
		);
	document.cookie = 'tree_' + this.o_root.n_id + '_selected=' + this.o_root.a_select.join('_')+';'+this.o_root.ce;
}


// ------------------------------------------------------------------------------------------
// loads item's state from cookies
// ------------------------------------------------------------------------------------------
function item_load(b_nohandlers) {

	// run cusom handler
	var s_hdlr = (s_hdlr ? s_hdlr : this.o_root.a_tpl['onItemLoad']);
	if (!b_nohandlers && s_hdlr) {
		eval ('var b_result=' + s_hdlr + '(this);');
		if (!b_result) return false;
	}

	if (!this.a_children) return;
	// set states as per params in items structure
	if (this.a_config[2] && typeof(this.a_config[2]['st']) == 'number') {
		if (Boolean(this.a_config[2]['st'])) this.n_state |= 8;
		else this.n_state &= ~8;
		return;
	}

	// set default states if no cookies found
	if (this.o_root.loadfix && !this.n_depth) {
//    No cookies && root && node
		this.n_state |= 8;
		this.save();
		return;
	}
	
	// load state from the cookies
	var n_wordindex = Math.floor(this.n_node_id / 31);
	if (Boolean(this.o_root.a_states[n_wordindex] & (1 << (this.n_node_id % 31))))  this.n_state |= 8;
	else this.n_state &= ~8;
}

// ------------------------------------------------------------------------------------------
// returns or adjusts item icons and styles accordingly to the item's state
// ------------------------------------------------------------------------------------------
function item_state_lookup (b_return) {

	// --- bitmap ---
	// mouse over (64)
	// root (32)
	// node (16)
	// opned (8)
	// selected (4)
	// junction icon (2)
	// last item (1)

	// template icon index (no junction, no last)
	var n_iindex = this.n_state & ~3,
	// template ckeckbox icon index (no junction, no last, no open)
		n_cindex = this.n_state & ~59,
	// template junction index (no mouseover, no selected, yes junction)
		n_jindex = this.n_state & ~68 | 2;

	// search for icon defined locally
	if(!this.a_config[2]) this.a_config[2] = [];
	var s_image = this.a_config[2]['i' + (n_iindex & ~48)];
	// search for icon defined locally via class
	if (!s_image) s_image = this.a_config[2]['ic'] ? eval(this.a_config[2]['ic'])['i' + (n_iindex & ~48)] : 0;
	// search for icon defined globally
	if (!s_image) s_image = this.o_root.a_tpl['icon_' + n_iindex];
	// search for icon for not mouseovered state
	if (!s_image) s_image = this.o_root.a_tpl['icon_' + (n_iindex & ~64)];
	
	var s_cimage = this.o_root.a_tpl['icon_c' + n_cindex];
	
	var s_junct = this.o_root.a_tpl['icon_' + n_jindex];
	// search for style defined locally
	var s_style = this.a_config[2]['s' + (n_iindex & ~48)];
	// search for style defined locally via class
	if (!s_style) s_style = this.a_config[2]['ic'] ? eval(this.a_config[2]['ic'])['s' + (n_iindex & ~48)] : 0;
	// search for style defined globally
	if (!s_style) s_style = this.o_root.a_tpl['style_' + n_iindex];
	// search for style for not mouseovered state
	if (!s_style) s_style = this.o_root.a_tpl['style_' + (n_iindex & ~64)];

	// value return request	
	if (b_return)
		return [s_image, s_junct, s_style, s_cimage];

	// get icon objects and update them accordingly to new state
	var o_obj = document.images['j' + this.o_root.n_id + '_' + this.n_id];
	if (o_obj) o_obj.src = s_junct;

	o_obj = document.images['i' + this.o_root.n_id + '_' + this.n_id];
	if (o_obj) o_obj.src = s_image;

	o_obj = document.images['cb' + this.o_root.n_id + '_' + this.n_id];
	if (o_obj) o_obj.src = s_cimage;

	o_obj = get_element('t' + this.o_root.n_id + '_' + this.n_id);
	if (o_obj) o_obj.className =  s_style;
}
function item_getattrs (a_prop) {
	var s_result = [];
	for (var s_key in a_prop)
		s_result[s_result.length] = s_key + '="' + a_prop[s_key] + '"';
	return s_result.join(' ');
}
function obj2obj(o_source){
	var o_destination;
	if(typeof(o_source)=='object' && o_source){
		o_destination=[];
		for(var i in o_source)
			o_destination[i]=obj2obj(o_source[i])
	}
	else o_destination=o_source;
	return o_destination;
}
// ------------------------------------------------------------------------------------------
// global variables and functions
var TREES = [], B_DOM;
get_element = document.all ?
	function (s_id) { return document.all[s_id] } :
	(document.getElementById ?
		function (s_id) { return document.getElementById(s_id) } :
		function (s_id) { return null });

// ------------------------------------------------------------------------------------------
// fin.
