/*
	Feel free to use your custom icons for the tree. Make sure they are all of the same size.
	User icons collections are welcome, we'll publish them giving all regards.
*/

var TREE_TPL = {
	'target'  : '_self',	// name of the frame links will be opened in
							// other possible values are: _blank, _parent, _search, _self and _top

	'icon_e'  : 'tree/icons/empty.gif', // empty image
	'icon_l'  : 'tree/icons/line.gif',  // vertical line
	
        'icon_32' : 'tree/icons/base.gif',   // root leaf icon normal
        'icon_36' : 'tree/icons/base.gif',   // root leaf icon selected
	
	'icon_48' : 'tree/icons/.gif',   // root icon normal
	'icon_52' : 'tree/icons/tom.gif',   // root icon selected
	'icon_56' : 'tree/icons/tom.gif',   // root icon opened
	'icon_60' : 'tree/icons/tom.gif',   // root icon selected
	
	'icon_16' : 'tree/icons/tom.gif', // node icon normal
	'icon_20' : 'tree/icons/tom.gif', // node icon selected
	'icon_24' : 'tree/icons/tom.gif', // node icon opened
	'icon_28' : 'tree/icons/tom.gif', // node icon selected opened

	'icon_0'  : 'tree/icons/tom.gif', // leaf icon normal
	'icon_4'  : 'tree/icons/tom.gif', // leaf icon selected
	
	'icon_2'  : 'tree/icons/joinbottom.gif', // junction for leaf
	'icon_3'  : 'tree/icons/join.gif',       // junction for last leaf
	'icon_18' : 'tree/icons/joinbottom.gif', // junction for closed node, plusbottom
	'icon_19' : 'tree/icons/join.gif',       // junctioin for last closed node, plus
	'icon_26' : 'tree/icons/joinbottom.gif',// junction for opened node, minusbottom
	'icon_27' : 'tree/icons/join.gif',       // junctioin for last opended node, minus
	
	'style_20' : 'linktxt',  //style for selected node
	'style_24' : 'bold',  //style for opened node
	'style_28' : 'linktxt',  //style for selected opened node
	'style_4' : 'linktxt', //style for selected leaf
	
	'style_48':'bold', // normal root caption style
	'style_52':'bold', // selected root caption style
	'style_56':'bold', // opened root caption style
	'style_60':'linktxt', // selected opened root caption style
	
	// event handlers - item
	'onItemSelect':'onItemSelectHandler',// on item open event handler
	'onItemOpen':'onItemOpenHandler'// on item open event handler
	
};

function onItemSelectHandler (o_item) {
if (o_item.a_children)
o_item.o_root.toggle(o_item.n_id)

return true;
}

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);

	// proceed to default handler
	return true;
}

function openItemByCaption (s_caption, o_tree) {
	// set to true when debugging the application
	var B_DEBUG = true;
var b_link = 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,b_link);
    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].n_state & 48)
	     a_parents[i].open();
		//o_item.select(); //visar vald länk i select-stil
	   //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.")
    }
}