/*
        This function extracts path to the first tree item which has the caption specified.

*/
function treePath (s_caption, treeName) {

        // set to true when debugging the application
        var B_DEBUG = false;

        // variables
        var SITE_URL   = "https://www.rdss.info";
	var LINK_TITLE = "";
	var LINK       = "";
	var ALINK      = "";
	var ARROW      = "&nbsp;&nbsp;<img src='/images/icons/arrow_dbl_blue.png'>&nbsp;&nbsp;"

        if (B_DEBUG) 
                 alert("looking for item with caption '" + s_caption+ "'.")

        // 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 (!treeName){
        if (B_DEBUG)
                alert("tree is not defined, assuming it is the first one!")
                o_tree = (parent.menu.TREES[0]);
        } else {
                o_tree = (parent.menu.TREES[treeName]);
        }

        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);
    if (B_DEBUG) 
             alert("found item ("+a_item.length+") long")

    if (B_DEBUG)
             alert(a_item[0].state());

    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];

        if (B_DEBUG)
             alert("parent is ("+a_parents.length+") long")

        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--){

           LINK       = a_parents[i].a_config[1];
           ALINK      = "<a href='" + LINK + "'>";
           LINK_TITLE = a_parents[i].a_config[0];
           LINK_PATH  = SITE_URL + LINK;

           // check if node or root
           if (a_parents[i].n_state & 48){
                if (B_DEBUG)
                     alert("parent "+ i + " caption ("+ LINK_TITLE +")")

		if (s_caption == LINK_TITLE){

                	if (B_DEBUG)
                         	alert("caption matched parent "+ i + " caption ("+ LINK_TITLE +")")

	              TREE_PATH ? TREE_PATH = TREE_PATH + ARROW + LINK_TITLE : TREE_PATH = LINK_TITLE;

		}else{
                     TREE_PATH ? TREE_PATH = TREE_PATH + ARROW + ALINK + LINK_TITLE + "</a>" : TREE_PATH = ALINK + LINK_TITLE + "</a>";
		}
           }else{
              TREE_PATH ? TREE_PATH = TREE_PATH + ARROW + LINK_TITLE : TREE_PATH = LINK_TITLE;
              if (B_DEBUG) 
                 alert("PATH: " + TREE_PATH)
           }
	} 
    }
  
}

