var tree_tpl = {
	// general
	'target':'_top', // name of the frame links will be opened in
	'width':'125px',
	// icons - root
	'icon_48':'/images/menu2/imgPOR1.gif',  // normal root icon
	'icon_52':'/images/menu2/imgPOR2.gif',  // selected root icon
	'icon_56':'/images/menu2/imgPOR1.gif',  // normal opened root icon
	'icon_60':'/images/menu2/imgPOR2.gif',  // selected opened root icon
	'icon_112':'/images/menu2/imgPOR2.gif', // mouseovered normal root icon 
	'icon_116':'/images/menu2/imgPOR2.gif', // mouseovered selected root icon
	'icon_120':'/images/menu2/imgPOR2.gif', // mouseovered normal opened root icon
	'icon_124':'/images/menu2/imgPOR2.gif', // mouseovered selected opened root icon
	// icons - leaf
	'icon_0':'/images/menu2/empty2.gif',    // leaf icon normal
	'icon_4':'/images/menu2/empty2.gif',    // leaf icon selected
	// 'icon_64':'icons/pagesel.gif',       // leaf icon selected
	// icons - junctions
	//'icon_2':'icons/joinbottom.gif',      // junction for leaf
	//'icon_3':'icons/join.gif',            // junction for last leaf
	'icon_18':'/images/menu2/false.gif',    // junction for closed node
	'icon_19':'/images/menu2/false.gif',    // junction for last closed node
	'icon_26':'/images/menu2/true.gif',     // junction for opened node
	'icon_27':'/images/menu2/true.gif',     // junction for last opended node
	// icons - misc
	'icon_e':'/images/menu2/empty1.gif',    // empty image
	'icon_l':'/images/menu2/empty1.gif',    // vertical line
	// styles - node
	'style_16':'ts1',                        // normal node caption style
	'style_20':'ts1v',                       // selected node caption style
	'style_24':'ts1',                        // normal opened node caption style
	'style_28':'ts1v',                       // selected opened node caption style
	'style_80':'ts1v',                       // mouseovered normal node caption style
	'style_84':'ts1v',                       // mouseovered selected node caption style
	'style_88':'ts1v',                       // mouseovered normal opened node caption style
	'style_92':'ts1v',                       // mouseovered selected opened node caption style
	// styles - leaf
	'style_0':'ts2',                         // normal leaf caption style
	'style_4':'ts2v',                        // selected leaf caption style
	'style_64':'ts2v',                       // mouseovered normal leaf caption style
	'style_68':'ts2v',                       // mouseovered selected leaf caption style
	'onItemOpen':'onItemOpenHandler'        // on item open event handler
	// make sure there is no comma after the last key-value pair
};

function onItemOpenHandler(o_item) {
	// get current block
	var a_curblock = o_item.o_parent.a_children;
	// close all nodes except current
	for (var i = 0; i < a_curblock.length; i++)
		if (a_curblock[i].n_state & 48 && a_curblock[i] != o_item)
			a_curblock[i].open(true);
	return true;
}

function closeParents(item) {
	item.open(true);
	item = item.o_parent;
	if (item) {closeParents(item);}
	return true;
}

function onItemOpenHandler2(o_item) {
	if (o_item != o_selected) {closeParents(o_selected);}
	return true;
}

function openItemById(n_uid, o_tree) {
	// set to true when debugging the application
	var B_DEBUG = false;
	
	// exit if required parameter isn't specified
	if (!n_uid)
		return (B_DEBUG
			? alert("Required parameter to function openItemById is missing")
			: false
		);
	
	// use first tree on the page if tree object isn't explicitly defined
	var i, b_valid = false;
	for(i in TREES)
		if(o_tree == TREES[i]) {
			b_valid = true;
			break;
		}
	if (!b_valid)
		o_tree = (TREES[0]);
	if (!o_tree)
		return (B_DEBUG
			? alert("No Tigra Tree Menu PRO instances can be found on this page")
			: false
		);
	
	// find item with specified caption
	var o_item = o_tree.find_item_by_id(n_uid);
	if (!o_item)
		return (B_DEBUG
			? alert("Item with ID '" + n_uid + "' can't be found in the tree hierarchy")
			: false
		);
	
	// check if node/root or leaf
	var a_parents = [];
	if (o_item.n_node_id)
		a_parents[0] = o_item;
	else if (B_DEBUG)
		alert("Item with ID '" + o_item.n_uid + "' is leaf.\nHierarchy will be opened to its parent node only.");
	
	// collect info about all item's parents
	var n_id = o_item.n_id,
		n_depth = o_item.n_depth,
		a_index = o_item.o_root.a_index;
	while (n_depth) {
		if (a_index[n_id].n_depth < n_depth) {
			a_parents[a_parents.length] = a_index[n_id];
			n_depth--;
		}
		n_id--;
	}
	
	// open all parents starting from root
	if (B_DOM) 
		// new browsers version
		for (var i = a_parents.length-1; i >= 0; i--) {
			if(a_parents[i].o_parent == o_tree) continue;
			a_parents[i].n_state |= 4;
			a_parents[i].b_path = true;
			a_parents[i].open();
			a_parents[i].state_lookup();
		}
	else {
		// old browsers version
		for (var i = a_parents.length-1; i >= 0; i--)
			a_parents[i].n_state |= 8;
		a_index[0].o_item.save();
		window.location = window.location;
	}
	
	o_item.b_path = true;
	o_item.n_state |= 4;
	// update styles and images
	o_item.state_lookup();
	
	return 0;
}
