var TREE_TPL = {
	'target'  : '_parent',	// name of the frame links will be opened in
							// other possible values are: _blank, _parent, _search, _self and _top

	'icon_e'  : '../../scripts/icons/spacer.gif', // empty image
	'icon_l'  : '../../scripts/icons/spacer.gif',  // vertical line

    'icon_32' : '../../scripts/icons/spacer.gif',   // root leaf icon normal
    'icon_36' : '../../scripts/icons/spacer.gif',   // root leaf icon selected
	
	'icon_48' : '../../scripts/icons/spacer.gif',   // root icon normal
	'icon_52' : '../../scripts/icons/spacer.gif',   // root icon selected
	'icon_56' : '../../scripts/icons/spacer.gif',   // root icon opened
	'icon_60' : '../../scripts/icons/spacer.gif',   // root icon selected
	
	'icon_16' : '../../scripts/icons/spacer.gif', // node icon normal
	'icon_20' : '../../scripts/icons/spacer.gif', // node icon selected
	'icon_24' : '../../scripts/icons/spacer.gif', // node icon opened
	'icon_28' : '../../scripts/icons/spacer.gif', // node icon selected opened

	'icon_0'  : '../../scripts/icons/spacer.gif', // leaf icon normal
	'icon_4'  : '../../scripts/icons/spacer.gif', // leaf icon selected
	
	'icon_2'  : '../../scripts/icons/joinbottom.gif', // junction for leaf
	'icon_3'  : '../../scripts/icons/join.gif',       // junction for last leaf
	'icon_18' : '../../scripts/icons/plusbottom.gif', // junction for closed node
	'icon_19' : '../../scripts/icons/plus.gif',       // junction for last closed node
	'icon_26' : '../../scripts/icons/minusbottom.gif',// junction for opened node
	'icon_27' : '../../scripts/icons/minus.gif'       // junction for last opened node
};

function openItemByCaption (s_caption, o_tree) {
	// set to true when debugging the application
	var B_DEBUG = true;

	// exit if required parameter isn't specified
	if (!s_caption)
		return (B_DEBUG
			? alert("Required parameter to function openItemByCaption is missing")
			: false
		);

	// use first tree on the page if tree object isn't explicitly defined
	if (!o_tree)
		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 a_item = o_tree.find_item (s_caption);
    for (var n = 0; n < a_item.length; n++) {
		o_item=a_item[n];
		// 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,
			a_parents = [o_item];
	
		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
		for (var i = a_parents.length - 1; i >= 0; i--) {
		   // check if node or root
		   if (a_parents[i].open)
		      a_parents[i].open();
		   else
		      if (B_DEBUG) 
		         alert("Item with caption '" + a_parents[i].a_config[0]+ 
		            "' is a leaf.\nHierarchy will be opened to its parent node only.")
		}
    	o_item.select();
	}
}
