<!-- http://www.softcomplex.com/products/tigra_tree_menu_pro/docs/#api //-->
var TREE_TPL= {
	// general
	'target':'_self',	// name of the frame links will be opened in
				// other possible values are:
				// _blank, _parent, _search, _self and _top
	
	// icons - root	
	'icon_48':'/resources/images/misc/trendnet_icon_5.gif',
	'icon_52':'/resources/images/misc/trendnet_icon_5.gif',
	'icon_56':'/resources/images/misc/trendnet_icon_4.gif',
	'icon_60':'/resources/images/misc/trendnet_icon_4.gif',

	// icons - node	
	'icon_16':'/resources/images/icons2/arrow_down.gif',
	'icon_20':'/resources/images/icons2/arrow_down.gif',
	'icon_24':'/resources/images/icons2/top_down.gif',
	'icon_28':'/resources/images/icons2/top_down.gif',
	
	'icon_80':'/resources/images/icons2/arrow_down.gif',

	// icons - leaf
	'icon_0':'/resources/images/icons2/arrow_right.gif',
	'icon_4':'/resources/images/icons2/arrow_right.gif',
	
	// icons - junctions
	'icon_2':'/resources/images/icons2/joinbottom.gif',
	'icon_3':'/resources/images/icons2/join.gif',
	'icon_18':'/resources/images/icons2/plusbottom.gif',
	'icon_19':'/resources/images/icons2/plus.gif',
	'icon_26':'/resources/images/icons2/minusbottom_002.gif',
	'icon_27':'/resources/images/icons2/minus.gif',

	// icons - misc
	'icon_e':'/resources/images/icons2/empty.gif',
	'icon_l':'/resources/images/icons2/line.gif',
	
	// styles - root
	'style_48':'mout', // normal root caption style
	'style_52':'mout', // selected root caption style
	'style_56':'mout', // opened root caption style
	'style_60':'mout', // selected opened root caption style
	'style_112':'mover', // mouseovered normal root caption style
	'style_116':'mover', // mouseovered selected root caption style
	'style_120':'mover', // mouseovered opened root caption style
	'style_124':'mover', // mouseovered selected opened root caption style
	
	// styles - node
	'style_16':'mout', // normal node caption style
	'style_20':'mout', // selected node caption style
	'style_24':'mout', // opened node caption style
	'style_28':'mout', // selected opened node caption style
	'style_80':'mover', // mouseovered normal node caption style
	'style_84':'mover', // mouseovered selected node caption style
	'style_88':'mover', // mouseovered opened node caption style
	'style_92':'mover', // mouseovered selected opened node caption style

	// styles - leaf
	'style_0':'mout', // normal leaf caption style
	'style_4':'mout', // selected leaf caption style
	'style_64':'mover', // mouseovered normal leaf caption style
	'style_68':'mover', // mouseovered selected leaf caption style

	// event handlers - item
	'onItemSelect':'onItemSelectHandler',
	'onItemOpen':'onItemOpenHandler'
	//'afterInit':'collapse_all'
	//'onItemClose':'close_handler',
	//'userJoinEvent': {'oncontextmenu':'return h_context_menu(o_tree_item)'}
};


/*
	This function modifies tree behavior so only one item
	in a level can be opened at a time.
	Function should be called AS onItemOpen handler of the tree
*/
function onItemOpenHandler (o_item) {
	//alert("This is node open event handler.\nThe caption of the item being opened is: '"+o_selected+"'");

	// 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;
}
/*
	This function opens first tree item which has the caption specified.
	There are a lot of verifications that will help you to debug your
	code. You can disable or remove those checks when finished.
	
*/
function openItemByCaption (s_caption, o_tree, search_link) {
	// set to true when debugging the application
	var B_DEBUG = false;

	// 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, search_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();
	   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.")
    }
}
/* 
	This function modifies tree behavior so nodes without link
	assigned will open on single click
	Function should be called AS onItemSelect handler of the tree
*/

function onItemSelectHandler (o_item) {
    // if node with no link then toggle
    var o_state = o_item.state();
    if (o_state['node'] && !o_item.a_config[1]) {
        o_item.o_root.toggle(o_item.n_id);
        // cancel default action
        return false;
    }
	
    // proceed to default handler
    return true;
}
/* expands nodes of the tree
	n_index - zero based index of the tree on the pate
                  if omitomittedn applied to first tree (n_index==0)
	n_depth - zero based level to which the tree with be expanded
	          if omitted the tree will be fully expanded
 */
function expand_all (n_index, n_depth) {
	var o_tree = TREES[n_index ? n_index : 0];
	if (!o_tree)
		alert("Tree is not initialized yet");
	var a_nodes = o_tree.a_nodes;
	for (var i = 0; i< a_nodes.length; i++)
		if (n_depth == null || a_nodes[i].n_depth <= n_depth)
			a_nodes[i].open(0, 1);
	o_tree.ndom_refresh();
}

/* collapses nodes of the tree
	n_index - zero based index of the tree on the pate
                  if omited then applied to first tree (n_index==0)
	n_depth - zero based level to which the tree with be collapsed
	          if omitted the tree will collapsed to second level (n_depth==1)
 */
function collapse_all (n_index, n_depth) {
	var o_tree = TREES[n_index ? n_index : 0];
	if (!n_depth) n_depth = 0;
	if (!o_tree)
		alert("Tree is not initialized yet");
	var a_nodes = o_tree.a_nodes;
	for (var i = a_nodes.length - 1; i >= 0; i--)
		if (a_nodes[i].n_depth >= n_depth && a_nodes[i].open)
			a_nodes[i].open(1, 1);
	o_tree.ndom_refresh();
}
function open_handler(o_item, o_selected){
	//alert("This is node open event handler.\nThe caption of the item being opened is: '"+o_item.AX[0]+"'");
	//alert(o_selected);
	return true
}
function close_handler(o_item){
	//alert("This is node close event handler.\nThe caption of the item being closed is: '"+o_item.AX[0]+"'");
	return true
}
function h_context_menu(o_item){
	alert('Context menu is disabled: '+o_item.a_config[0]);
	return false;
}


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'  : '/resources/images//resources/images//resources/images/icons2/empty.gif', // empty image
	'icon_l'  : '/resources/images//resources/images//resources/images/icons2/line.gif',  // vertical line

        'icon_32' : '/resources/images//resources/images//resources/images/icons2/base.gif',   // root leaf icon normal
        'icon_36' : '/resources/images//resources/images//resources/images/icons2/base.gif',   // root leaf icon selected

	'icon_48' : '/resources/images//resources/images//resources/images/icons2/base.gif',   // root icon normal
	'icon_52' : '/resources/images//resources/images//resources/images/icons2/base.gif',   // root icon selected
	'icon_56' : '/resources/images//resources/images//resources/images/icons2/base.gif',   // root icon opened
	'icon_60' : '/resources/images//resources/images//resources/images/icons2/base.gif',   // root icon selected
	
	'icon_16' : '/resources/images//resources/images//resources/images/icons2/folder.gif', // node icon normal
	'icon_20' : '/resources/images//resources/images//resources/images/icons2/folderopen.gif', // node icon selected
	'icon_24' : '/resources/images//resources/images//resources/images/icons2/folderopen.gif', // node icon opened
	'icon_28' : '/resources/images//resources/images//resources/images/icons2/folderopen.gif', // node icon selected opened

	'icon_0'  : '/resources/images//resources/images//resources/images/icons2/page.gif', // leaf icon normal
	'icon_4'  : '/resources/images//resources/images//resources/images/icons2/page.gif', // leaf icon selected
	
	'icon_2'  : '/resources/images//resources/images//resources/images/icons2/joinbottom.gif', // junction for leaf
	'icon_3'  : '/resources/images//resources/images//resources/images/icons2/join.gif',       // junction for last leaf
	'icon_18' : '/resources/images//resources/images//resources/images/icons2/plusbottom.gif', // junction for closed node
	'icon_19' : '/resources/images//resources/images//resources/images/icons2/plus.gif',       // junctioin for last closed node
	'icon_26' : '/resources/images//resources/images//resources/images/icons2/minusbottom.gif',// junction for opened node
	'icon_27' : '/resources/images//resources/images//resources/images/icons2/minus.gif'       // junctioin for last opended node
};

